This plugin press "Show more" button when display it on your browser by scroll.
当前为
// ==UserScript==
// @name Auto show more for YouTube
// @name:ja YouTubeの「もっと見る」ボタンを自動で押す
// @description This plugin press "Show more" button when display it on your browser by scroll.
// @description:ja YouTube.comの「もっと見る」ボタンが、スクロールによって画面に表示された瞬間、自動で押されます。
// @namespace https://twitter.com/sititou70
// @include /https*:\/\/www\.youtube\.com\/.*/
// @version 2.0.0
// @grant none
// ==/UserScript==
const user_agent = window.navigator.userAgent.toLowerCase();
const adjust_scroll_px = 0;
let clicked_buttons = [];
const fireClickEvent = (elem) => {
if( user_agent.match(/(msie|MSIE)/) || user_agent.match(/(T|t)rident/) ) {
elem.fireEvent("onclick");
} else {
const event = document.createEvent("MouseEvents");
event.initEvent("click", true, true);
elem.dispatchEvent(event);
}
};
document.addEventListener("scroll", function(){
buttons.forEach(function(obj){
document.querySelectorAll(obj.selector).forEach((elem) => {
if(clicked_buttons.includes(elem))return;
if(elem.getBoundingClientRect().y - window.innerHeight + adjust_scroll_px < 0){
clicked_buttons.push(elem);
fireClickEvent(elem);
}
});
});
});
document.addEventListener("click", function(e){
let target = e.target;
while(target !== document.body){
if(target.tagName == "A"){
clicked_buttons = [];
return;
}
target = target.parentElement;
}
});
const buttons = [
{
name: "Comment show more button",
selector: ".more-button > paper-button.ytd-comment-replies-renderer",
},
{
name: "Watch more related button",
selector: "paper-button.yt-next-continuation",
},
{
name: "Video info show more button",
selector: "paper-button.ytd-expander",
}
];