Compare commits

..

No commits in common. "38eee1eb4459b5b4ec2397e888f17a970f22e31f" and "71751283e1a4d380b72b1d3f425da7892bec1319" have entirely different histories.

View File

@ -1,9 +1,15 @@
// 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;
switch (document.domain) {
case "forum.effectivealtruism.org":
/*
.class
#id
*/
if (document.domain == "forum.effectivealtruism.org") {
styles = `
/*
.Layout-main {
@ -22,15 +28,17 @@ switch (document.domain) {
}
*/
`;
break;
case "nationstates.net":
}
if (document.domain == "nationstates.net") {
styles = `
.adidentifier {
display: none;
}
`;
break;
case "mail.proton.me":
}
if (document.domain == "mail.proton.me") {
styles = `
/*
.item-container-row.read, .item-container.read {
@ -45,48 +53,26 @@ switch (document.domain) {
zoom: 0.625 !important;
*/
`;
break;
case "forum.nunosempere.com":
}
if (document.domain == "forum.nunosempere.com") {
styles = `
body {
zoom: 0.625 !important;
}
`;
break;
case "search.nunosempere.com":
styles = `
/*
body {
zoom: 1.8;
}
*/
if (document.domain == "search.nunosempere.com") {
styles = `
body {
/* zoom: 1.8; */
}
footer {
display: none;
}
`;
break;
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":
if (document.domain == "twitter.com") {
styles = `
/* hide promoted tweets */
:has(meta[property="og:site_name"][content="Twitter"])
@ -169,10 +155,62 @@ switch (document.domain) {
[aria-live^="polite"]{
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) {
@ -182,7 +220,7 @@ if (styles != null) {
console.log("Style changed");
}
// Extra: Replace default alert with new function
// Replace default alert with new function
// whose style can be changed!
window.alert = (message) => {
let alertDiv = document.getElementById("customAlert");
@ -241,46 +279,7 @@ window.alert = (message) => {
document.getElementById("alertMessage").textContent = message;
alertDiv.classList.add("visible");
};
// 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.
// ^ 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";