Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name YouTube-Default-Channel-Sort-Latest
- // @namespace https://github.com/bidaumm/
- // @version 0.2
- // @description YouTube-Default-Channel-Sort-Latest
- // @author bidaumm
- // @match https://www.youtube.com/*videos
- // @match https://www.youtube.com/*streams
- // @match https://www.youtube.com/*shorts
- // @grant none
- // ==/UserScript==
- function waitForElm(selector) {
- return new Promise(resolve => {
- if (document.querySelector(selector)) {
- return resolve(document.querySelector(selector));
- }
- const observer = new MutationObserver(mutations => {
- if (document.querySelector(selector)) {
- resolve(document.querySelector(selector));
- observer.disconnect();
- }
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- });
- }
- document.body.addEventListener('yt-navigate-finish', () => {
- waitForElm('yt-formatted-string[title="Latest"]').then((elm) => {
- console.log('Element is ready');
- console.log(elm.textContent);
- elm.click();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment