Hide videos that are in playlist

button on the left side to Hide videos that are in a playlist established by the user.

当前为 2023-09-06 提交的版本,查看 最新版本

// ==UserScript==
// @name            Hide videos that are in playlist
// @namespace   https://greasyfork.org/es/users/758165-AlÉxito
// @match           https://www.youtube.com/*
// @version         1.1
// @author           AlExito
// @description    button on the left side to Hide videos that are in a playlist established by the user.
// @grant             GM_xmlhttpRequest
// @license          MIT   feel free to modify improve and share
// @noframes
// ==/UserScript==

(function () {

  function action1() {
      var idplist = "insert here the ID of your playlist";
      var api = "insert here your APIKEY";
      var url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&contentDetails&maxResults=100&playlistId=" + idplist + "&key=" + api + "&fields=items(snippet(resourceId(videoId)))&part=snippet";
GM_xmlhttpRequest({
  method: "GET",
  url: url,
  headers: {
    "Content-Type": "application/json"
  },
  onload: function(response) {
    const playlistvid = response.responseText.replace(/{/g, "").replace(/}/g, "").replace(/"items":/g, "").replace(/"snippet":/g, "").replace(/"resourceId":/g, "").replace(/"videoId":/g, "").replace(/\s/g, "")
    var elementos = document.querySelectorAll(["ytd-grid-video-renderer", "ytd-rich-item-renderer", "ytd-compact-video-renderer", "ytd-video-renderer"])
            for (let i = elementos.length-1; 0 <= i ; i--){
            let video=elementos[i];
               let video_url = video.querySelector("a").href.replace("https://www.youtube.com/watch?v=", "").replace(/&.+/g, "")
     if(playlistvid.includes(video_url)){
       video.setAttribute("style", "display: none !important;");
     }
    }
  }
});
}

    function Boton02() {
        var aBoton02 = document.createElement("div");
        var aEtiqueta = document.createElement("p");
        aBoton02.style.position = "fixed";
        aBoton02.style.zIndex = "10000";
        aBoton02.style.padding = "1px 5px 1px 5px";
        aBoton02.style.backgroundColor = "#35374a";
        aBoton02.style.width = "auto";
        aBoton02.style.cursor = "pointer";
        aBoton02.style.top = "55vh";
        aBoton02.style.left = "-3px";
        aEtiqueta.textContent = "H";
        aEtiqueta.style.color = "#999";
        aBoton02.onmouseover = function () {
            aEtiqueta.textContent = "Hide Videos in to playlist";
        };
        aBoton02.onmouseleave = function () {
            aEtiqueta.textContent = "H";
        };
        document.body.appendChild(aBoton02);
        aBoton02.appendChild(aEtiqueta);

        aBoton02.onclick = function () {
action1()
        };
    }
    Boton02();
})();