🔥🔥🔥文本选中复制🔥🔥🔥

解除网站不允许复制的限制,文本选中后点击复制按钮即可复制,主要用于 百度文库 道客巴巴 无忧考网 学习啦 蓬勃范文 思否社区 力扣 知乎 语雀 等

目前為 2022-02-06 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 🔥🔥🔥文本选中复制🔥🔥🔥
  3. // @description 解除网站不允许复制的限制,文本选中后点击复制按钮即可复制,主要用于 百度文库 道客巴巴 无忧考网 学习啦 蓬勃范文 思否社区 力扣 知乎 语雀 等
  4. // @namespace https://github.com/WindrunnerMax/TKScript
  5. // @version 3.1.2
  6. // @author Czy
  7. // @include *://wenku.baidu.com/view/*
  8. // @include *://wenku.baidu.com/share/*
  9. // @include *://wenku.baidu.com/link*
  10. // @include *://www.51test.net/show/*
  11. // @include *://www.xuexi.la/*
  12. // @include *://www.xuexila.com/*
  13. // @include *://www.cspengbo.com/*
  14. // @include *://*.doc88.com/*
  15. // @include *://segmentfault.com/*
  16. // @include *://wk.baidu.com/view/*
  17. // @include *://leetcode-cn.com/problems/*
  18. // @include *://www.zhihu.com/*
  19. // @include *://z.30edu.com.cn/*
  20. // @include *://docs.qq.com/doc/*
  21. // @include *://boke112.com/post/*
  22. // @include *://www.yuque.com/*
  23. // @include *://www.commandlinux.com/*
  24. // @include *://*.diyifanwen.com/*
  25. // @include *://*.mbalib.com/*
  26. // @include *://*.cnitpm.com/*
  27. // @include *://bbs.mihoyo.com/ys/obc/*
  28. // @include *://*.ruiwen.com/*
  29. // @include *://www.uemeds.cn/*
  30. // @include *://www.oh100.com/*
  31. // @include *://www.aiyuke.com/news/*
  32. // @include *://www.fwsir.com/*
  33. // @include *://www.wenxm.cn/*
  34. // @include *://www.unjs.com/*
  35. // @include *://www.ahsrst.cn/*
  36. // @include *://*.yjbys.com/*
  37. // @include *://*.qidian.com/*
  38. // @include *://*.zongheng.com/*
  39. // @include *://*.17k.com/*
  40. // @include *://*.ciweimao.com/*
  41. // @include *://book.qq.com/*
  42. // @include *://*.360doc.com/content/*
  43. // @include *://*.850500.com/news/*
  44. // @include *://utaten.com/lyric/*
  45. // @include *://*.jianbiaoku.com/*
  46. // @include *://*.kt250.com/*
  47. // @include *://www.kejudati.com/*
  48. // @include *://*.xiaohongshu.com/discovery/*
  49. // @include *://*.baibeike.com/*
  50. // @supportURL https://github.com/WindrunnerMax/TKScript/issues
  51. // @license GPL License
  52. // @run-at document-end
  53. // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js
  54. // @require https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.8/clipboard.min.js
  55. // @connect res1.doc88.com
  56. // @grant unsafeWindow
  57. // @grant GM_xmlhttpRequest
  58. // ==/UserScript==
  59. (function () {
  60. 'use strict';
  61.  
  62. function styleInject(css, ref) {
  63. if ( ref === void 0 ) ref = {};
  64. var insertAt = ref.insertAt;
  65.  
  66. if (!css || typeof document === 'undefined') { return; }
  67.  
  68. var head = document.head || document.getElementsByTagName('head')[0];
  69. var style = document.createElement('style');
  70. style.type = 'text/css';
  71.  
  72. if (insertAt === 'top') {
  73. if (head.firstChild) {
  74. head.insertBefore(style, head.firstChild);
  75. } else {
  76. head.appendChild(style);
  77. }
  78. } else {
  79. head.appendChild(style);
  80. }
  81.  
  82. if (style.styleSheet) {
  83. style.styleSheet.cssText = css;
  84. } else {
  85. style.appendChild(document.createTextNode(css));
  86. }
  87. }
  88.  
  89. var css_248z = "#_copy{align-items:center;background:#4c98f7;border-radius:3px;color:#fff;cursor:pointer;display:flex;font-size:13px;height:30px;justify-content:center;position:absolute;width:60px;z-index:1000}#select-tooltip,#sfModal,.modal-backdrop,div[id^=reader-helper]{display:none!important}.modal-open{overflow:auto!important}._sf_adjust_body{padding-right:0!important}";
  90. styleInject(css_248z);
  91.  
  92. var initEvent = function ($, websiteConfig) {
  93. $("body").on("mousedown", function () { return $("#_copy").remove(); });
  94. if (websiteConfig.initCopyEvent) {
  95. document.oncopy = function (e) { return e.stopPropagation(); };
  96. document.body.oncopy = function (e) { return e.stopPropagation(); };
  97. $("body").on("copy", function (e) {
  98. e.stopPropagation();
  99. return true;
  100. });
  101. }
  102. };
  103. var bindClipboardEvent = function (clipboard) {
  104. clipboard.on("success", function (e) {
  105. $("#_copy").html("复制成功");
  106. setTimeout(function () { return $("#_copy").fadeOut(1000); }, 1000);
  107. e.clearSelection();
  108. });
  109. clipboard.on("error", function (e) {
  110. $("#_copy").html("复制失败");
  111. setTimeout(function () { return $("#_copy").fadeOut(1000); }, 1000);
  112. e.clearSelection();
  113. });
  114. };
  115.  
  116. var path = "";
  117. var website$n = {
  118. regexp: /.*doc88\.com\/.+/,
  119. init: function ($) {
  120. // GM_xmlhttpRequest({
  121. // method: "GET",
  122. // url: "https://res.doc88.com/assets/js/v2.js",
  123. // onload: function(response) {
  124. // var view = new Function("var view = " + response.responseText.replace("eval", "") + "; return view;");
  125. // path = /<textarea[\s\S]*?Viewer.([\S]*?)\+[\S]*?\/textarea>/.exec(view())[1];
  126. // }
  127. // })
  128. $("body").append("<style id=\"copy-hide\">#left-menu{display: none !important;}</style>");
  129. GM_xmlhttpRequest({
  130. method: "GET",
  131. url: "https://res1.doc88.com/resources/js/modules/main-v2.min.js?v=2.90",
  132. onload: function (response) {
  133. path = /<textarea[\s\S]+>'\+([\S]*?)\+"<\/textarea>/.exec(response.responseText)[1];
  134. },
  135. });
  136. },
  137. getSelectedText: function () {
  138. var select = unsafeWindow;
  139. path.split(".").forEach(function (v) {
  140. select = select[v];
  141. });
  142. return select;
  143. },
  144. };
  145.  
  146. var website$m = {
  147. regexp: /.*segmentfault\.com\/.+/,
  148. init: function ($) {
  149. $("body").addClass("_sf_adjust_body");
  150. $("body").on("click", function () {
  151. $("body").css("padding-right", 0);
  152. });
  153. },
  154. };
  155.  
  156. var stopJQueryPropagation = function (event) {
  157. event.stopPropagation();
  158. // event.stopImmediatePropagation(); // 即停且阻止该元素后`on`同类事件触发
  159. return true; // 若为 `false` 则会 `preventDefault` `stopPropagation`
  160. };
  161. var stopNativePropagation = function (event) { return event.stopPropagation(); };
  162. var utils = {
  163. hideButton: function ($) {
  164. $("body").append("<style id=\"copy-hide\">#_copy{display: none !important;}</style>");
  165. },
  166. showButton: function ($) {
  167. $("#copy-hide").remove();
  168. },
  169. removeAttributes: function ($, selector, attr) {
  170. if (attr === void 0) { attr = []; }
  171. var dom = $(selector);
  172. attr.forEach(function (item) { return dom.removeAttr(item); });
  173. },
  174. enableUserSelect: function ($, selector, inline) {
  175. if (inline === void 0) { inline = false; }
  176. var cur = $(selector);
  177. if (inline) {
  178. cur.css("user-select", "auto");
  179. cur.css("-webkit-user-select", "auto");
  180. }
  181. else {
  182. var template = "\n <style>\n ".concat(selector, "{\n user-select: auto !important;\n -webkit-user-select: auto !important;\n }\n </style>\n ");
  183. $("body").append(template.replace(/\s*/, " "));
  184. }
  185. },
  186. enableOnSelectStart: function ($, selector) {
  187. $(selector).on("selectstart", stopJQueryPropagation);
  188. },
  189. enableOnContextMenu: function ($, selector) {
  190. $(selector).on("contextmenu", stopJQueryPropagation);
  191. },
  192. enableOnCopy: function ($, selector) {
  193. $(selector).on("copy", stopJQueryPropagation);
  194. },
  195. enableOnKeyDown: function ($, selector) {
  196. $(selector).on("keydown", function (e) {
  197. if (e.key === "c" && e.ctrlKey)
  198. return stopJQueryPropagation(e);
  199. });
  200. },
  201. enableOnSelectStartByCapture: function () {
  202. document.addEventListener("selectstart", stopNativePropagation, true);
  203. },
  204. enableOnContextMenuByCapture: function () {
  205. document.addEventListener("contextmenu", stopNativePropagation, true);
  206. },
  207. enableOnCopyByCapture: function () {
  208. document.addEventListener("copy", stopNativePropagation, true);
  209. },
  210. enableOnKeyDownByCapture: function () {
  211. document.addEventListener("keydown", stopNativePropagation, true);
  212. },
  213. };
  214.  
  215. var website$l = {
  216. regexp: /.*wk\.baidu\.com\/view\/.+/,
  217. init: function ($) {
  218. utils.hideButton($);
  219. $(window).on("load", function () {
  220. $(".sf-edu-wenku-vw-container").attr("style", "");
  221. $(".sfa-body").on("selectstart", function (e) {
  222. e.stopPropagation();
  223. return true;
  224. });
  225. });
  226. },
  227. };
  228.  
  229. var website$k = {
  230. regexp: /.*zhihu\.com\/.*/,
  231. init: function ($) {
  232. utils.hideButton($);
  233. },
  234. };
  235.  
  236. var website$j = {
  237. regexp: /.*zhihu\.com\/pub\/reader\/.+/,
  238. init: function ($) {
  239. setTimeout(utils.showButton, 500, $);
  240. },
  241. };
  242.  
  243. var website$i = {
  244. regexp: /.*30edu\.com\.cn\/.+/,
  245. init: function ($) {
  246. window.onload = function () {
  247. var iframes = document.getElementsByTagName("iframe");
  248. if (iframes.length === 2) {
  249. var body = $(iframes[1].contentWindow.document.querySelector("body"));
  250. body.attr("oncopy", "");
  251. body.attr("oncontextmenu", "");
  252. body.attr("onselectstart", "");
  253. }
  254. };
  255. },
  256. };
  257.  
  258. var restrictCopying = true;
  259. var website$h = {
  260. regexp: /.*docs\.qq\.com\/.+/,
  261. config: {
  262. initCopyEvent: false,
  263. },
  264. init: function ($) {
  265. window.onload = function () {
  266. if (unsafeWindow.pad) {
  267. if (unsafeWindow.pad.editor._docEnv.copyable === true) {
  268. // 不限制复制
  269. restrictCopying = false;
  270. utils.hideButton($);
  271. }
  272. else {
  273. unsafeWindow.pad.editor._docEnv.copyable = true;
  274. }
  275. }
  276. else {
  277. restrictCopying = false;
  278. utils.hideButton($);
  279. }
  280. };
  281. },
  282. getSelectedText: function () {
  283. if (!restrictCopying)
  284. return "";
  285. if (unsafeWindow.pad) {
  286. unsafeWindow.pad.editor._docEnv.copyable = true;
  287. unsafeWindow.pad.editor.clipboardManager.copy();
  288. return unsafeWindow.pad.editor.clipboardManager.customClipboard.plain;
  289. }
  290. return "";
  291. },
  292. };
  293.  
  294. var website$g = {
  295. regexp: new RegExp(".+://boke112.com/post/.+"),
  296. init: function ($) {
  297. $("body").on("click", function () { return false; });
  298. var template = "\n <style>\n :not(input):not(textarea)::selection {\n background-color: #2440B3 !important;\n color: #fff !important;\n }\n\n :not(input):not(textarea)::-moz-selection {\n background-color: #2440B3 !important;\n color: #fff !important;\n }\n </style>\n ";
  299. $("body").append(template.replace(/\s*/, " "));
  300. },
  301. };
  302.  
  303. var website$f = {
  304. regexp: /diyifanwen/,
  305. init: function () {
  306. setTimeout(function () {
  307. document.oncopy = function (e) { return e.stopPropagation(); };
  308. document.body.oncopy = function (e) { return e.stopPropagation(); };
  309. }, 1000);
  310. },
  311. };
  312.  
  313. var website$e = {
  314. regexp: /mbalib/,
  315. init: function ($) {
  316. window.onload = function () {
  317. var container = $("#fullScreenContainer");
  318. container.attr("oncopy", "");
  319. container.attr("oncontextmenu", "");
  320. container.attr("onselectstart", "");
  321. };
  322. },
  323. };
  324.  
  325. var website$d = {
  326. regexp: /cnitpm/,
  327. init: function ($) {
  328. utils.hideButton($);
  329. window.onload = function () {
  330. var container = $("body");
  331. container.attr("oncopy", "");
  332. container.attr("oncontextmenu", "");
  333. container.attr("onselectstart", "");
  334. };
  335. },
  336. };
  337.  
  338. var website$c = {
  339. regexp: new RegExp(".+bbs.mihoyo.com/ys/obc.+"),
  340. init: function ($) {
  341. utils.hideButton($);
  342. $(".detail__content").on("copy", function (e) { return e.stopPropagation(); });
  343. var template = "\n <style>\n body{\n user-select: auto;\n -webkit-user-select: auto;\n }\n </style>\n ";
  344. $("body").append(template.replace(/\s*/, " "));
  345. },
  346. };
  347.  
  348. var website$b = {
  349. regexp: new RegExp(".+www.uemeds.cn/.+"),
  350. init: function ($) {
  351. utils.hideButton($);
  352. var template = "\n <style>\n .detail-main{\n user-select: auto;\n -webkit-user-select: auto;\n }\n </style>\n ";
  353. $("body").append(template.replace(/\s*/, " "));
  354. },
  355. };
  356.  
  357. var website$a = {
  358. regexp: new RegExp(".+aiyuke.com/news/.+"),
  359. init: function ($) {
  360. utils.hideButton($);
  361. $(".news_content_body").css("user-select", "auto");
  362. },
  363. };
  364.  
  365. var website$9 = {
  366. regexp: new RegExp("qidian"),
  367. init: function ($) {
  368. utils.hideButton($);
  369. utils.enableUserSelect($, "body");
  370. utils.enableOnCopy($, ".main-read-container");
  371. utils.enableOnContextMenu($, ".main-read-container");
  372. },
  373. };
  374.  
  375. var website$8 = {
  376. regexp: new RegExp("zongheng"),
  377. init: function ($) {
  378. utils.removeAttributes($, ".reader_box", ["style", "unselectable", "onselectstart"]);
  379. utils.removeAttributes($, ".reader_main", ["style", "unselectable", "onselectstart"]);
  380. utils.hideButton($);
  381. utils.enableOnKeyDown($, "body");
  382. utils.enableUserSelect($, ".reader_box .content p");
  383. utils.enableOnCopy($, ".content");
  384. utils.enableOnContextMenu($, "body");
  385. utils.enableOnSelectStart($, ".content");
  386. },
  387. };
  388.  
  389. var website$7 = {
  390. regexp: new RegExp("17k"),
  391. init: function ($) {
  392. utils.hideButton($);
  393. utils.enableOnCopy($, ".readAreaBox .p");
  394. },
  395. };
  396.  
  397. var website$6 = {
  398. regexp: new RegExp("ciweimao"),
  399. init: function ($) {
  400. utils.hideButton($);
  401. utils.enableUserSelect($, "#J_BookRead");
  402. utils.enableOnCopy($, "#J_BookCnt");
  403. utils.enableOnContextMenu($, "body");
  404. utils.enableOnSelectStart($, "#J_BookCnt");
  405. },
  406. };
  407.  
  408. var website$5 = {
  409. regexp: new RegExp("book\\.qq"),
  410. init: function ($) {
  411. utils.hideButton($);
  412. utils.enableUserSelect($, "body");
  413. utils.enableOnCopy($, "body");
  414. utils.enableOnContextMenu($, "body");
  415. utils.enableOnSelectStart($, "body");
  416. },
  417. };
  418.  
  419. var website$4 = {
  420. regexp: new RegExp("utaten"),
  421. init: function ($) {
  422. utils.removeAttributes($, "body", ["oncontextmenu", "onselectstart"]);
  423. utils.hideButton($);
  424. utils.enableUserSelect($, ".lyricBody", true);
  425. },
  426. };
  427.  
  428. var website$3 = {
  429. regexp: new RegExp("wenku.baidu.com/view/.*"),
  430. init: function ($) {
  431. utils.enableOnKeyDownByCapture();
  432. $("head").append("<style>@media print { body{ display:block; } }</style>");
  433. },
  434. getSelectedText: function () {
  435. if (window.getSelection && window.getSelection().toString()) {
  436. return window.getSelection().toString();
  437. }
  438. var result = /查看全部包含“([\s\S]*?)”的文档/.exec(document.body.innerHTML);
  439. if (result)
  440. return result[1];
  441. return "";
  442. },
  443. };
  444.  
  445. var website$2 = {
  446. regexp: new RegExp("xiaohongshu"),
  447. init: function ($) {
  448. utils.hideButton($);
  449. utils.enableUserSelect($, "*");
  450. utils.enableOnKeyDownByCapture();
  451. },
  452. };
  453.  
  454. var website$1 = {
  455. regexp: new RegExp("leetcode"),
  456. init: function ($) {
  457. utils.hideButton($);
  458. utils.enableOnCopyByCapture();
  459. },
  460. };
  461.  
  462. var website = {
  463. regexp: new RegExp([
  464. "commandlinux",
  465. "cnki",
  466. "ruiwen",
  467. "oh100",
  468. "fwsir",
  469. "wenxm",
  470. "unjs",
  471. "ahsrst",
  472. "yjbys",
  473. "360doc",
  474. "850500",
  475. "jianbiaoku",
  476. "kt250",
  477. "kejudati",
  478. "baibeike",
  479. ].join("|")),
  480. init: function ($) {
  481. utils.hideButton($);
  482. },
  483. };
  484.  
  485. var websites = [
  486. website$n,
  487. website$m,
  488. website$l,
  489. website$k,
  490. website$j,
  491. website$i,
  492. website$h,
  493. website$g,
  494. website$f,
  495. website$e,
  496. website$d,
  497. website$c,
  498. website$b,
  499. website$a,
  500. website$9,
  501. website$8,
  502. website$7,
  503. website$6,
  504. website$5,
  505. website$4,
  506. website$3,
  507. website$2,
  508. website$1,
  509. website,
  510. ];
  511.  
  512. var siteGetSelectedText = null;
  513. var initWebsite = function ($) {
  514. var websiteConfig = {
  515. initCopyEvent: true,
  516. };
  517. var mather = function (regex, website) {
  518. if (regex.test(window.location.href)) {
  519. website.init($);
  520. if (website.config)
  521. websiteConfig = Object.assign(websiteConfig, website.config);
  522. if (website.getSelectedText)
  523. siteGetSelectedText = website.getSelectedText;
  524. return true;
  525. }
  526. return false;
  527. };
  528. websites.some(function (website) { return mather(website.regexp, website); });
  529. return websiteConfig;
  530. };
  531. var getSelectedText = function () {
  532. if (siteGetSelectedText)
  533. return siteGetSelectedText();
  534. if (window.getSelection)
  535. return window.getSelection().toString();
  536. if (document.getSelection)
  537. return document.getSelection().toString();
  538. if (document.selection)
  539. return document.selection.createRange().text;
  540. return "";
  541. };
  542.  
  543. (function () {
  544. var $ = window.$;
  545. var ClipboardJS = window.ClipboardJS; // https://clipboardjs.com/#example-text
  546. var websiteConfig = initWebsite($);
  547. initEvent($, websiteConfig);
  548. document.addEventListener("mouseup", function (e) {
  549. var copyText = getSelectedText();
  550. if (copyText)
  551. console.log(copyText);
  552. else
  553. return "";
  554. $("#_copy").remove();
  555. var template = "\n <div id=\"_copy\"\n style=\"left:".concat(e.pageX + 30, "px;top:").concat(e.pageY, "px;\"\n data-clipboard-text=\"").concat(copyText.replace(/"/g, "&quot;"), "\">\u590D\u5236</div>\n ");
  556. $("body").append(template);
  557. $("#_copy").on("mousedown", function (event) { return event.stopPropagation(); });
  558. $("#_copy").on("mouseup", function (event) { return event.stopPropagation(); });
  559. var clipboard = new ClipboardJS("#_copy");
  560. bindClipboardEvent(clipboard);
  561. });
  562. })();
  563. /**
  564. * https://www.huiyingwu.com/1718/
  565. */
  566.  
  567. })();

QingJ © 2025

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