Skip to content

Commit f0cc1a3

Browse files
xiaohuohumaxgithub-actions[bot]
authored andcommitted
build: 📦 build user script
1 parent 5cbe72f commit f0cc1a3

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

dist/common-right-click-copy.user.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name 🖱右键快速复制/粘贴文本(Common Right Click Copy)
33
// @namespace xiaohuohumax/userscripts/common-right-click-copy
4-
// @version 1.0.0
4+
// @version 1.1.0
55
// @author xiaohuohumax
66
// @description 用户可以通过右键点击选中的文本,快速复制到剪贴板,然后在输入框中右键即可快速粘贴剪贴板的文本(PS:对应复制限制的网站暂不支持)。
77
// @license MIT
@@ -32,7 +32,7 @@
3232
var _GM_setClipboard = /* @__PURE__ */ (() => typeof GM_setClipboard != "undefined" ? GM_setClipboard : void 0)();
3333
var _GM_setValue = /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)();
3434
const ID = "common-right-click-copy";
35-
const VERSION = "1.0.0";
35+
const VERSION = "1.1.0";
3636
const LAST_VERSION = 1;
3737
class Store {
3838
constructor() {
@@ -191,15 +191,20 @@
191191
const view = new View(store);
192192
console.log(`${ID}(v${VERSION})`);
193193
function copy(selection) {
194-
selection && _GM_setClipboard(selection, "text");
194+
selection && _GM_setClipboard(selection, "text", () => {
195+
Toast.fire({
196+
icon: "success",
197+
title: "复制成功"
198+
});
199+
});
195200
}
196201
async function paste(target, isContenteditable, isInput) {
197202
const clipboardContext = await navigator.clipboard.readText();
198203
if (isContenteditable) {
199204
const range = window.getSelection().getRangeAt(0);
200205
range.deleteContents();
201206
range.insertNode(document.createTextNode(clipboardContext));
202-
} else if (isInput) {
207+
} else if (isInput && (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)) {
203208
target.value = clipboardContext.trim();
204209
}
205210
}
@@ -213,7 +218,8 @@
213218
const isContenteditable = target.hasAttribute("contenteditable");
214219
const isInput = target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement;
215220
const isCopy = !!selection && !isInput;
216-
if (!(isCopy && store.enableCopy || (isInput || isContenteditable) && store.enablePaste)) {
221+
const isPaste = isInput || isContenteditable;
222+
if (!(isCopy && store.enableCopy || isPaste && store.enablePaste)) {
217223
return;
218224
}
219225
if (timer > CLEANED) {
@@ -224,9 +230,9 @@
224230
copy(selection);
225231
return;
226232
}
227-
if (store.pasteTrigger === "double" && isInput) {
233+
if (store.pasteTrigger === "double" && isPaste) {
228234
e.preventDefault();
229-
await paste(target, isContenteditable, isInput);
235+
paste(target, isContenteditable, isInput);
230236
return;
231237
}
232238
return;
@@ -240,7 +246,7 @@
240246
copy(selection);
241247
return;
242248
}
243-
if (store.pasteTrigger === "single" && isInput) {
249+
if (store.pasteTrigger === "single" && isPaste) {
244250
paste(target, isContenteditable, isInput);
245251
}
246252
}, THRESHOLD);

0 commit comments

Comments
 (0)