import React, { useEffect, useRef } from "react"; import { Box, Paper, TextField, Typography } from "@mui/material"; import { useI18n } from "../i18n/I18nProvider"; import { useToast } from "../toast"; /** The bookmarklet opens the app at /?add=, which triggers quick-capture. */ function buildBookmarklet(origin: string): string { // Kept as a single minified expression; opens a small popup so the user's tab is undisturbed. return `javascript:void(window.open('${origin}/?add='+encodeURIComponent(location.href),'jobbjakt','width=520,height=720'))`; } export default function QuickCaptureCard() { const { t } = useI18n(); const { toast } = useToast(); const linkRef = useRef(null); const origin = typeof window !== "undefined" ? window.location.origin : ""; const bookmarklet = buildBookmarklet(origin); // React refuses to render javascript: hrefs, so set it directly on the DOM node. useEffect(() => { if (linkRef.current) linkRef.current.setAttribute("href", bookmarklet); }, [bookmarklet]); return ( {t("settingsQuickCaptureTitle")} {t("settingsQuickCaptureSubtitle")} { // Clicking (vs dragging) shouldn't navigate; the value is meant to be dragged to the bar. e.preventDefault(); toast(t("settingsQuickCaptureDragHint"), "info"); }} sx={{ display: "inline-block", px: 2, py: 1, borderRadius: 2, border: "1px solid", borderColor: "primary.main", color: "primary.main", fontWeight: 800, textDecoration: "none", cursor: "grab", userSelect: "none", }} > {t("settingsQuickCaptureButton")} {t("settingsQuickCaptureDragHint")} e.target.select()} /> ); }