-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfix-selection-color.user.js
41 lines (38 loc) · 1.33 KB
/
fix-selection-color.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
40
41
// ==UserScript==
// @name fix selection color
// @namespace http://tampermonkey.net/
// @version 0.1
// @description The selection color is whiteish and I thought it wasn't selecting at all. Oops.
// @author Josh Parker
// @match https://www.blunt-therapy.com/*
// @icon https://www.google.com/s2/favicons?domain=blunt-therapy.com
// @grant none
// ==/UserScript==
(function fixSelectionColor() {
const editRules = function editRules(searchTerm, replaceTerm) {
if (searchTerm.constructor.name !== 'String' || replaceTerm.constructor.name !== 'String') {
throw new Error('string terms only');
}
const styleSheets = [...document.styleSheets];
styleSheets.forEach((styleSheet, ssi) => {
try {
const cssRules = [...styleSheet.cssRules];
cssRules.forEach((cssRule, cri) => {
const { cssText } = cssRule;
if (cssText.includes(searchTerm)) {
const editedText = cssText.replace(searchTerm, replaceTerm);
document.styleSheets[ssi].deleteRule(cri);
document.styleSheets[ssi].insertRule(editedText);
}
});
} catch (e) {
console.error(e);
console.log('could not access css rules on styleSheet, ', styleSheet);
}
});
};
editRules(
'::selection { background: rgb(251, 251, 255); }',
'::selection { background: blue; color: white; }',
);
}());