嘀咚纽森-程序设计文档显示扩展-2024-10-29.user.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // ==UserScript==
  2. // @name 嘀咚纽森-程序设计文档显示扩展
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-10-29
  5. // @description try to take over the world!
  6. // @author You
  7. // @match *://*/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=0.1
  9. // @grant none
  10. // ==/UserScript==
  11. (function() {
  12. 'use strict';
  13. // 添加CSS样式
  14. const style = document.createElement('style');
  15. style.type = 'text/css';
  16. style.innerHTML = `
  17. g.node:hover {
  18. cursor: pointer;
  19. background: gray; /* hover时的背景颜色 */
  20. fill: green; /* 可以自定义hover时的填充颜色 */
  21. stroke: darkgreen; /* 可以自定义hover时的边框颜色 */
  22. stroke-width: 2px; /* 可以自定义hover时的边框宽度 */
  23. }
  24. `;
  25. document.head.appendChild(style);
  26. // 查找所有符合条件的 <line> 元素
  27. const lines = document.querySelectorAll('line,path');
  28. lines.forEach(line => {
  29. // 获取前一个兄弟元素的文本内容
  30. const prevElement = line.previousElementSibling;
  31. if (prevElement && prevElement.tagName.toLowerCase() === 'text') {
  32. const textElement = prevElement;
  33. const anchorText = textElement.textContent.trim();
  34. const anchorLink = window.location.href.split('#')[0] + '#' + encodeURIComponent(anchorText);
  35. // 为 <text> 元素添加点击事件
  36. textElement.addEventListener('click', () => {
  37. window.location.href = anchorLink;
  38. });
  39. // 设置鼠标指针样式为手形,颜色为绿色
  40. textElement.style.cursor = 'pointer';
  41. textElement.style.fill = 'green';
  42. }
  43. });
  44. // 给所有class为node的g标签增加鼠标可点击的hover样式
  45. const nodes = document.querySelectorAll('g.node');
  46. nodes.forEach(node => {
  47. node.addEventListener('mouseover', () => {
  48. node.style.fill = 'green'; // hover时的填充颜色
  49. node.style.stroke = 'darkgreen'; // hover时的边框颜色
  50. node.style.strokeWidth = '2'; // hover时的边框宽度
  51. });
  52. node.addEventListener('mouseout', () => {
  53. node.style.fill = ''; // 恢复默认填充颜色
  54. node.style.stroke = ''; // 恢复默认边框颜色
  55. node.style.strokeWidth = ''; // 恢复默认边框宽度
  56. });
  57. });
  58. })();