|
1 | 1 | // ==UserScript== |
2 | 2 | // @name 🖱右键快速复制/粘贴文本(Common Right Click Copy) |
3 | 3 | // @namespace xiaohuohumax/userscripts/common-right-click-copy |
4 | | -// @version 1.0.0 |
| 4 | +// @version 1.1.0 |
5 | 5 | // @author xiaohuohumax |
6 | 6 | // @description 用户可以通过右键点击选中的文本,快速复制到剪贴板,然后在输入框中右键即可快速粘贴剪贴板的文本(PS:对应复制限制的网站暂不支持)。 |
7 | 7 | // @license MIT |
|
32 | 32 | var _GM_setClipboard = /* @__PURE__ */ (() => typeof GM_setClipboard != "undefined" ? GM_setClipboard : void 0)(); |
33 | 33 | var _GM_setValue = /* @__PURE__ */ (() => typeof GM_setValue != "undefined" ? GM_setValue : void 0)(); |
34 | 34 | const ID = "common-right-click-copy"; |
35 | | - const VERSION = "1.0.0"; |
| 35 | + const VERSION = "1.1.0"; |
36 | 36 | const LAST_VERSION = 1; |
37 | 37 | class Store { |
38 | 38 | constructor() { |
|
191 | 191 | const view = new View(store); |
192 | 192 | console.log(`${ID}(v${VERSION})`); |
193 | 193 | 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 | + }); |
195 | 200 | } |
196 | 201 | async function paste(target, isContenteditable, isInput) { |
197 | 202 | const clipboardContext = await navigator.clipboard.readText(); |
198 | 203 | if (isContenteditable) { |
199 | 204 | const range = window.getSelection().getRangeAt(0); |
200 | 205 | range.deleteContents(); |
201 | 206 | range.insertNode(document.createTextNode(clipboardContext)); |
202 | | - } else if (isInput) { |
| 207 | + } else if (isInput && (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement)) { |
203 | 208 | target.value = clipboardContext.trim(); |
204 | 209 | } |
205 | 210 | } |
|
213 | 218 | const isContenteditable = target.hasAttribute("contenteditable"); |
214 | 219 | const isInput = target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement; |
215 | 220 | 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)) { |
217 | 223 | return; |
218 | 224 | } |
219 | 225 | if (timer > CLEANED) { |
|
224 | 230 | copy(selection); |
225 | 231 | return; |
226 | 232 | } |
227 | | - if (store.pasteTrigger === "double" && isInput) { |
| 233 | + if (store.pasteTrigger === "double" && isPaste) { |
228 | 234 | e.preventDefault(); |
229 | | - await paste(target, isContenteditable, isInput); |
| 235 | + paste(target, isContenteditable, isInput); |
230 | 236 | return; |
231 | 237 | } |
232 | 238 | return; |
|
240 | 246 | copy(selection); |
241 | 247 | return; |
242 | 248 | } |
243 | | - if (store.pasteTrigger === "single" && isInput) { |
| 249 | + if (store.pasteTrigger === "single" && isPaste) { |
244 | 250 | paste(target, isContenteditable, isInput); |
245 | 251 | } |
246 | 252 | }, THRESHOLD); |
|
0 commit comments