좆같은유튜브새끼들이상한건왜바꾸고지랄이야

Clicks on Latest sort on YouTube channels

// ==UserScript==
// @name         좆같은유튜브새끼들이상한건왜바꾸고지랄이야
// @namespace    https://개좆같은유튜브놈들.com
// @version      0.3
// @description  Clicks on Latest sort on YouTube channels
// @author       taulover
// @match        https://www.youtube.com
// @match        https://www.youtube.com/*
// @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="최신순"]').then((elm) => {
        console.log('Element is ready');
        console.log(elm.textContent);
        elm.click();
    });
});