您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
回归单纯的复制
// ==UserScript== // @name 掘金复制功能防篡改 // @namespace czzonet // @version 1.0.7 // @description 回归单纯的复制 // @author czzonet // @include *://juejin.im/* // @exclude *://*.eggvod.cn/* // @connect juejin.im // @license MIT License // @grant GM_download // @grant GM_openInTab // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @grant GM_addStyle // @grant unsafeWindow // @grant GM_setClipboard // @grant GM_getResourceURL // @grant GM_getResourceText // ==/UserScript== /** 执行 */ addEventLoad(clipboardGuard); /** * 附加一层函数包裹,打包新旧处理函数到window.onload一起执行 * @param {*} func */ function addEventLoad(func) { const oldOnload = window.onload; if (typeof window.onload != "function") { window.onload = func; } else { window.onload = function () { oldOnload(); func(); }; } } /** * dom元素的复制处理 */ function clipboardGuard() { console.log("Call clipboardGuard."); /** 选出对应dom元素 */ let con = document.querySelector( "#juejin > div.view-container > main > div.view.column-view" ); if (!con) { console.log("[clipboardGuard] Dom target not found."); return; } setTimeout(() => { /** 覆盖copy事件 */ con.addEventListener("copy", copyOverride); }, 1000); } /** * 覆盖copy行为,直接复制选中文字 * @param {*} event */ function copyOverride(event) { event.preventDefault(); event.stopPropagation(); /** 读取选中文字 */ const selectedData = window.getSelection(0).toString(); /** 读取选中html */ const node = document.createElement("div"); node.appendChild(window.getSelection().getRangeAt(0).cloneContents()); /** 直接写入剪贴板 判断兼容IE */ if (event.clipboardData) { /** 两种格式都进行覆盖 */ event.clipboardData.setData("text/plain", selectedData); event.clipboardData.setData("text/html", node.innerHTML); } else { window.clipboardData.setData("text", selectedData); } }
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址