rework style code to use a switch statement

This commit is contained in:
NunoSempere 2024-03-21 08:47:57 -03:00
parent 8829166139
commit 38eee1eb44

View File

@ -1,15 +1,9 @@
// Inspired by the Stylus app: <https://addons.mozilla.org/en-GB/firefox/addon/styl-us/> // Inspired by the Stylus app: <https://addons.mozilla.org/en-GB/firefox/addon/styl-us/>
// Main part of the code: switch on the domain and select the corresponding style
var styles = null; var styles = null;
switch (document.domain) {
/* case "forum.effectivealtruism.org":
.class
#id
*/
if (document.domain == "forum.effectivealtruism.org") {
styles = ` styles = `
/* /*
.Layout-main { .Layout-main {
@ -28,17 +22,15 @@ if (document.domain == "forum.effectivealtruism.org") {
} }
*/ */
`; `;
} break;
case "nationstates.net":
if (document.domain == "nationstates.net") {
styles = ` styles = `
.adidentifier { .adidentifier {
display: none; display: none;
} }
`; `;
} break;
case "mail.proton.me":
if (document.domain == "mail.proton.me") {
styles = ` styles = `
/* /*
.item-container-row.read, .item-container.read { .item-container-row.read, .item-container.read {
@ -53,15 +45,15 @@ if (document.domain == "mail.proton.me") {
zoom: 0.625 !important; zoom: 0.625 !important;
*/ */
`; `;
} break;
if (document.domain == "forum.nunosempere.com") { case "forum.nunosempere.com":
styles = ` styles = `
body { body {
zoom: 0.625 !important; zoom: 0.625 !important;
} }
`; `;
} break;
if (document.domain == "search.nunosempere.com") { case "search.nunosempere.com":
styles = ` styles = `
/* /*
body { body {
@ -73,9 +65,10 @@ if (document.domain == "search.nunosempere.com") {
display: none; display: none;
} }
`; `;
} break;
case "reddit.com":
if (document.domain == "reddit.com" || document.domain == "old.reddit.com") { // fallthrough
case "old.reddit.com":
styles = ` styles = `
/* kill sidebar ads */ /* kill sidebar ads */
.ad-container, .ad-container,
@ -92,17 +85,8 @@ if (document.domain == "reddit.com" || document.domain == "old.reddit.com") {
display: none !important; display: none !important;
} }
`; `;
} break;
case "twitter.com":
if (styles != null) {
var styleSheet = document.createElement("style");
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
console.log("Style changed");
}
if (document.domain == "twitter.com") {
styles = ` styles = `
/* hide promoted tweets */ /* hide promoted tweets */
:has(meta[property="og:site_name"][content="Twitter"]) :has(meta[property="og:site_name"][content="Twitter"])
@ -186,10 +170,19 @@ if (document.domain == "twitter.com") {
background: white !important; background: white !important;
} }
`; `;
break;
default:
console.log("No custom style");
} }
// Replace default alert with new function if (styles != null) {
var styleSheet = document.createElement("style");
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
console.log("Style changed");
}
// Extra: Replace default alert with new function
// whose style can be changed! // whose style can be changed!
window.alert = (message) => { window.alert = (message) => {
let alertDiv = document.getElementById("customAlert"); let alertDiv = document.getElementById("customAlert");
@ -249,6 +242,7 @@ window.alert = (message) => {
alertDiv.classList.add("visible"); alertDiv.classList.add("visible");
}; };
// Extra: hide video players on twitter
if (document.domain == "twitter.com") { if (document.domain == "twitter.com") {
// Function to hide the grandparent of video players // Function to hide the grandparent of video players
// takes 0.014ms to run, so performance is not the concern here. // takes 0.014ms to run, so performance is not the concern here.