From 7127339574b2be70aa0f7ac9b40d395996b2c5e1 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Mon, 12 Feb 2024 22:55:44 +0800 Subject: [PATCH] LinkHints: copy-text: always try sending a vimiumData event --- content/link_actions.ts | 6 +++--- pages/options_wnd.ts | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/content/link_actions.ts b/content/link_actions.ts index af7124541..952985873 100644 --- a/content/link_actions.ts +++ b/content/link_actions.ts @@ -50,6 +50,9 @@ const accessElAttr = (isUrlOrText: 0 | 1 | 2): [string: string, isUserCustomized const format = dataset && hintOptions.access let el: SafeElement | null | undefined const cb = (_: string, i: string): string => i.split("||").reduce((v, j) => v || extractField(el!, j), "") + if (dataset && isUrlOrText && (dataset.vimText === "" || dataset.vimUrl === "")) { + dispatchEvent_(clickEl, newEvent_("vimiumData")) + } for (let accessor of format ? Array.isArray(format) ? format : (format + "").split(",") : []) { accessor = accessor.trim() const __arr = accessor.split(":"), selector = __arr.length > 1 ? __arr[0] : 0 @@ -61,9 +64,6 @@ const accessElAttr = (isUrlOrText: 0 | 1 | 2): [string: string, isUserCustomized json = json !== props ? json : extractField(el!, props) if (json) { return [json, 1] } } - if (dataset && isUrlOrText && (dataset.vimText === "" || dataset.vimUrl === "")) { - dispatchEvent_(clickEl, newEvent_("vimiumData")) - } return [dataset && ((isUrlOrText > 1 ? dataset.vimText : isUrlOrText && dataset.vimUrl) || isUrlOrText < 2 && (dataset.canonicalSrc || dataset.src || tag === "a" && dataset.href)) || ""] } diff --git a/pages/options_wnd.ts b/pages/options_wnd.ts index cf402b3af..f96279a01 100644 --- a/pages/options_wnd.ts +++ b/pages/options_wnd.ts @@ -175,6 +175,7 @@ let optionsInit1_ = function (): void { delayBinding_("[data-href]", "mousedown", (): void => { document.onmouseover = null as never + document.removeEventListener("vimiumData", FillDataHref) for (const element of $$("[data-href]")) { element.onmousedown = null as never void post_(kPgReq.convertToUrl, [element.dataset.href, Urls.WorkType.ConvertKnown]).then(([str]): void => { @@ -183,10 +184,12 @@ let optionsInit1_ = function (): void { }) } }, "on") - document.onmouseover = (): void => { + const FillDataHref = (): void => { didBindEvent_("mousedown") ; ($("[data-href]").onmousedown as () => void)() } + document.onmouseover = FillDataHref + document.addEventListener("vimiumData", FillDataHref) const openExt = $("#openExtensionsPage"); if (OnChrome && Build.MinCVer < BrowserVer.MinEnsuredChromeURL$ExtensionShortcuts