双击右键粘贴

双击右键粘贴,Chrome 浏览器测试通过

  1. // ==UserScript==
  2. // @name 双击右键粘贴
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 双击右键粘贴,Chrome 浏览器测试通过
  6. // @author hostloc @大师兄
  7. // @match http*://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. var CONFIG = {
  14. threshold: 500,
  15. _storageKey: 'rightClickTime'
  16. };
  17. document.addEventListener('mouseup', function (e) {
  18. if (e.button === 2) {
  19. if (!window.localStorage.getItem(CONFIG._storageKey)) {
  20. window.localStorage.setItem(CONFIG._storageKey, String((new Date()).valueOf()));
  21. } else {
  22. var lastTime = Number(window.localStorage.getItem(CONFIG._storageKey));
  23. var thisTime = (new Date()).valueOf();
  24. window.localStorage.setItem(CONFIG._storageKey, String(thisTime));
  25. if (thisTime - lastTime <= CONFIG.threshold) {
  26. if ((e.target.localName.toLowerCase() === 'input' || e.target.localName.toLowerCase() === 'textarea') && e.target.disabled === false) {
  27. var inp = e.target;
  28. console.log('pasted')
  29. window.navigator.clipboard.readText().then(function (d) {
  30. var cursurPosition = (inp.selectionStart) ? inp.selectionStart : null;
  31. if (!cursurPosition && document.selection) {
  32. var range = document.selection.createRange();
  33. range.moveStart("character", -inp.value.length);
  34. cursurPosition = range.text.length;
  35. }
  36. var oldVal = inp.value;
  37. var newVal = oldVal.slice(0, cursurPosition) + d + oldVal.slice(cursurPosition);
  38. inp.value = newVal;
  39. window.localStorage.removeItem(CONFIG._storageKey);
  40. })
  41. }
  42. }
  43. }
  44. }
  45. });
  46. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址