Restore Clipboard ( 剪贴板消毒,去掉版权信息 )

remove annoying copyright words on zhihu.com, jianshu.com, douban.com...

目前為 2023-08-29 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Restore Clipboard ( 剪贴板消毒,去掉版权信息 )
  3. // @namespace https://github.com/harryhare
  4. // @version 0.4.10
  5. // @description remove annoying copyright words on zhihu.com, jianshu.com, douban.com...
  6. // @author harryhare
  7. // @license GPL 3.0
  8. // @icon https://raw.githubusercontent.com/harryhare/userscript/master/index.png
  9. // @match https://*.zhihu.com/**
  10. // @match https://*.jianshu.com/**
  11. // @match https://*.douban.com/**
  12. // @match https://*.csdn.net/**
  13. // @match https://*.ftchinese.com/**
  14. // @match https://*.1point3acres.com/**
  15. // @match https://blog.skk.moe/**
  16. // @match https://www.bilibili.com/**
  17. // @match https://juejin.cn/**
  18. // @match https://*.nowcoder.com/**
  19. // @match https://*.mbalib.com/**
  20. // @match http://www.360doc.com/**
  21. // @match https://www.360doc.com/**
  22. // @match https://*.geekbang.org/**
  23. // @grant none
  24. // ==/UserScript==
  25.  
  26. // use match instead of include
  27. // https://stackoverflow.com/questions/31817758/what-is-the-difference-between-include-and-match-in-userscripts
  28.  
  29. // 代码思路
  30. // if ( oncopy 所在的 element 在 document 上){
  31. // 在 document.body 上 stopPropagation();
  32. // }
  33. // else if level( oncopy 所在的 element) > level(content element){
  34. // 在 content element 上调用 stopPropagation();
  35. // }
  36. // else if level( oncopy 所在的 element) == level(content element){
  37. // 操作剪贴板
  38. // }
  39.  
  40.  
  41. function rewrite_html(e){
  42. let inner=e.innerHTML;
  43. e.innerHTML=inner;
  44. }
  45.  
  46. function do_douban(){
  47. var targets=document.querySelectorAll('div#link-report .note,div.review-content.clearfix');
  48. for(let i=0;i<targets.length;i++){
  49. targets[i].oncopy=(e)=>{e.stopPropagation();};
  50. }
  51. }
  52.  
  53. function do_csdn(){
  54. var targets=document.querySelectorAll('div#article_content');
  55. for(let i=0;i<targets.length;i++){
  56. targets[i].oncopy=(e)=>{e.stopPropagation();};
  57. }
  58. }
  59.  
  60. function do_juejin(){
  61. var targets=document.querySelectorAll('div.article-content div.markdown-body');
  62. for(let i=0;i<targets.length;i++){
  63. targets[i].oncopy=(e)=>{e.stopPropagation();};
  64. }
  65. }
  66.  
  67. function do_360doc(){
  68. var targets=document.querySelectorAll('div.doc360article_content');
  69. for(let i=0;i<targets.length;i++){
  70. targets[i].oncopy=(e)=>{e.stopPropagation();};
  71. }
  72. }
  73.  
  74. function do_bilibili(){
  75. var targets=document.querySelectorAll('div#read-article-holder');
  76. for(let i=0;i<targets.length;i++){
  77. targets[i].oncopy=(e)=>{e.stopPropagation();};
  78. }
  79. }
  80.  
  81. function do_zhihu(){
  82. var targets=document.querySelectorAll('div.RichContent--unescapable');
  83. for(let i=0;i<targets.length;i++){
  84. targets[i].oncopy=(e)=>{e.stopPropagation();};
  85. //targets[i].className=""
  86. }
  87. }
  88.  
  89.  
  90.  
  91. // B站改了,这个是原先的代码
  92. // function do_bilibili(){
  93. //
  94. // async function clean(e) {
  95. // e.preventDefault();
  96. // //可能有用
  97. // e.stopImmediatePropagation();
  98. // // 在执行完当前事件处理程序之后,停止当前节点以及所有后续节点的事件处理程序的运行
  99. // var copytext = window.getSelection().toString();
  100. // //console.log(await navigator.clipboard.readText());
  101. // await navigator.clipboard.writeText(window.getSelection().toString());
  102. //
  103. //
  104. // // 没有效果
  105. // // var clipdata = e.clipboardData || window.clipboardData;
  106. // // console.log(clipdata.getData('Text'));
  107. // // console.log(clipdata.getData('text/plain'));
  108. // // let clipboardItems = [];
  109. // // console.log("items begin");
  110. // // for (const item of e.clipboardData.items) {
  111. // // console.log(item);
  112. // // if (!item.type.startsWith('image/')) {
  113. // // continue;
  114. // // }
  115. // // clipboardItems.push(
  116. // // new ClipboardItem({
  117. // // [item.type]: item,
  118. // // })
  119. // // );
  120. // // }
  121. // // if (clipdata) {
  122. // // clipdata.setData('text/plain', copytext);
  123. // // clipdata.setData('Text', copytext);
  124. // // }
  125. // }
  126. // var targets=document.querySelectorAll('div.article-holder');
  127. // for(let i=0;i<targets.length;i++){
  128. // targets[i].oncopy=clean;
  129. // }
  130. //
  131. // // 因为B站js函数中有这样的代码,
  132. // // i.preventDefault(),
  133. // // i.stopPropagation()
  134. // // 所以直接在body上面家 listener 没有效果
  135. // // document.body.addEventListener('copy', clean);
  136. // // document.body.oncopy=clean;
  137. // }
  138.  
  139.  
  140. function do_geekbang(){
  141. var last_selection;
  142. var last_selection_string;
  143. var last_selection_range=[];
  144. var last_change_is_copy=false;
  145. document.onselectionchange=(e)=>{
  146. //console.log("on selection changed");
  147. if(last_change_is_copy==true){
  148. //console.log("the fake change!")
  149. last_change_is_copy=false;
  150. return;
  151. }
  152. last_selection=window.getSelection();
  153. // 这句报错不知道怎么做申拷贝
  154. //last_selection=Object.assign({},window.getSelection());
  155. //console.log(last_selection.toString());
  156. last_selection_string=""+last_selection.toString();
  157. last_selection_range=[];
  158. for(var i=0;i<last_selection.rangeCount;i++){
  159. last_selection_range.push(last_selection.getRangeAt(i));
  160. }
  161.  
  162. }
  163.  
  164. async function clean(e) {
  165. // 由于 增加版权声明的代码中有这样的代码
  166. // var e = window.getSelection(),
  167. // e.selectAllChildren(s),
  168. // 这里这句为了防止错误的保存这次变化
  169. last_change_is_copy=true;
  170.  
  171. // window.getSelection() 要用copy,深拷贝才行
  172. //console.log(last_selection==window.getSelection());
  173.  
  174. //此方法可以缓解问题,但是会导致只能复制到单个element 的内容
  175. //window.getSelection().selectAllChildren(e.target);
  176.  
  177. var currnent_selection=window.getSelection();
  178. currnent_selection.removeAllRanges();
  179. for(var i=0;i<last_selection_range.length;i++){
  180. currnent_selection.addRange(last_selection_range[0]);
  181. }
  182. // range 和 直接改clipboard 二选一, clipboard 的结果可以覆盖 window.getSelection() 的状态
  183. //console.log("last_selection string");
  184. //console.log(last_selection_string);
  185. //await navigator.clipboard.writeText(last_selection_string);
  186. //await navigator.clipboard.writeText("测试");
  187. }
  188. document.body.oncopy=clean;
  189. /*
  190. // 由于网站 js 中没有加
  191. // i.stopPropagation()
  192. // 所以不用在同一层,只要在上层(body)处理就可以了
  193. function callback(records){
  194. records.map(function (record) {
  195. if (record.addedNodes.length != 0) {
  196. for(var i=0;i<record.addedNodes.length;i++){
  197. var node=record.addedNodes[i];
  198. if(node.className=="quiz-box"){
  199. var targets=node.querySelectorAll("div#article-content.richcontent");
  200. console.log(targets);
  201. for(let i=0;i<targets.length;i++){
  202. targets[i].oncopy=clean;
  203. }
  204. }
  205. }
  206. }
  207. });
  208. }
  209.  
  210.  
  211.  
  212. var mo = new MutationObserver(callback);
  213.  
  214. var option = {
  215. 'childList': true,
  216. 'subtree': true,
  217. };
  218.  
  219. mo.observe(document.body, option);
  220. */
  221. }
  222.  
  223.  
  224. (function() {
  225. 'use strict';
  226. if(location.href.match("https://[a-z]+.douban.com")!=null){
  227. do_douban();
  228. }else if(location.href.match("https://[a-z]+.csdn.net")!=null){
  229. do_csdn();
  230. }else if(location.href.match("https://[a-z]+.bilibili.com")!=null){
  231. do_bilibili();
  232. }else if(location.href.match("https://juejin.cn")!=null){
  233. do_juejin();
  234. }else if(location.href.match("https?://www.360doc.com")!=null){
  235. do_360doc();
  236. }else if(location.href.match("https://[a-z]+.geekbang.org")!=null){
  237. do_geekbang();
  238. }else if(location.href.match("https://[a-z]+.zhihu.com")!=null){
  239. do_zhihu();
  240. }else{
  241. document.body.oncopy=(e)=>{e.stopPropagation();};
  242. //document.documentElement.addEventListener('copy',function(e){e.stopImmediatePropagation()});
  243. //document.documentElement.addEventListener('copy',function(e){e.stopPropagation()});
  244. //document.body.addEventListener('copy',function(e){e.stopPropagation()});
  245. //document.body.oncopy=function(e){e.stopPropagation()};
  246. }
  247.  
  248.  
  249. /*
  250. var targets=document.querySelectorAll('span.RichText.CopyrightRichText-richText');
  251. for(let i=0;i<targets.length;i++){
  252. //rewrite_html(targets[i].parentElement);
  253. targets[i].oncopy=(e)=>{e.stopPropagation();};
  254. targets[i].parentElement.oncopy=(e)=>{e.stopPropagation();};
  255. targets[i].parentElement.parentElement.oncopy=(e)=>{e.stopPropagation();};
  256. }*/
  257. })();

QingJ © 2025

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