Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name TY Dark Mode
- // @namespace http://tampermonkey.net/
- // @version 0.09
- // @description Force dark mode enable and stop autoplay
- // @author pqwoerituytrueiwoq
- // @match https://www.youtube.com/*
- // @exclude https://www.youtube.com/embed/*
- // @grant none
- // ==/UserScript==
- (function() {
- var ran=false,log=console.log;
- log=function(){return;}// disable debug messages
- log('yt dark mode script running',document.location.href);
- function initilizeScript(){
- if(!ran){
- log('page load complete');
- }
- function STFUautoplay(){
- log('make autoplay fuck off');
- var ap=document.evaluate("//div[@id='autoplay']/../paper-toggle-button", document, null, 9, null).singleNodeValue;// find autoplay button
- if(ap){
- log('autoplay toggle found');
- if(ap.getAttribute('checked')===null){
- log('autoplay is off');
- }
- else{
- log('autoplay was on');
- ap.click();// toggle autoplay
- }
- }
- else{
- log('no autoplay toggle on page');
- }
- setTimeout(STFUautoplay,5000);// do it again
- }
- if(document.body.parentNode.getAttribute('dark')===null){
- function findMenuEntry(n=0){
- var m=document.evaluate("//ytd-toggle-theme-compact-link-renderer/div[@id='label']", document, null, 9, null).singleNodeValue;
- if(!m){
- log('waiting on menu');
- return setTimeout(function(){
- n++;
- if(n/20==parseInt(n)){
- b.click();// click open menu again
- }
- findMenuEntry(n);
- },50);// not found, try again later
- }
- log('clicking menu entry');
- m.click();// click menu entry
- log('click switch');
- document.evaluate("//ytd-multi-page-menu-renderer//div[@id='toggleButton']", document, null, 9, null).singleNodeValue.click();// click toggle option
- log('set color');
- document.body.parentNode.setAttribute('dark',true);// turn it back to dark
- log('close menu');
- document.getElementById('button').click();//close menu
- log('dark mode fully enabled');
- }
- log('set color');
- document.body.parentNode.setAttribute('dark',true);// turn it dark
- log('open menu');
- var b=document.evaluate("//ytd-topbar-menu-button-renderer/div[@id='button']/a/yt-icon-button[@id='button']/button[@aria-label='Settings']", document, null, 9, null).singleNodeValue||document.getElementById('img');// find menu button
- b.click();// open menu
- findMenuEntry();// do stuff in menu
- }
- else{
- log('dark mode in use, no action needed');
- }
- STFUautoplay();
- ran=true;
- }
- window.addEventListener('load',initilizeScript,false);
- setTimeout(function(){
- if(!ran){
- log('page never loaded, lets try to run');
- try{
- ran=true;
- initilizeScript();
- }
- catch(e){
- log('Error:',e);
- }
- }
- },5000);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement