Greasy Fork is available in English.
脚本菜单可用于调整网页的字体和行间距倍数
当前为
// ==UserScript==
// @name 调整网页字体和行间距倍数
// @author ChatGPT
// @version 6.3
// @description 脚本菜单可用于调整网页的字体和行间距倍数
// @match *://*/*
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-end
// @namespace http://greasyfork.icu/users/452911
// ==/UserScript==
(function () {
"use strict";
var storageKey = window.location.hostname;
var fontMultiplier = GM_getValue(storageKey + "_font_multiplier", 1);
var lineHeightMultiplier = GM_getValue(
storageKey + "_line_height_multiplier",
1
);
function enlargeFontSize() {
const rootFontSize = parseFloat(
getComputedStyle(document.documentElement).fontSize
);
const newRootFontSize = rootFontSize * fontMultiplier;
document.documentElement.style.fontSize = `${newRootFontSize}px`;
const rootLineHeight = parseFloat(
getComputedStyle(document.documentElement).lineHeight
);
const newRootLineHeight = rootLineHeight * lineHeightMultiplier;
document.documentElement.style.lineHeight = `${newRootLineHeight}px`;
const elementsToScale = document.querySelectorAll("*");
elementsToScale.forEach((element) => {
const fontSize = parseFloat(getComputedStyle(element).fontSize);
element.style.fontSize = `${(fontSize / rootFontSize) * newRootFontSize}px`;
const lineHeight = parseFloat(getComputedStyle(element).lineHeight);
element.style.lineHeight = `${
(lineHeight / rootLineHeight) * newRootLineHeight
}px`;
});
}
enlargeFontSize();
GM_registerMenuCommand("调整字体大小", function () {
var newFontMultiplier = prompt(
"请输入字体大小倍数",
fontMultiplier.toString()
);
if (newFontMultiplier !== null) {
fontMultiplier = parseFloat(newFontMultiplier);
GM_setValue(storageKey + "_font_multiplier", fontMultiplier);
enlargeFontSize();
}
});
GM_registerMenuCommand("调整行间距", function () {
var newLineHeightMultiplier = prompt(
"请输入行间距倍数",
lineHeightMultiplier.toString()
);
if (newLineHeightMultiplier !== null) {
lineHeightMultiplier = parseFloat(newLineHeightMultiplier);
GM_setValue(
storageKey + "_line_height_multiplier",
lineHeightMultiplier
);
enlargeFontSize();
}
});
})();