Dont fuck my clipboard

Prevents some annoying websites from fucking your clipboard

目前为 2025-03-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Dont fuck my clipboard
  3. // @namespace https://github.com/KoishiMoe/dont-fxxk-my-clipboard/
  4. // @version 0.5.2
  5. // @description Prevents some annoying websites from fucking your clipboard
  6. // @description:zh-CN 阻止一些恶心网站篡改你的剪贴板
  7. // @author KoishiMoe & Gemini
  8. // @license Unlicense
  9. // @require https://cdn.jsdelivr.net/npm/toastify-js@1.12.0
  10. // @resource toastifyCSS https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css
  11. // @match *://m.bilibili.com/*
  12. // @match *://*.lofter.com/*
  13. // @match *://*.123pan.com/*
  14. // @match *://*.xiaohongshu.com/*
  15. // @match *://*.baidu.com/*
  16. // @include /\.123\d{3}\.com\//
  17. // @include /\.lanzou\w\.com\//
  18. // @grant GM_addStyle
  19. // @grant GM_getResourceText
  20. // ==/UserScript==
  21.  
  22. (function() {
  23. 'use strict';
  24.  
  25. GM_addStyle(GM_getResourceText('toastifyCSS'));
  26.  
  27. function showToast(message, type = 'success') {
  28. Toastify({
  29. text: message,
  30. duration: 3000,
  31. close: true,
  32. gravity: "top", // `top` or `bottom`
  33. position: "right", // `left`, `center` or `right`
  34. stopOnFocus: false,
  35. style: {
  36. background: type === 'success' ? "linear-gradient(to right, #00b09b, #96c93d)" :
  37. type === 'error' ? "#f93154" :
  38. "#f39c12", // warning color
  39. }
  40. }).showToast();
  41. }
  42.  
  43. // Method 1: Overriding clipboard methods (more robust)
  44. const originalClipboard = {
  45. write: navigator.clipboard.write.bind(navigator.clipboard),
  46. writeText: navigator.clipboard.writeText.bind(navigator.clipboard)
  47. };
  48.  
  49. navigator.clipboard.write = async function() {
  50. console.warn('Clipboard write attempt blocked (using write method).');
  51. showToast(getTranslatedMessage('Blocked an attempt to change your clipboard!'), 'error');
  52. return Promise.resolve();
  53. };
  54.  
  55. navigator.clipboard.writeText = async function() {
  56. console.warn('Clipboard write attempt blocked (using writeText method).');
  57. showToast(getTranslatedMessage('Blocked an attempt to change your clipboard!'), 'error');
  58. return Promise.resolve();
  59. };
  60.  
  61. // Method 2: Overriding document.execCommand (less robust, but catches some cases)
  62. let originalExecCommand = null;
  63. try {
  64. originalExecCommand = document.execCommand;
  65. } catch (err) {
  66. console.warn("Could not capture original execCommand:", err);
  67. }
  68.  
  69. document.execCommand = function(command) {
  70. if (command === 'copy') {
  71. console.warn('Clipboard copy attempt blocked (using execCommand).');
  72. showToast(getTranslatedMessage('Blocked an attempt to hijack your copy action!'), 'error');
  73. return false;
  74. }
  75.  
  76. // If need to use execCommand for other commands
  77. if (originalExecCommand) {
  78. return originalExecCommand.apply(document, arguments);
  79. } else {
  80. console.warn("Original execCommand not available. Cannot execute:", command);
  81. return false;
  82. }
  83. };
  84.  
  85. // Method 3: Event listener (less robust, but might catch some cases)
  86. window.addEventListener('beforeunload', function (e) {
  87. console.warn("Clipboard modified before unload, likely an unwanted attempt. Operation not blocked by this event.");
  88. // There is almost no possibility to block it at this stage
  89. });
  90.  
  91. window.addEventListener('copy', function (e) {
  92. e.stopImmediatePropagation(); // Try to stop other listeners
  93. console.warn("Copy event intercepted. Modification prevented (hopefully).");
  94. showToast(getTranslatedMessage('Stopped a sneaky attempt to change your copied content!'), 'warning');
  95. });
  96.  
  97. window.addEventListener('cut', function (e) {
  98. console.warn('Cut event triggered, likely legitimate user action.');
  99. showToast(getTranslatedMessage('You cut some text.'), 'success');
  100. });
  101.  
  102. console.log('Clipboard protection loaded');
  103.  
  104. function getTranslatedMessage(message) {
  105. const translations = {
  106. 'Blocked an attempt to change your clipboard!': {
  107. 'zh-CN': '已阻止网站修改剪贴板'
  108. },
  109. 'Blocked an attempt to hijack your copy action!': {
  110. 'zh-CN': '已阻止网站劫持复制操作'
  111. },
  112. 'Stopped a sneaky attempt to change your copied content!': {
  113. 'zh-CN': '已阻止网站修改复制内容'
  114. },
  115. 'You cut some text. Everything\'s normal!': {
  116. 'zh-CN': '您剪切了一些文本'
  117. }
  118. };
  119.  
  120. const language = navigator.language;
  121. if (translations[message] && translations[message][language]) {
  122. return translations[message][language];
  123. }
  124. return message; // Default to English if no translation found
  125. }
  126. })();

QingJ © 2025

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