Custom Change Color Script

Заменяет указанные цвета на других доменах

  1. // ==UserScript==
  2. // @name Custom Change Color Script
  3. // @name:ru Скрипт для замены указанного цвета на странице
  4. // @namespace http://tampermonkey.net/
  5. // @version 1.1
  6. // @description:en Change specific colors to another on selected domains
  7. // @description:ru Заменяет указанные цвета на других доменах
  8. // @author Shaman_Lesnoy
  9. // @match *://*/*
  10. // @grant none
  11. // @license GPL-3.0
  12. // @description Заменяет указанные цвета на других доменах
  13. // ==/UserScript==
  14.  
  15. const SOURCE_COLOR = '#5cdd8b'; // целевой hex цвет
  16. const TARGET_COLOR = '#93fab9'; // новый hex цвет
  17. const ALLOWED_DOMAINS = ['example.com', 'anotherdomain.com']; // Список доменов
  18.  
  19. (function() {
  20. 'use strict';
  21.  
  22. const currentDomain = window.location.hostname;
  23.  
  24. if (!ALLOWED_DOMAINS.some(domain => currentDomain.includes(domain))) {
  25. return;
  26. }
  27.  
  28. function hexToRgb(hex) {
  29. const bigint = parseInt(hex.slice(1), 16);
  30. const r = (bigint >> 16) & 255;
  31. const g = (bigint >> 8) & 255;
  32. const b = bigint & 255;
  33. return `rgb(${r}, ${g}, ${b})`;
  34. }
  35.  
  36. const sourceRgb = hexToRgb(SOURCE_COLOR);
  37. const targetColor = TARGET_COLOR;
  38.  
  39. function updateColors() {
  40. document.querySelectorAll('*').forEach(el => {
  41. const styles = getComputedStyle(el);
  42. if (styles.color === sourceRgb) {
  43. el.style.setProperty('color', targetColor, 'important');
  44. }
  45. if (styles.backgroundColor === sourceRgb) {
  46. el.style.setProperty('background-color', targetColor, 'important');
  47. }
  48. if (styles.borderColor === sourceRgb) {
  49. el.style.setProperty('border-color', targetColor, 'important');
  50. }
  51. });
  52. }
  53.  
  54. function processShadowRoots(node) {
  55. if (node.shadowRoot) {
  56. updateColorsInShadow(node.shadowRoot);
  57. }
  58. node.childNodes.forEach(child => processShadowRoots(child));
  59. }
  60.  
  61. function updateColorsInShadow(shadowRoot) {
  62. shadowRoot.querySelectorAll('*').forEach(el => {
  63. const styles = getComputedStyle(el);
  64. if (styles.color === sourceRgb) {
  65. el.style.setProperty('color', targetColor, 'important');
  66. }
  67. if (styles.backgroundColor === sourceRgb) {
  68. el.style.setProperty('background-color', targetColor, 'important');
  69. }
  70. if (styles.borderColor === sourceRgb) {
  71. el.style.setProperty('border-color', targetColor, 'important');
  72. }
  73. });
  74. }
  75.  
  76. const observer = new MutationObserver(() => {
  77. updateColors();
  78. processShadowRoots(document.body);
  79. });
  80.  
  81. observer.observe(document.body, { childList: true, subtree: true });
  82.  
  83. updateColors();
  84. processShadowRoots(document.body);
  85. })();