Advertisement
Guest User

Untitled

a guest
Sep 13th, 2020
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         TY Dark Mode
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.09
  5. // @description  Force dark mode enable and stop autoplay
  6. // @author       pqwoerituytrueiwoq
  7. // @match        https://www.youtube.com/*
  8. // @exclude      https://www.youtube.com/embed/*
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     var ran=false,log=console.log;
  14.     log=function(){return;}// disable debug messages
  15.     log('yt dark mode script running',document.location.href);
  16.     function initilizeScript(){
  17.         if(!ran){
  18.             log('page load complete');
  19.         }
  20.         function STFUautoplay(){
  21.             log('make autoplay fuck off');
  22.             var ap=document.evaluate("//div[@id='autoplay']/../paper-toggle-button", document, null, 9, null).singleNodeValue;// find autoplay button
  23.             if(ap){
  24.                 log('autoplay toggle found');
  25.                 if(ap.getAttribute('checked')===null){
  26.                     log('autoplay is off');
  27.                 }
  28.                 else{
  29.                     log('autoplay was on');
  30.                     ap.click();// toggle autoplay
  31.                 }
  32.             }
  33.             else{
  34.                 log('no autoplay toggle on page');
  35.             }
  36.             setTimeout(STFUautoplay,5000);// do it again
  37.         }
  38.         if(document.body.parentNode.getAttribute('dark')===null){
  39.             function findMenuEntry(n=0){
  40.                 var m=document.evaluate("//ytd-toggle-theme-compact-link-renderer/div[@id='label']", document, null, 9, null).singleNodeValue;
  41.                 if(!m){
  42.                     log('waiting on menu');
  43.                     return setTimeout(function(){
  44.                         n++;
  45.                         if(n/20==parseInt(n)){
  46.                             b.click();// click open menu again
  47.                         }
  48.                         findMenuEntry(n);
  49.                     },50);// not found, try again later
  50.                 }
  51.                 log('clicking menu entry');
  52.                 m.click();// click menu entry
  53.                 log('click switch');
  54.                 document.evaluate("//ytd-multi-page-menu-renderer//div[@id='toggleButton']", document, null, 9, null).singleNodeValue.click();// click toggle option
  55.                 log('set color');
  56.                 document.body.parentNode.setAttribute('dark',true);// turn it back to dark
  57.                 log('close menu');
  58.                 document.getElementById('button').click();//close menu
  59.                 log('dark mode fully enabled');
  60.             }
  61.             log('set color');
  62.             document.body.parentNode.setAttribute('dark',true);// turn it dark
  63.             log('open menu');
  64.             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
  65.             b.click();// open menu
  66.             findMenuEntry();// do stuff in menu
  67.         }
  68.         else{
  69.             log('dark mode in use, no action needed');
  70.         }
  71.         STFUautoplay();
  72.         ran=true;
  73.     }
  74.     window.addEventListener('load',initilizeScript,false);
  75.     setTimeout(function(){
  76.         if(!ran){
  77.             log('page never loaded, lets try to run');
  78.             try{
  79.                 ran=true;
  80.                 initilizeScript();
  81.             }
  82.             catch(e){
  83.                 log('Error:',e);
  84.             }
  85.         }
  86.     },5000);
  87. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement