javaGuideAdRemove

JavaGuide 指北 提示\广告 移除 java面试题

  1. // ==UserScript==
  2. // @name javaGuideAdRemove
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @description JavaGuide 指北 提示\广告 移除 java面试题
  6. // @author Alone
  7. // @match *://*javaguide.cn/*
  8. // @match *://*.yuque.com/snailclimb*
  9. // @require https://code.jquery.com/jquery-3.7.1.slim.js
  10. // @grant none
  11. // @license GPL
  12. // ==/UserScript==
  13. (function () {
  14. 'use strict';
  15.  
  16.  
  17. // 防抖\节流
  18. function debounce(func, wait) {
  19. let timeout;
  20.  
  21. return function () {
  22. const context = this,
  23. args = arguments;
  24.  
  25. // 如果定时器已设置,则清除它
  26. if (timeout) {
  27. clearTimeout(timeout);
  28. }
  29.  
  30. // 设置新的定时器
  31. timeout = setTimeout(() => {
  32. func.apply(context, args);
  33. }, wait);
  34. };
  35. }
  36.  
  37. function modifyIcon() {
  38. // 替换此URL为你想要的图标URL
  39. const newIconUrl = 'https://baidu.com/favicon.ico';
  40.  
  41. // 查找现有的favicon标签
  42. let link = document.querySelector("link[rel*='icon']") || document.createElement('link');
  43. link.type = 'image/x-icon';
  44. link.rel = 'shortcut icon';
  45. link.href = newIconUrl;
  46.  
  47. // 如果favicon标签不存在,则添加它
  48. if (!document.querySelector("link[rel*='icon']")) {
  49. document.getElementsByTagName('head')[0].appendChild(link);
  50. }
  51. }
  52.  
  53. function handle() {
  54. modifyIcon()
  55. $("img[alt='JavaGuide 官方公众号']").remove()
  56.  
  57. $("a[href='/about-the-author/zhishixingqiu-two-years.html']").remove()
  58.  
  59. $(".vp-navbar-start>a").remove()
  60.  
  61. var originalText = "面试";
  62. var newText = "笔记";
  63.  
  64. let title = $("title").html().replace(new RegExp(originalText, 'g'), newText).replace("| JavaGuide", "")
  65.  
  66. $("title").html(title)
  67.  
  68. $('body :not(script)').contents().filter(function () {
  69. return this.nodeType === 3; // 文本节点
  70. }).each(function () {
  71. this.nodeValue = this.nodeValue.replace(new RegExp(originalText, 'g'), newText);
  72. });
  73. $(".hint-container[baseURI='https://javaguide.cn/cs-basics/network/other-network-questions.html']").remove()
  74. $(".hint-container,.tip").remove()
  75. console.log(" 执行成功")
  76. }
  77.  
  78. // 定义一个回调函数,该函数会在DOM变化时被调用
  79. function mutationCallback(mutationsList, observer) {
  80. for (let mutation of mutationsList) {
  81. if (mutation.type === 'childList') {
  82. debounce(handle(), 5000);
  83. break
  84. }
  85. }
  86. }
  87.  
  88. $(document).ready(function () {
  89. handle()
  90. })
  91.  
  92. // 创建一个MutationObserver实例并传入回调函数
  93. const observer = new MutationObserver(mutationCallback);
  94. const config = {childList: true, subtree: true};
  95. const targetNode = document.body;
  96. debounce(observer.observe(targetNode, config), 5000);
  97.  
  98.  
  99. })();

QingJ © 2025

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