YouTube MostPopular/Newest Videos of Channel

Popular And Newest Videos shortcut (Adds after Show More button)

// ==UserScript==
// @name               YouTube MostPopular/Newest Videos of Channel
// @namespace          https://greasyfork.org/en/users/664455-ali-tale
// @version            1.6
// @description        Popular And Newest Videos shortcut (Adds after Show More button)
// @run-at             document-start
// @include            https://www.youtube.com/*
// @require            http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @author             AliTale
// ==/UserScript==

function PopularButt() {
    var channel = $('#channel-info a').attr('href');
    window.open( 'https://www.youtube.com' + channel + '/videos?SRT=P','_blank');
};

function NewestButt() {
    var channel = $('#channel-info a').attr('href');
    window.open( 'https://www.youtube.com' + channel + '/videos?SRT=R','_blank');
};

$(document).ready(function() {


    if (window.location.href.indexOf("SRT=P") > -1) {
      var checkExist2 = setInterval(function() {
              if ($('yt-formatted-string[title=Popular]').length) {
                  clearInterval(checkExist2);
                  $('yt-formatted-string[title=Popular]').click();
              }
          }, 100);
    }

    if (window.location.href.indexOf("SRT=R") > -1) {}

    var checkExist = setInterval(function() {
        if ($('tp-yt-paper-button#expand.button.style-scope.ytd-text-inline-expander').length) {
            clearInterval(checkExist);
            var location= $('tp-yt-paper-button#expand.button.style-scope.ytd-text-inline-expander').parent()
            $('<div  style="text-decoration: none;margin-left:10px;cursor:pointer" id="PopularButt" class="more-button style-scope ytd-video-secondary-info-renderer"> Popular </div>').insertAfter(location);
            document.getElementById ("PopularButt").addEventListener ("click", PopularButt, false);
            $('<a style="text-decoration: none;margin-left:10px;cursor:pointer" id="NewestButt" class="more-button style-scope ytd-video-secondary-info-renderer" href="javascript:void(0);" > Newest </a>').insertAfter(location);
            document.getElementById ("NewestButt").addEventListener ("click", NewestButt, false);
        }
    }, 500);


});