Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Reddit Green Beta Theme Remover
- // @namespace http://tampermonkey.net/
- // @version 2024-12-11
- // @description Removes Reddit's latest UI disaster
- // @author ez
- // @match https://www.reddit.com/*
- // @match https://reddit.com/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=reddit.com
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Function to remove a specific class from an element, if it exists
- function removeClassFromElement(element, className) {
- if (element.classList && element.classList.contains(className)) {
- element.classList.remove(className);
- }
- }
- // Function to replace a specific class in the element's class list
- function replaceClassInElement(element, oldClass, newClass) {
- if (element.classList && element.classList.contains(oldClass)) {
- element.classList.replace(oldClass, newClass);
- }
- }
- // Function to replace color in inline styles
- function replaceColorInStyles(element) {
- if (element.style.cssText) {
- element.style.cssText = element.style.cssText.replace(/#0e1113/g, '#121213');
- }
- }
- // Function to replace color '#0e1113' with '#121213' in styles
- function replaceColorInPage() {
- const allElements = document.querySelectorAll('*');
- allElements.forEach(element => {
- replaceColorInStyles(element);
- });
- }
- // Function to modify the classes for the page (removing or replacing specific classes)
- function modifyClassesOnPage() {
- const allElements = document.querySelectorAll('*');
- allElements.forEach(element => {
- // For all elements, remove 'theme-beta' and 'bg-neutral-background'
- if (element.classList) {
- removeClassFromElement(element, 'theme-beta');
- removeClassFromElement(element, 'bg-neutral-background');
- }
- });
- }
- // Function to update all CSS variables starting with '--color-neutral-background'
- function changeCssVariablesWithWildcard() {
- const root = document.documentElement;
- // Update all CSS variables that start with --color-neutral-background
- const styles = window.getComputedStyle(root);
- for (let i = 0; i < styles.length; i++) {
- const property = styles[i];
- if (property.startsWith('--color-neutral-background')) {
- root.style.setProperty(property, '#121213');
- }
- }
- }
- // Debounced function to apply changes
- let scrollTimeout;
- function applyChangesOnScroll() {
- clearTimeout(scrollTimeout);
- scrollTimeout = setTimeout(() => {
- modifyClassesOnPage(); // Modify classes
- replaceColorInPage(); // Replace color
- changeCssVariablesWithWildcard(); // Update CSS variables
- }, 200); // Adjust debounce delay as needed (200ms in this case)
- }
- // Scroll event listener to apply changes as you scroll
- window.addEventListener('scroll', applyChangesOnScroll);
- // Initial call to apply changes when the page loads
- window.addEventListener('load', function() {
- modifyClassesOnPage(); // Modify classes
- replaceColorInPage(); // Replace color
- changeCssVariablesWithWildcard(); // Update CSS variables
- });
- // Use MutationObserver to detect dynamically added elements and update them
- const observer = new MutationObserver(() => {
- modifyClassesOnPage(); // Modify classes
- });
- // Observe changes to the entire document, particularly for added nodes (including dynamically added <div>s)
- observer.observe(document.body, { childList: true, subtree: true });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement