稍微放大电脑网站的字体

稍微放大电脑网站的字体,脚本菜单可以控制网站启用与禁用,并设置单独网站的字体和行间距倍数。

目前為 2023-03-08 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 稍微放大电脑网站的字体
  3. // @author ChatGPT定制
  4. // @version 4
  5. // @description 稍微放大电脑网站的字体,脚本菜单可以控制网站启用与禁用,并设置单独网站的字体和行间距倍数。
  6. // @match *://*/*
  7. // @grant GM_registerMenuCommand
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @run-at document-end
  11. // @namespace https://gf.qytechs.cn/users/452911
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16.  
  17. var storageKey = window.location.href.replace(/\/|\./g, "_");
  18. var isEnabled = GM_getValue(storageKey + "_enabled", true);
  19. var fontMultiplier = GM_getValue(
  20. storageKey + "_font_multiplier",
  21. 1.04
  22. );
  23. var lineHeightMultiplier = GM_getValue(
  24. storageKey + "_line_height_multiplier",
  25. 1.08
  26. );
  27.  
  28. function enlargeFontSize() {
  29. const rootFontSize = parseFloat(
  30. getComputedStyle(document.documentElement).fontSize
  31. );
  32. const newRootFontSize = rootFontSize * fontMultiplier;
  33. document.documentElement.style.fontSize = `${newRootFontSize}px`;
  34. const rootLineHeight = parseFloat(
  35. getComputedStyle(document.documentElement).lineHeight
  36. );
  37. const newRootLineHeight = rootLineHeight * lineHeightMultiplier;
  38. document.documentElement.style.lineHeight = `${newRootLineHeight}px`;
  39. const elementsToScale = document.querySelectorAll("*");
  40. elementsToScale.forEach((element) => {
  41. const fontSize = parseFloat(getComputedStyle(element).fontSize);
  42. element.style.fontSize = `${(fontSize / rootFontSize) * newRootFontSize}px`;
  43. const lineHeight = parseFloat(getComputedStyle(element).lineHeight);
  44. element.style.lineHeight = `${
  45. (lineHeight / rootLineHeight) * newRootLineHeight
  46. }px`;
  47. });
  48. }
  49.  
  50. function checkFontSize() {
  51. const width = window.innerWidth;
  52. if (width > 700) {
  53. enlargeFontSize();
  54. }
  55. }
  56.  
  57. if (isEnabled) {
  58. window.addEventListener("resize", checkFontSize);
  59. checkFontSize();
  60. }
  61.  
  62. GM_registerMenuCommand(isEnabled ? "禁用字体放大" : "启用字体放大", function () {
  63. isEnabled = !isEnabled;
  64. GM_setValue(storageKey + "_enabled", isEnabled);
  65. if (isEnabled) {
  66. window.addEventListener("resize", checkFontSize);
  67. checkFontSize();
  68. } else {
  69. document.documentElement.style.fontSize = "";
  70. document.documentElement.style.lineHeight = "";
  71. const elementsToReset = document.querySelectorAll("*");
  72. elementsToReset.forEach((element) => {
  73. element.style.fontSize = "";
  74. element.style.lineHeight = "";
  75. });
  76. window.removeEventListener("resize", checkFontSize);
  77. }
  78. });
  79.  
  80. GM_registerMenuCommand("调整字体大小", function () {
  81. var newFontMultiplier = prompt(
  82. "请输入字体大小倍数",
  83. fontMultiplier.toString()
  84. );
  85. if (newFontMultiplier !== null) {
  86. fontMultiplier = parseFloat(newFontMultiplier);
  87. GM_setValue(storageKey + "_font_multiplier", fontMultiplier);
  88. checkFontSize();
  89. }
  90. });
  91.  
  92. GM_registerMenuCommand("调整行间距", function () {
  93. var newLineHeightMultiplier = prompt(
  94. "请输入行间距倍数",
  95. lineHeightMultiplier.toString()
  96. );
  97. if (newLineHeightMultiplier !== null) {
  98. lineHeightMultiplier = parseFloat(newLineHeightMultiplier);
  99. GM_setValue(
  100. storageKey + "_line_height_multiplier",
  101. lineHeightMultiplier
  102. );
  103. checkFontSize();
  104. }
  105. });
  106. })();

QingJ © 2025

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