From ac7606fdc01dea6baeefa2f26ba4ee1e10afa16f Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Wed, 14 Feb 2024 10:28:36 +0800 Subject: [PATCH] innerClipboard_: on get, detect another name with/without "!" --- background/clipboard.ts | 14 ++++++++++---- background/store.ts | 2 ++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/background/clipboard.ts b/background/clipboard.ts index 867eaeb46..092b1c625 100644 --- a/background/clipboard.ts +++ b/background/clipboard.ts @@ -1,6 +1,7 @@ import { CurCVer_, CurFFVer_, OnChrome, OnEdge, OnFirefox, copy_, paste_, substitute_, set_copy_, set_paste_, set_substitute_, - settingsCache_, updateHooks_, searchEngines_, blank_, runOnTee_, innerClipboard_, framesForTab_, curTabId_ + settingsCache_, updateHooks_, searchEngines_, blank_, runOnTee_, innerClipboard_, framesForTab_, curTabId_, + readInnerClipboard_, set_readInnerClipboard_ } from "./store" import * as BgUtils_ from "./utils" import * as Exclusions from "./exclusions" @@ -285,7 +286,7 @@ export const replaceUsingClipboard = (text: string, item: ClipSubItem, lastClean return "$" + key } const cmd = s1.replace( /^<|>$/, ""), opArr = ( /\|\|=|[+\-*\/\|]=?|=/).exec(cmd) - let name = opArr ? cmd.slice(0, opArr.index) : cmd, value = innerClipboard_.get(name) || "" + let name = opArr ? cmd.slice(0, opArr.index) : cmd, value = readInnerClipboard_(name) if (opArr && (value || "||=".includes(opArr[0]))) { let op = opArr[0], alg = op[0], x = +cmd.slice(name.length + op.length) || 0, y = +value if (!isNaN(y || x)) { @@ -385,7 +386,7 @@ set_substitute_(((input: string, normalContext: SedContext, mixedSed?: MixedSedO if (typeof action === "string") { const actionName = action.split("=")[0], actionVal = action.slice(actionName.length + 1) if (actionName === "copy") { writeInnerClipboard_(actionVal, text) } - else if (actionName === "paste") { text = innerClipboard_.get(actionVal) || "" } + else if (actionName === "paste") { text = readInnerClipboard_(actionVal) } else if (actionName === "keyword" && exOut) { exOut.keyword_ = actionVal } else if (actionName === "act" && exOut) { exOut.actAnyway_ = actionVal !== "false" } else if ((actionName === "sys-clip" || actionName === "sysclip") && exOut) { @@ -451,6 +452,11 @@ const writeInnerClipboard_ = (name: string, text: string): void => { }, Build.NDEBUG ? 20_000 : 45_000) } +set_readInnerClipboard_(((name: string): string => { + const val = innerClipboard_.get(name) + return (val ?? innerClipboard_.get(name.endsWith("!") ? name.slice(0, -1) : name + "!")) || "" +}) satisfies typeof readInnerClipboard_) + const getTextArea_html = (): HTMLTextAreaElement => { const el = (globalThis as MaybeWithWindow).document!.createElement("textarea") el.style.position = "absolute" @@ -540,7 +546,7 @@ set_copy_(((data, join, sed, keyword): string | Promise => { set_paste_(((sed, newLenLimit?: number, exOut?: InfoOnSed): string | Promise => { const clip = detectClipSed(sed, "<") if (clip) { - return reformat_(innerClipboard_.get(clip) || "", null, exOut) + return reformat_(readInnerClipboard_(clip), null, exOut) } if (Build.MV3 || OnFirefox && (navClipboard || (navClipboard = navigator.clipboard))) { return (Build.MV3 ? runOnTee_(kTeeTask.Paste, null, null) diff --git a/background/store.ts b/background/store.ts index 0861c4ba2..ed1313d3b 100644 --- a/background/store.ts +++ b/background/store.ts @@ -225,6 +225,7 @@ export let paste_: (sed?: MixedSedOpts | null, len?: number, exOut?: InfoOnSed ) => string | Promise | null = () => "" export let substitute_: (text: string, context: SedContext, sed?: MixedSedOpts | null, exOut?: InfoOnSed) => string = s => s +export let readInnerClipboard_: (name: string) => string = () => "" export let evalVimiumUrl_: Urls.Executor = () => null export let updateToLocal_: ((wait: number) => void) | true | null = null export let shownHash_: ((this: void) => string) | null = null @@ -237,6 +238,7 @@ export const set_restoreSettings_ = (_newRestore: typeof restoreSettings_): void export const set_copy_ = (_newCopy: typeof copy_): void => { copy_ = _newCopy } export const set_paste_ = (_newPaste: typeof paste_): void => { paste_ = _newPaste } export const set_substitute_ = (_newSed: typeof substitute_): void => { substitute_ = _newSed } +export const set_readInnerClipboard_ = (_newRIC: typeof readInnerClipboard_): void => { readInnerClipboard_ = _newRIC } export const set_evalVimiumUrl_ = (_newEval: typeof evalVimiumUrl_): void => { evalVimiumUrl_ = _newEval } export const set_shownHash_ = (_newHash: typeof shownHash_): void => { shownHash_ = _newHash } export const set_updateToLocal_ = (_newBackup: typeof updateToLocal_): void => { updateToLocal_ = _newBackup }