-
Notifications
You must be signed in to change notification settings - Fork 3
/
smaller-text.user.js
39 lines (37 loc) · 1.33 KB
/
smaller-text.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// ==UserScript==
// @name Smashing smaller text.
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Smashing Magazine text size is ENORMOUS, so I try to make it more reasonable.
// @author Josh Parker
// @match https://www.smashingmagazine.com/*
// @icon https://www.google.com/s2/favicons?domain=smashingmagazine.com
// @grant none
// ==/UserScript==
(function smashingSmallerText() {
// delete rules is meant to be reusable across many userscripts
const deleteRules = (selector, ruleName) => {
const styleSheets = [...document.styleSheets];
styleSheets.forEach((styleSheet, ssi) => {
const cssRules = [...styleSheet.cssRules];
cssRules.forEach((cssRule, cri) => {
const { cssText } = cssRule;
const selectorRE = new RegExp(`${selector}.*\\{`, 'i');
if (cssText.match(selectorRE)) {
const rulesRE = /\{(.*)\}/;
const rulesText = cssText.match(rulesRE)[1].trim();
const ruleRE = /[^;]*;/g;
const rules = rulesText.match(ruleRE);
rules.forEach((rule) => {
const ruleNameRE = new RegExp(`^${ruleName}:`, 'i');
if (rule.match(ruleNameRE)) {
document.styleSheets[ssi].deleteRule(cri);
}
});
}
});
});
};
deleteRules('body', 'font-size');
document.styleSheets[0].insertRule('body { font-size: 15px; }');
}());