网站好帮手

本脚本提供了一系列小工具,在您访问互联网网站的时候加快您访问网站的速度和提高您的工作效率。包括删除服务器重定向(支持全网网站)

安装此脚本?
作者推荐脚本

您可能也喜欢GreasyFork网站助手

安装此脚本
  1. // ==UserScript==
  2. // @name Website helper
  3. // @name:zh-CN 网站好帮手
  4. // @name:zh-TW 网站好帮手
  5. // @namespace https://github.com/kingphoenix2000/tampermonkey_scripts
  6. // @supportURL https://github.com/kingphoenix2000/tampermonkey_scripts
  7. // @version 0.2.0
  8. // @author 浴火凤凰(QQ:307053741,油猴脚本讨论QQ群:194885662)
  9. // @description This script provides a series of small tools to speed up the speed of your visit to the website and improve your work efficiency.
  10. // @description:zh-CN 本脚本提供了一系列小工具,在您访问互联网网站的时候加快您访问网站的速度和提高您的工作效率。包括删除服务器重定向(支持全网网站)
  11. // @description:zh-TW 本脚本提供了一系列小工具,在您访问互联网网站的时候加快您访问网站的速度和提高您的工作效率。包括删除服务器重定向(支持全网网站)
  12. // @homepage https://blog.csdn.net/kingwolf_javascript/
  13. // @include *
  14. // @grant GM_getValue
  15. // @grant GM_setValue
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_setClipboard
  18. // @noframes
  19. // @note 2020-04-10:添加删除服务器跳转功能。
  20. // @note 2020-04-12:修改域名解析函数。
  21. // @note 2020-04-19:增加 回到顶部 功能。
  22. // @note 2021-09-03:增加 Ctrl+单击 可 复制网页标题和域名 功能。查看当前页面收到了哪些Message消息。
  23. // ==/UserScript==
  24.  
  25. (function () {
  26. 'use strict';
  27. document.addEventListener("click", function (e) {
  28. if (e.ctrlKey == true) {
  29. let title = document.title;
  30. let domain = location.hostname;
  31. let str = title + " | " + domain;
  32. GM_setClipboard(str);
  33. }
  34. }, false);
  35. window.addEventListener("message", function (e) { console.groupCollapsed("当前页面收到Message消息:"); console.log(e); console.groupEnd(); }, false);
  36.  
  37. let div1 = document.createElement("div");
  38. div1.id = "returnToTop";
  39. div1.innerHTML = "回到顶部";
  40. div1.style.cssText = "display:none;font-size:15px;padding: 10px;bottom: 5px;right: 5px;z-index: 1000;background-color: gray;position: fixed;border-radius: 25px;text-align: center;cursor: pointer;color: #fff;";
  41. div1.onclick = function () { scrollTo(0, 0); }
  42. let height = document.documentElement.scrollHeight;
  43. if (height > 2000) { div1.style.display = "block"; }
  44. document.body.appendChild(div1);
  45.  
  46.  
  47. let WebSite = JSON.parse(GM_getValue("Phoenix_City_WebSite", false));
  48. // console.log(WebSite);
  49. let redirect_URL_list = [];
  50. if (WebSite) {
  51. //以下代码为升级版本的兼容性代码
  52. if (!WebSite.Redirect_URL_List) {
  53. for (let domain in WebSite) {
  54. let links = WebSite[domain].removeURLList;
  55. for (let i = 0; i < links.length; i++) {
  56. let url = links[i];
  57. if (!redirect_URL_list.includes(url)) {
  58. redirect_URL_list.push(url);
  59. }
  60. }
  61. }
  62. WebSite = {};
  63. WebSite.Redirect_URL_List = redirect_URL_list;
  64. console.log(WebSite);
  65. GM_setValue("Phoenix_City_WebSite", JSON.stringify(WebSite));
  66. }
  67. }
  68. else {
  69. WebSite = {};
  70. WebSite.Redirect_URL_List = redirect_URL_list;
  71. }
  72. console.log(WebSite);
  73.  
  74. let num = 0;
  75. function removeRedirectURL(msg, links) {
  76. let len1 = WebSite.Redirect_URL_List.length;
  77. for (let i = 0; i < links.length; i++) {
  78. let href = links[i].getAttribute("href");
  79. if (href.startsWith("http")) {
  80. for (let j = 0; j < len1; j++) {
  81. const url = WebSite.Redirect_URL_List[j];
  82. if (href.startsWith(url)) {
  83. href = href.replace(url, '');
  84. href = decodeURIComponent(href);
  85. break;
  86. }
  87. }
  88. for (let j = 0; j < len1; j++) {
  89. const url = WebSite.Redirect_URL_List[j];
  90. if (href.startsWith(url)) {
  91. href = href.replace(url, '');
  92. href = decodeURIComponent(href);
  93. break;
  94. }
  95. }
  96. for (let j = 0; j < len1; j++) {
  97. const url = WebSite.Redirect_URL_List[j];
  98. if (href.startsWith(url)) {
  99. href = href.replace(url, '');
  100. href = decodeURIComponent(href);
  101. break;
  102. }
  103. }
  104. if (href.startsWith("http")) {
  105. links[i].href = href;
  106. }
  107. else {
  108. console.log("发现类似重定向,实际上不是重定向的网址: ", links[i].href);
  109. }
  110. }
  111. }
  112. num = num + links.length;
  113. // console.log(msg, "目前已经删除重定向的链接数:", num);
  114. }
  115. //首先删除已经加载的超链接的重定向
  116. removeRedirectURL("页面初始化阶段-->", document.links);
  117.  
  118.  
  119. const MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  120. var mutationObserver = new MutationObserver(function (mutations, instance) {
  121. //console.log(instance);
  122. mutations.forEach(function (mutation) {
  123. let addedNodes = mutation.addedNodes;
  124. if (addedNodes.length > 0) {
  125. addedNodes.forEach(function (node) {
  126. if (node.nodeType == 1) {
  127. removeRedirectURL("页面链接动态加载阶段-->", node.querySelectorAll("a"));
  128. }
  129. });
  130. }
  131. });
  132. });
  133.  
  134. // 开始监听页面根元素 HTML 变化。
  135. mutationObserver.observe(document.body, {
  136. childList: true,
  137. subtree: true
  138. });
  139. GM_registerMenuCommand("添加重定向链接", () => {
  140. let url = prompt("链接必须以http或者https开头,并且带有?和=\n类似于:https://link.zhihu.com/?target=", "");
  141. if (url) {
  142. if (WebSite.Redirect_URL_List.includes(url)) {
  143. console.log(`要添加的重定向URL${url}已经存在。`);
  144. }
  145. else {
  146. WebSite.Redirect_URL_List.push(url);
  147. GM_setValue("Phoenix_City_WebSite", JSON.stringify(WebSite));
  148. console.log(`重定向URL${url} 添加成功。`);
  149. }
  150. }
  151. });
  152. GM_registerMenuCommand("删除重定向链接", () => {
  153. let url = prompt("链接必须以http或者https开头,并且带有?和=\n类似于:https://link.zhihu.com/?target=", "");
  154. if (url) {
  155. let index = WebSite.Redirect_URL_List.indexOf(url);
  156. if (index == -1) {
  157. console.log(`找不到要删除的重定向URL${url}。`);
  158. }
  159. else {
  160. WebSite.Redirect_URL_List.splice(index, 1);
  161. GM_setValue("Phoenix_City_WebSite", JSON.stringify(WebSite));
  162. console.log(`重定向URL${url} 删除成功。`);
  163. }
  164. }
  165. });
  166.  
  167. })();