CSDN-筑基

仅供参考学习

当前为 2022-09-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name CSDN-筑基
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @match *://*.blog.csdn.net/*
  6. // @icon chrome://favicon/http://blog.csdn.net/
  7. // @description 仅供参考学习
  8. // @author haiw2
  9. // @grant GM_setClipboard
  10. // @reference https://source.unsplash.com/random
  11. // @namespace https://gf.qytechs.cn/zh-CN/scripts/432021
  12. // @supportURL https://github.com/haiw2/MonkeyScript
  13. // @homepageURL https://github.com/haiw2/MonkeyScript
  14. // ==/UserScript==
  15. (function() {
  16. 'use strict';
  17.  
  18. function HAIW2(){};
  19. HAIW2.prototype = {
  20. status: -1,
  21. // 属性变化监听器
  22. attribute_change_listener: function(node){
  23. let listen_op = {attributes:true};
  24. function callback(mutationsList){
  25. node.style.left = "";
  26. };
  27. var observer = new MutationObserver(callback);
  28. observer.observe(node, listen_op);
  29. },
  30. // 复制权限
  31. modifyCopyPriviledge: function(codeElem,signElem){
  32. //代码容器修改
  33. codeElem.removeAttribute('onclick');
  34. codeElem.style.setProperty('user-select','auto');
  35. codeElem.parentNode.style.setProperty('user-select','auto');
  36. codeElem.parentNode.style.setProperty('margin-bottom','30px');
  37. // 登录(不可用)容器修改
  38. try{
  39. signElem.removeAttribute('onclick');
  40. signElem.setAttribute('data-title','点击复制');
  41. signElem.style.margin = '0';
  42. // signElem.style.setProperty('margin-bottom', '40px');
  43. signElem.style.setProperty('max-width','80px');
  44. signElem.style.setProperty('min-height','15px');
  45. signElem.style.setProperty('font-size','15px');
  46. // signElem.style.left = '56px';
  47. return true
  48. }catch(e){
  49. return false
  50. }finally{
  51. // 复制按钮位置变化 代码块并列、代码块内、代码块外
  52. codeElem.parentNode.insertBefore(signElem, codeElem);
  53. }
  54. },
  55. // 复制逻辑
  56. copy: function(signElem) {
  57. let codeelem = null;
  58. try{
  59. codeelem = signElem.parentNode;
  60. if(codeelem.id.indexOf('code')===-1){ // 父节点
  61. throw new EvalError('值错误');
  62. }
  63. }catch(err){// 兄弟节点
  64. codeelem = signElem.previousElementSibling;
  65. }
  66. document.oncopy=function(e){
  67. e.clipboardData.setData('text',codeelem.innerText);
  68. e.preventDefault();
  69. document.oncopy=null;
  70. }
  71. document.execCommand("Copy");// 执行浏览器复制命令
  72. signElem.setAttribute('data-title','复制成功');
  73. signElem.style.cssText += 'background-color: green';
  74. setTimeout(()=>{ // 先延时1000ms,再执行回调函数
  75. signElem.setAttribute('data-title','点击复制');
  76. signElem.style.removeProperty('background-color','green');
  77. },1000);
  78. },
  79. // 小飞侠
  80. modifyFocusPriviledge: function(that){
  81. let toolbar = document.querySelector('.csdn-side-toolbar');
  82. toolbar.style.right = "20px";
  83. toolbar.style.position = "fixed";
  84. let focusSwitch = document.querySelector('.option-box').cloneNode(true);
  85. focusSwitch.firstElementChild.src = 'https://s1.aigei.com/src/img/png/05/055f0df239ef4451a25be1e5c4617f96.png?imageMogr2/auto-'+
  86. 'orient/thumbnail/!199x199r/gravity/Center/crop/199x199/quality/85/&e=1735488000&'+
  87. 'token=P7S2Xpzfz11vAkASLTkfHN7Fw-oOZBecqeJaxypL:pxpJ0L3fOUppABVi15gOFs94eqk=';
  88. focusSwitch.style.background = "rgba(0,0,0,0.1)";
  89. focusSwitch.firstElementChild.style.width = "200%";
  90. focusSwitch.firstElementChild.style.display = "block"; // 去除初始鼠标放上有动态加载事件
  91. focusSwitch.removeChild(focusSwitch.lastElementChild);
  92. focusSwitch.removeAttribute('mouseup');
  93. toolbar.replaceChildren(focusSwitch);
  94. toolbar.style.right = '0';
  95. let head_toolbar = document.getElementById('csdn-toolbar');
  96. // 重点:回调函数传入的参数在哪个域下,那么此回调函数内部的this就指向谁
  97. head_toolbar.style.display = 'none';
  98. // 进入全屏
  99. that.fullScreenRead(false);
  100. focusSwitch.addEventListener('click', function(){
  101. // 重点:回调函数传入的参数在哪个域下,那么此回调函数内部的this就指向谁
  102. that.status = ~that.status;
  103. if(that.status==0) head_toolbar.style.display = 'none';
  104. else head_toolbar.style.display = 'block';
  105. // 进入全屏
  106. that.fullScreenRead(that.status);
  107. },'true');
  108.  
  109. },
  110. // 删除选中复制多段,粘贴出现版权信息
  111. delete_copy_right: function(){
  112. csdn.copyright.textData = '';
  113. },
  114. // 删除右下角小辣条广告
  115. delete_right_aside_ad: function(){
  116. let toolbar = document.querySelector('.csdn-side-toolbar');
  117. toolbar.addEventListener("DOMNodeInserted", function(e) {
  118. if(e.target.className=='csdn-common-logo-advert') toolbar.removeChild(toolbar.firstElementChild);
  119. });
  120. },
  121. // 删除头部“大屏-小屏”动画广告
  122. delete_head_ad: function(){
  123. let head_nav_toolbar = document.querySelector('#csdn-toolbar');
  124. head_nav_toolbar.addEventListener("DOMNodeInserted", function() {
  125. if(head_nav_toolbar.firstElementChild.className==='toolbar-advert') head_nav_toolbar.removeChild(head_nav_toolbar.firstElementChild);
  126. });
  127. },
  128. // 删除登录(不可用)弹窗
  129. delete_login_dialog: function(){
  130. document.body.addEventListener("DOMNodeInserted", function() {
  131. let login1 = document.querySelector('#app');
  132. let login2 = document.querySelector('#passportbox');
  133. if (login1!=null) login1.style.display = 'none';
  134. if (login2!=null) {
  135. login2.style.display = 'none';
  136. login2.previousElementSibling.style.display = 'none';
  137. }
  138. });
  139. },
  140. // 允许复制
  141. allow_copy: function(){
  142. let codes = document.querySelectorAll('#content_views pre code');
  143. let signs = document.querySelectorAll('#content_views .signin');
  144. // 解决部分文章允许不登陆复制的脚本定位问题
  145. if(signs.length===0) signs = document.querySelectorAll('#content_views .hljs-button');
  146. for(var i=0;i<codes.length;i++){
  147. let sign = signs[i], code = codes[i];
  148. this.modifyCopyPriviledge(code, sign);
  149. sign.addEventListener('click', function(){
  150. GM_setClipboard(code.innerText, "text");
  151. sign.setAttribute('data-title','复制成功');
  152. sign.style.cssText += 'background-color: green';
  153. setTimeout(()=>{ // 先延时1000ms,再执行回调函数
  154. sign.setAttribute('data-title','点击复制');
  155. sign.style.removeProperty('background-color','green');
  156. },1000);
  157. },'true');
  158. }
  159. },
  160. // 专注阅读
  161. fullScreenRead: function(status){
  162. let leftSide = document.querySelector('.blog_container_aside');
  163. let father = document.querySelector('.main_father');
  164. let main = father.querySelector('main');
  165. leftSide.childNodes.forEach((item,index)=>{
  166. if(status==0 && item.firstElementChild && item.id!='asidedirectory'){
  167. item.style.setProperty('display', 'none');
  168. main.style.setProperty('width','100%');
  169. }
  170. if(status==0 && item.id=='asidedirectory'){
  171. item.style.position = 'fixed';
  172. item.style.left = '0';
  173.  
  174. console.log(item.firstChild);
  175.  
  176. // item.querySelector('.aside-title').style.background = 'rgba(0,0,0,.7)';
  177. // item.querySelector('.group_item').style.background = 'rgba(0,0,0,.7)';
  178. const toc = item.querySelector('.aside-title');
  179. toc.parentNode.style.width = 'auto';
  180. toc.parentNode.style.background = '#6c928c';
  181. toc.style.background = 'transparent';
  182. const content = item.querySelector('.group_item');
  183. content.style.display = 'None';
  184. let showTOC = false;
  185. toc.addEventListener('click', ()=>{
  186. showTOC = ~showTOC;
  187. if (showTOC){
  188. toc.parentNode.style.width = '300px';
  189. toc.style.removeProperty('background: #f5f5f5');
  190. content.style.display = 'block';
  191. }else{
  192. toc.parentNode.style.width = 'auto';
  193. toc.parentNode.style.background = 'background: #6c928c';
  194. content.style.display = 'None';
  195.  
  196. }
  197.  
  198. })
  199.  
  200.  
  201. father.style.margin = '0';
  202. father.style.padding = '0';
  203. father.firstElementChild.style.width = '100%';
  204. main.style.setProperty('width','100%');
  205. }
  206.  
  207. if(status!=0 && item.firstElementChild && item.id!='asidedirectory'){
  208. item.style.display = 'block';
  209. main.style.removeProperty('width');
  210.  
  211. }
  212. if(status!=0 && item.firstElementChild && item.id=='asidedirectory'){
  213. item.style.removeProperty('position');
  214. item.style.removeProperty('right');
  215. father.style.removeProperty('margin');
  216. father.style.removeProperty('padding');
  217. father.firstElementChild.style.removeProperty('width');
  218. main.style.removeProperty('width');
  219. }
  220.  
  221. })
  222. },
  223.  
  224. delete_or_unvisable_elem: function (selector, method){
  225. const elem = document.querySelector(selector);
  226. if (method === 'del') elem.parentNode.removeChild(elem);
  227. else elem.style.display = 'None';
  228. },
  229. delete_author_toolbox: function(selector){
  230. this.delete_or_unvisable_elem(selector, 'del');
  231. }
  232. };
  233.  
  234. const w2 = new HAIW2();
  235. let that = this;
  236. w2.delete_copy_right();
  237. w2.delete_head_ad();
  238. w2.delete_right_aside_ad();
  239. w2.delete_login_dialog();
  240. w2.allow_copy();
  241. w2.modifyFocusPriviledge(w2);
  242. w2.delete_author_toolbox('.left-toolbox');
  243. })();

QingJ © 2025

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