tab tools

some tools

当前为 2024-08-07 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name tab tools
  3. // @name:zh-CN 标签页小工具
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.5
  6. // @description some tools
  7. // @description:zh-cn 会用到的
  8. // @author onionycs
  9. // @run-at document-start
  10. // @match *://*/*
  11. // @grant GM_registerMenuCommand
  12. // @require http://code.jquery.com/jquery-3.x-git.min.js
  13. // ==/UserScript==
  14.  
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. GM_registerMenuCommand("Remove - title", removeName);
  20. GM_registerMenuCommand("faker", faker);
  21. GM_registerMenuCommand("adjustSSPNOTE", adjustSSPNOTE);
  22. GM_registerMenuCommand("adjustSVISVI", adjustSVISVI);
  23.  
  24.  
  25. function removeName() {
  26. var head = document.getElementsByTagName('head')[0];
  27.  
  28. // 获取所有<title>标签
  29. var titles = head.getElementsByTagName('title');
  30.  
  31. // 遍历<title>标签并删除
  32. for (var i = 0; i < titles.length; i++) {
  33. head.removeChild(titles[i]);
  34. }
  35. }
  36.  
  37. function adjustSSPNOTE() {
  38. var $ = unsafeWindow.jQuery;
  39. console.log("start");
  40. $('div[role="combobox"]')[0].click();
  41. var id=$('div[role="combobox"]')[0].id+'-option-2';
  42. setTimeout(function() {
  43. // 这里写你希望延迟执行的代码
  44. console.log('执行了延迟300ms的代码');
  45. $('#'+id)[0].click();
  46. }, 300);
  47. document.getElementsByClassName("left-content")[0].style.width = "40%";
  48. document.getElementsByClassName("right-content")[0].style.width = "60%";
  49. console.log("end");
  50. }
  51.  
  52. function adjustSVISVI(){
  53. document.getElementsByClassName("editor")[0].style.marginLeft="200px"
  54. document.getElementsByClassName("editor")[0].style.width="1080px"
  55. document.getElementsByClassName("editor")[0].style.maxWidth="1080px"
  56. }
  57.  
  58. function faker() {
  59. // 假设新的favicon图标URL是'new-favicon.ico'
  60. var newFaviconUrl = 'https://img-ys011.didistatic.com/static/cooper_cn/ico-dbook.png';
  61. //var newFaviconUrl = 'file:///users/didi/downloads/wiki.ico';
  62.  
  63.  
  64. // 创建一个新的<link>元素
  65. var link = document.createElement('link');
  66. link.type = 'image/x-icon';
  67. link.rel = 'icon';
  68. link.href = newFaviconUrl;
  69.  
  70. // 查找旧的favicon链接(如果有的话),并移除它
  71. // 注意:这里我们假设只有一个favicon链接,或者我们只关心第一个
  72. // 查找并删除所有rel="shortcut icon"的link元素
  73. var links = document.querySelectorAll('link[rel="shortcut icon"]');
  74. links.forEach(function(link) {
  75. link.remove();
  76. });
  77. // 查找并删除所有rel="shortcut icon"的link元素
  78. links= document.querySelectorAll('link[rel="icon"]');
  79. links.forEach(function(link) {
  80. link.remove();
  81. });
  82.  
  83. // 将新的<link>元素添加到<head>部分
  84. var head = document.head || document.getElementsByTagName('head')[0];
  85. head.appendChild(link);
  86.  
  87. // 注意:在有些情况下,浏览器可能不会立即显示新的favicon
  88. // 这取决于浏览器的缓存策略和实现细节
  89.  
  90. removeName();
  91. var myhead = document.head || document.getElementsByTagName('head')[0];
  92. var title = document.createElement('title');
  93. title.textContent='知识库 - Cooper';
  94. myhead.appendChild(title);
  95. }
  96.  
  97. function replaceTextInNode(node, regex, replacement) {
  98. if (node.nodeType === 3) { // Node.TEXT_NODE
  99. node.textContent = node.textContent.replace(regex, replacement);
  100. } else if (node.nodeType === 1) { // Node.ELEMENT_NODE
  101. Array.from(node.childNodes).forEach(child => {
  102. replaceTextInNode(child, regex, replacement);
  103. });
  104. }
  105. }
  106.  
  107. })();