Compare commits

..

2 Commits

Author SHA1 Message Date
38eee1eb44 rework style code to use a switch statement 2024-03-21 08:47:57 -03:00
8829166139 reorg custom style code again 2024-03-21 08:40:09 -03:00

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,26 +45,48 @@ 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 {
/* zoom: 1.8; */ zoom: 1.8;
} }
*/
footer { footer {
display: none; display: none;
} }
`; `;
} break;
if (document.domain == "twitter.com") { case "reddit.com":
// fallthrough
case "old.reddit.com":
styles = `
/* kill sidebar ads */
.ad-container,
a[href^="https://alb.reddit.com"]
a[href="/premium"],
[data-promoted^="true"],
#eu-cookie-policy,
.infobar-toaster-container,
.listingsignupbar,
.native-ad-container,
.native-sidebar-ad,
.premium-banner-outer,
{
display: none !important;
}
`;
break;
case "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"])
@ -155,62 +169,10 @@ if (document.domain == "twitter.com") {
[aria-live^="polite"]{ [aria-live^="polite"]{
background: white !important; background: white !important;
} }
`;
// Function to hide the grandparent of video players
function hideVideoPlayerGrandparent() {
document
.querySelectorAll('[data-testid="videoPlayer"]')
.forEach(function (videoPlayer) {
var grandparentElement =
videoPlayer.parentElement.parentElement.parentElement.parentElement
.parentElement.parentElement;
var newTextElement = document.createElement("div");
newTextElement.textContent = " [ twitter video ] ";
newTextElement.style["margin-top"] = "10px";
newTextElement.style["margin-left"] = "10px";
newTextElement.style["margin-bottom"] = "10px";
grandparentElement.replaceWith(newTextElement);
});
}
// Create a new MutationObserver instance
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length) {
hideVideoPlayerGrandparent(); // Call the function to hide video players
}
});
});
// Options for the observer (which mutations to observe)
var config = { childList: true, subtree: true };
// Start observing the target node for configured mutations
observer.observe(document.body, config);
// Call the function initially to hide any video players on initial load
hideVideoPlayerGrandparent();
}
if (document.domain == "reddit.com" || document.domain == "old.reddit.com") {
styles = `
/* kill sidebar ads */
.native-ad-container,
.premium-banner-outer,
.native-sidebar-ad,
.infobar-toaster-container,
#eu-cookie-policy,
.ad-container,
.listingsignupbar,
a[href="/premium"],
[data-promoted^="true"],
a[href^="https://alb.reddit.com"]
{
display: none !important;
}
`; `;
break;
default:
console.log("No custom style");
} }
if (styles != null) { if (styles != null) {
@ -220,7 +182,7 @@ if (styles != null) {
console.log("Style changed"); console.log("Style changed");
} }
// Replace default alert with new function // 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");
@ -279,7 +241,46 @@ window.alert = (message) => {
document.getElementById("alertMessage").textContent = message; document.getElementById("alertMessage").textContent = message;
alertDiv.classList.add("visible"); alertDiv.classList.add("visible");
}; };
// ^ takes 0.014ms to run, so performance is not the concern here.
// timed with console.time, console.timeEnd // Extra: hide video players on twitter
if (document.domain == "twitter.com") {
// Function to hide the grandparent of video players
// takes 0.014ms to run, so performance is not the concern here.
// timed with console.time, console.timeEnd
function hideVideoPlayerGrandparent() {
document
.querySelectorAll('[data-testid="videoPlayer"]')
.forEach(function (videoPlayer) {
var grandparentElement =
videoPlayer.parentElement.parentElement.parentElement.parentElement
.parentElement.parentElement;
var newTextElement = document.createElement("div");
newTextElement.textContent = " [ twitter video ] ";
newTextElement.style["margin-top"] = "10px";
newTextElement.style["margin-left"] = "10px";
newTextElement.style["margin-bottom"] = "10px";
grandparentElement.replaceWith(newTextElement);
});
}
// Create a new MutationObserver instance
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.addedNodes.length) {
hideVideoPlayerGrandparent(); // Call the function to hide video players
}
});
});
// Options for the observer (which mutations to observe)
var config = { childList: true, subtree: true };
// Start observing the target node for configured mutations
observer.observe(document.body, config);
// Call the function initially to hide any video players on initial load
hideVideoPlayerGrandparent();
}
document.body.style.visibility = "visible"; document.body.style.visibility = "visible";