bidaum

YouTube-Default-Channel-Sort-Latest

May 20th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. // ==UserScript==
  2. // @name YouTube-Default-Channel-Sort-Latest
  3. // @namespace https://github.com/bidaumm/
  4. // @version 0.2
  5. // @description YouTube-Default-Channel-Sort-Latest
  6. // @author bidaumm
  7. // @match https://www.youtube.com/*videos
  8. // @match https://www.youtube.com/*streams
  9. // @match https://www.youtube.com/*shorts
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. function waitForElm(selector) {
  14. return new Promise(resolve => {
  15. if (document.querySelector(selector)) {
  16. return resolve(document.querySelector(selector));
  17. }
  18.  
  19. const observer = new MutationObserver(mutations => {
  20. if (document.querySelector(selector)) {
  21. resolve(document.querySelector(selector));
  22. observer.disconnect();
  23. }
  24. });
  25.  
  26. observer.observe(document.body, {
  27. childList: true,
  28. subtree: true
  29. });
  30. });
  31. }
  32.  
  33. document.body.addEventListener('yt-navigate-finish', () => {
  34. waitForElm('yt-formatted-string[title="Latest"]').then((elm) => {
  35. console.log('Element is ready');
  36. console.log(elm.textContent);
  37. elm.click();
  38. });
  39. });
Advertisement
Add Comment
Please, Sign In to add comment