reorg custom style code again

This commit is contained in:
NunoSempere 2024-03-21 08:40:09 -03:00
parent 71751283e1
commit 8829166139

View File

@ -63,15 +63,45 @@ if (document.domain == "forum.nunosempere.com") {
}
if (document.domain == "search.nunosempere.com") {
styles = `
/*
body {
/* zoom: 1.8; */
zoom: 1.8;
}
*/
footer {
display: none;
}
`;
}
if (document.domain == "reddit.com" || document.domain == "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;
}
`;
}
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 = `
/* hide promoted tweets */
@ -155,69 +185,8 @@ if (document.domain == "twitter.com") {
[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;
}
`;
}
if (styles != null) {
var styleSheet = document.createElement("style");
styleSheet.innerText = styles;
document.head.appendChild(styleSheet);
console.log("Style changed");
}
// Replace default alert with new function
@ -279,7 +248,45 @@ window.alert = (message) => {
document.getElementById("alertMessage").textContent = message;
alertDiv.classList.add("visible");
};
// ^ takes 0.014ms to run, so performance is not the concern here.
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";