youtube channel video fliter/search demo

Simpler to find songs and singing videos in the vtuber streaming channel.

2022-10-31 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

// ==UserScript==
// @name         youtube channel video fliter/search demo
// @description  Simpler to find songs and singing videos in the vtuber streaming channel.
// @namespace    ytb_channel_video_fliter
// @author       Covenant
// @version      1.0.3
// @license      MIT
// @homepage
// @match        https://www.youtube.com/channel/*/videos*
// @match        https://www.youtube.com/channel/*/streams*
// @match        https://www.youtube.com/c/*/videos*
// @match        https://www.youtube.com/c/*/streams*
// @match        https://www.youtube.com/user/*/videos*
// @match        https://www.youtube.com/feed/subscriptions*
// @icon         data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAD///8AEiP//xIj//8SI///EyP//xIj//8SI///EiP//xIj//8SI///EyP//xIj//8SI///EiP//xIj//////8AEiP//wAc7v8AHO7/AB3v/wAc7v8AHO7/ABzu/wAc7v8AHO7/ABzu/wAd7/8AHe//ABzu/wAc7/8AHe//EiP//xIj//8SI////////09V//+6uv////////////9PVf//z87///////+ysv//EiP//5ub////////0tH//xIj//8SI///EiP///////9PVf///////xIj////////T1X///////8SI////////5qZ////////EiP//xIj//8TI///EiP//xIj////////T1X///////8TI////////09V////////EiP///////+amf/////////////S0f//EiP//xIj//8SI////////09V////////EiL///////9PVf////////////+6uv//EiP//7q6///v8P//0tH//xIj//8SI///EyP///////8SI///EiP//xIj//8SI///EiP///////8SI///EiP//xIj//8SI///EiP//xIj//8SI///EiP//////////////////xIj//8SI///EiP//xMj////////EiP//xIj//8SI///EiP//xIj//8SI///EiP//9nZ//8SI///EiP//xMj//8SI///EiP//xIj//8SI///EiP//xIj//8SI///EiP//xIj//8SI///EiL//9na//////////////////////////////////////////////////////////////////////////////////////////////////+r5/b/AAAA//372P//////R5K5/wAAAP/IiWb//////26v1f8AAAD/rGZE////////////////////////////qub1/wAAAP/+/Nj/qub2/wAAAP//////AAAA//782P8TcJ3//vzY/wAAAP///////////////////////////6rm9f8AAAD//vzY/6rm9v8AAAD//////wAAAP/+/Nj/AAAA//////8AAAD///////////////////////////9ur9b/AAAA/+PFov//////R5K6/wAAAP/JiWb//////wAAAP//////AAAA////////////////////////////AAAA//+p7/8AAAD/////////////////////////////////////////////////////////////////bq7V/wxKf///////rGZE/+PFov//////////////////////////////////////////////////////gAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==
// @connect
// @run-at       document-end
// @noframes
// ==/UserScript==
var btn_print;
var input_sec;
var input_word;
var btn_exception;
function create_btn(new_name,top,right,class_name){
    if(top==undefined){top=0;}
    if(typeof right=="undefined"){right=0;}
    var btn = document.createElement("Button");
    btn.innerText = new_name;
    btn.style = "top:"+top+"px;right:"+right+"px;position:fixed;"
    btn.className=class_name;
    //btn.type="submit";
    if(true)document.body.appendChild(btn);
    return btn;
}
function create_input(new_name,top,right,is_num,class_name){
    if(top==undefined){top=0;}
    if(typeof right=="undefined"){right=0;}
    var input = document.createElement("Input");
    input.placeholder=new_name;
    input.style="top:"+top+"px;right:"+right+"px;position:fixed;";
    input.type="text";
    input.className=class_name;
    if(is_num)input.size="15";
    if(is_num)input.setAttribute("maxlength", "5");
    if(is_num)input.setAttribute("oninput","this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\\..*?)\\..*/g, '$1');");
    if(true)document.body.appendChild(input);
    return input;
}
function fn_btn_print(){//press button
    var video=document.querySelectorAll('#items>ytd-grid-video-renderer');
    var results=0;
    for(let i = 0; i < video.length; i++){
        if(video[i].querySelectorAll('div.badge-style-type-live-now-alternate')[0]!=undefined){
            //video[i].style.display="none";
            continue;//配信中(feed/subscriptions)
        }
        var ary_time=video[i].querySelectorAll('span#text')[0].innerText.split(':');
        var video_name=video[i].querySelectorAll('a#video-title')[0].innerText;
        var time=0;
        var max_len;
        if(ary_time.length==1){//NaN
            video[i].style.display="";//配信予定, ytb_shorts
        }
        else if(ary_time.length==3){//hour
            time=time+parseInt(ary_time[0])*3600+parseInt(ary_time[1])*60+parseInt(ary_time[2]);
        }
        else{
            time=time+parseInt(ary_time[0])*60+parseInt(ary_time[1]);
        }
        //btn_print.innerHTML=btn_print.innerHTML+time+" "
        if(input_sec.value==''){max_len=86400;}else{max_len=parseInt(input_sec.value)*60;}
        if(time<max_len&&video_name.search(new RegExp(input_word.value, "i"))!=-1){
            video[i].style.display="";
            results++;
        }
        else{
            video[i].style.display="none";
        }
    }
    btn_print.innerText="検索("+results+"本の動画)";
}
function fn_check_ui(){
    if(document.querySelectorAll('#items>ytd-grid-video-renderer').length==0){//UI check
        btn_exception=create_btn("exception",800,0,'exception');
        var user_tool=document.querySelectorAll('.user_tool');
        for(let i = 0; i < user_tool.length; i++){
            user_tool[i].style.display="none";
        }
    }
}

(function() {
    'use strict';
    btn_print=create_btn("検索",500,0,'user_tool')
    btn_print.addEventListener('click',() => {
        fn_btn_print();
    });
    input_sec=create_input("最大映像時間(分)/Maximum video time (minutes)",525,0,true,'user_tool')
    input_word=create_input("抽出条件の指定",550,0,false,'user_tool')
    window.setTimeout(( () => fn_check_ui() ), 1000);////UI check need delay
})();