在油猴里粘贴下面的代码即可实现字体放大,最后的数字可以改成你需要在原来基础上加多少
// ==UserScript==
// @name 字体放大
// @version 0.1
// @description try to take over the world!
// @author You
// @match *://dalao.net/*
// @match *://www.dalao.net/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=dalao.net
// @grant none
// ==/UserScript==
(function() {// 获取所有文本节点
const textNodes = [];
function getTextNodes(node) {
if (node.nodeType === Node.TEXT_NODE) {
textNodes.push(node);
} else {
const children = node.childNodes;
for (let i = 0; i < children.length; i++) {
getTextNodes(children[i]);
}
}
}
console.log(textNodes)
// 修改文字大小
function changeTextSize(size) {
for (let i = 0; i < textNodes.length; i++) {
const parentElement = textNodes[i].parentNode;
const computedStyle = window.getComputedStyle(parentElement);
const currentSize = computedStyle.getPropertyValue('font-size');
const currentValue = parseFloat(currentSize);
const unit = currentSize.replace(currentValue, '');
console.log(unit)
parentElement.style.fontSize = (currentValue + size) + unit;
}
}
getTextNodes(document.body);
// 调用 changeTextSize 函数来增大文字大小(例如,增加 2 像素)
changeTextSize(2);
})();