Youtube Save to... playlist incremental search

This script injects a search field into the dialog where user can save a video to a playlist. When the user starts to type an incremental search is implemented and the playlists are filtered out

当前为 2019-11-08 提交的版本,查看 最新版本

// ==UserScript==
// @name         Youtube Save to... playlist incremental search
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  This script injects a search field into the dialog where user can save a video to a playlist. When the user starts to type an incremental search is implemented and the playlists are filtered out
// @author       Jaq Drako
// @match        *://www.youtube.com/*
// @grant        none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// ==/UserScript==

var $ = window.$;
(function() {
    'use strict';

    $(function() {
        var labelExist = setInterval(function() {
            if ($("div#title.ytd-add-to-playlist-renderer").length) {
                clearInterval(labelExist);

                var saveToLabel = $('div#title.ytd-add-to-playlist-renderer');
                saveToLabel.html("<span>Search:&nbsp;&nbsp;&nbsp;</span><input id='lookupSearch' type='search'/>");

                $("input#lookupSearch").on("search", function() {
                    var labels = $("ytd-add-to-playlist-renderer div#playlists div#checkbox-container yt-formatted-string#label");
                    labels.closest('ytd-playlist-add-to-option-renderer').show();
                });

                $("input#lookupSearch").keyup(function( event ) {
                    var sv = $("input#lookupSearch").val().toLowerCase();
                    var labels = $("ytd-add-to-playlist-renderer div#playlists div#checkbox-container yt-formatted-string#label");
                    labels.each(function(data) {
                        var label = $(this);
                        var title = label.attr("title").toLowerCase();
                        if(title.indexOf(sv) > -1) {
                            label.closest('ytd-playlist-add-to-option-renderer').show();
                        } else {
                            label.closest('ytd-playlist-add-to-option-renderer').hide();
                        }
                    });
                });
            }
        }, 100); // check every 100ms
    });
})();