更换腾讯文档背景颜色

如题

  1. // ==UserScript==
  2. // @name 更换腾讯文档背景颜色
  3. // @namespace https://palerock.cn
  4. // @version 1.0.1
  5. // @description 如题
  6. // @include https://docs.qq.com/doc/*
  7. // @author Cangshi
  8. // @license GPL-3.0-or-later
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function (factory) {
  13. typeof define === 'function' && define.amd ? define(factory) :
  14. factory();
  15. }((function () { 'use strict';
  16.  
  17. var isDOMLoaded = false;
  18. var waitLoadList = [];
  19. var style = null; // 向head注入样式
  20.  
  21. function injectStyle(css) {
  22. var style = document.createElement('style');
  23. style.innerHTML = css; // @ts-ignore
  24.  
  25. style.name = 'injected-style';
  26. document.head.appendChild(style);
  27. return style;
  28. } // 取消样式注入
  29.  
  30.  
  31. function removeStyle(style) {
  32. if (style && style.parentNode) {
  33. style.parentNode.removeChild(style);
  34. }
  35. } // 获取文档id
  36. // example: https://docs.qq.com/doc/DWlpNenVmR25DQmhU => DWlpNenVmR25DQmhU
  37.  
  38.  
  39. function getDocId() {
  40. var match = window.location.href.match(/docs\.qq\.com\/doc\/([A-Za-z0-9]+)/);
  41. return match ? match[1] : null;
  42. } // 更新脚本样式
  43.  
  44.  
  45. function updateStyle(params) {
  46. if (!params.backgroundColor) {
  47. // 读取保存的 params
  48. params = Object.assign(params, JSON.parse(localStorage.getItem(getDocId()) || '{}')); // 自动改变hash值
  49.  
  50. window.location.hash = params.backgroundColor;
  51. return;
  52. }
  53.  
  54. if (style) {
  55. removeStyle(style);
  56. }
  57.  
  58. style = injectStyle("\n canvas.melo-page-main-view {\n background-color: ".concat(params.backgroundColor, ";\n }\n ")); // 保存文档id和params
  59.  
  60. localStorage.setItem(getDocId(), JSON.stringify(params));
  61. } // 监听url的hash改变
  62.  
  63.  
  64. window.addEventListener('hashchange', function () {
  65. // 更新样式
  66. updateStyle({
  67. backgroundColor: location.hash.replace('#', '')
  68. });
  69. });
  70.  
  71. function onBodyLoad(cb) {
  72. if (isDOMLoaded) {
  73. cb();
  74. return;
  75. }
  76.  
  77. if (waitLoadList.length == 0) {
  78. document.addEventListener('readystatechange', function () {
  79. if (document.readyState === 'interactive' || document.readyState === 'complete') {
  80. waitLoadList = waitLoadList.filter(function (cb) {
  81. if (typeof cb === 'function' && !isDOMLoaded) {
  82. cb(undefined);
  83. }
  84.  
  85. return false;
  86. });
  87. isDOMLoaded = true;
  88. }
  89. });
  90. }
  91.  
  92. waitLoadList.push(cb);
  93. } // 当html页面加载完成时
  94.  
  95.  
  96. onBodyLoad(function () {
  97. updateStyle({
  98. backgroundColor: location.hash.replace('#', '')
  99. });
  100. });
  101.  
  102. })));

QingJ © 2025

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