ballerburg9005 / Youtube SHOW MORE & NEWEST FIRST

// ==UserScript==
// @name        Youtube SHOW MORE & NEWEST FIRST
// @description Auto-expand description box on Youtube and auto-switch to "Newest First" sorting
// @include       http*://*youtube.*/*
// @run-at      document-start
// @license MIT
// @author Ballerburg9005
// ==/UserScript==

new MutationObserver(function(_,self) {
    // Newest first
    for(let el of document.querySelectorAll('*[id="menu"] a.yt-dropdown-menu:not(.iron-selected)'))
    {
        if(el.innerHTML.match(new RegExp(".*Newest first.*")) !== null)
        {
			el.click();
          	break;
        }
    }
    
    // Show more
  	const d = {"more": "(Read |Show |...)more", "expand": "(Show |...)more"}; // , "more-replies": "REPLIES", "button": "Show more replies"};
  	for(const key in d)
    {
	    for(let el of document.querySelectorAll('*[id="'+key+'"]:not([hidden=""])'))
		{
           	if(el.innerHTML.match(new RegExp(".*"+d[key]+".*")) !== null)
           	{
                el.click();
                for(let ele of el.querySelectorAll('button')) { ele.click(); }
        	}
      	}
    }
}).observe(document, {childList:true, subtree:true});