Sun of North America

The Only, the Holy, President Donald J. Trump, the Sun of North America!

  1. // ==UserScript==
  2. // @name Sun of North America
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description The Only, the Holy, President Donald J. Trump, the Sun of North America!
  6. // @author TechCiel
  7. // @license WTFPL
  8. // @match https://www.whitehouse.gov/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=whitehouse.gov
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (()=>{
  14. 'use strict';
  15. const regex = /((?:President )?(?:Donald )?(?:J. )?(?<!Melania )(?<!Ivanka )(?<!Ivana )(?<!Barron )(?<!Tiffany )(?<!Eric )(?<!Mrs\. )Trump)/gi;
  16.  
  17. function update() {
  18. console.log('Be careful, the sun\'s rising!');
  19. // 创建TreeWalker遍历所有符合条件的文本节点
  20. const walker = document.createTreeWalker(
  21. document.body,
  22. NodeFilter.SHOW_TEXT,
  23. {
  24. acceptNode: function(node) {
  25. // 排除不需要处理的父元素标签
  26. const parentTag = node.parentNode.tagName.toLowerCase();
  27. const excludeTags = ['script', 'style', 'noscript', 'textarea', 'option', 'meta', 'title'];
  28. return excludeTags.includes(parentTag) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT;
  29. }
  30. },
  31. false
  32. );
  33.  
  34. // 收集所有文本节点
  35. const textNodes = [];
  36. let node;
  37. while (node = walker.nextNode()) textNodes.push(node);
  38.  
  39. // 处理每个文本节点
  40. textNodes.forEach((textNode) => {
  41. const content = textNode.textContent;
  42. if (content.search(regex) === -1) return;
  43. if (textNode.parentNode.className == 'sun-of-north-america') return;
  44.  
  45. // 分割文本为多个部分
  46. const parts = content.split(regex);
  47. const fragment = document.createDocumentFragment();
  48.  
  49. parts.forEach(part => {
  50. if (part === '') return; // 忽略空字符串
  51. if (part.match(regex)) {
  52. const span = document.createElement('span');
  53. span.textContent = part;
  54. span.className = 'sun-of-north-america';
  55. fragment.appendChild(span);
  56. } else {
  57. fragment.appendChild(document.createTextNode(part));
  58. }
  59. });
  60.  
  61. // 替换原始文本节点
  62. textNode.parentNode.replaceChild(fragment, textNode);
  63. })
  64. }
  65.  
  66. update();
  67.  
  68. //setInterval(update, 2000);
  69. window.navigation && window.navigation.addEventListener('navigate', update);
  70. window.addEventListener('click', update);
  71.  
  72. // 添加样式
  73. let styleNode = document.createElement("style");
  74. styleNode.textContent = 'span.sun-of-north-america { font-size:1.5em; font-weight:bolder; cursor: none; user-select: none }';
  75. document.head.appendChild(styleNode);
  76. })()

QingJ © 2025

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