Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Twitter - CSS Class for Night Mode
- // @namespace http://xt-8147.blogspot.com/
- // @version 1.0
- // @description Detects if you're using Night Mode on Twitter and sticks a CSS class on the body tag.
- // @author XT-8147
- // @include https://twitter.com/*
- // @grant none
- // @run-at document-start
- // ==/UserScript==
- /* Version History
- * Version Notes
- * 0.1 * Original version.
- * 0.2 * Properly adds and removes the CSS class as necessary after page load, since the user is free to toggle it at will after page load.
- * 0.3 * The head actually mutates twice every time Night Mode is toggled, the toggle doesn't complete until the second mutation. Now detecting this.
- * 1.0 * Code declared release-worthy.
- */
- function maintainCSSClass() {
- var isNightMode = ( document.querySelector( 'link[rel="stylesheet"][href*="nightmode"]' ) !== null );
- var pushingState = document.body.classList.contains( 'pushing-state' );
- if( !pushingState ) {
- if( isNightMode ) {
- document.body.classList.add( 'night-mode' );
- }
- else {
- document.body.classList.remove( 'night-mode' );
- }
- }
- }
- var o = new MutationObserver( maintainCSSClass );
- o.observe( document.head, { characterData: false, attributes: false, childList: true, subtree: false } );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement