Greasy Fork

Greasy Fork is available in English.

YouTube Lite (Mó Paz)

Deixa a página inicial do YouTube mais leve, abre o vídeo em uma página livre de anúncios e com apenas o vídeo e um botão para download.

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

// ==UserScript==
// @name         YouTube Lite (Mó Paz)
// @namespace    http://linkme.bio/jhonpergon/?userscript=youtube_lite
// @version      0.1
// @description  Deixa a página inicial do YouTube mais leve, abre o vídeo em uma página livre de anúncios e com apenas o vídeo e um botão para download.
// @author       Jhon Pérgon
// @match        https://www.youtube.com/*
// @match        https://youtu.be/*
// @match        https://m.youtube.com/*
// @icon         https://icons.iconarchive.com/icons/designbolts/cute-social-media/256/Youtube-icon.png
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';


    // Array de palavras-chave que você deseja verificar
  var palavrasChave = ["funk", "MC", "Alok", "Champions", "Certanejo", "Mendonça", "Comédia","American","muambros", "Globinho","Podpah", "Golpista","MrBeast",
                       "Felipe Neto","Pica Pau", "Pica-Pau", "Rir", "Bob Esponja","Funny", "Naruto","Ronaldinho", "Neymar", "Gols", "Esgotinho Clips","Gospel",
                       "Goal","Galaxy","Iphone","TRAILERS", "Trailers", "Shelby", "Comprar", "Vender", "Restored", "Restaurando", "Pago", "Minecraft", "Kpop",
                       "Army","Opala","Ei Nerd","GOKU","Goku", "SAMSUNG","Samsung","Caio Teixeira","DRAGON","Ball","Pobre","Alanzoka","GAMEPLY","alanzoka","60FPS","FPS",
                       "HERÓI","Elite", "Jogos", "RTX","ULTRON","Anime","Cristiano Ronaldo","Life Media","Bonito","Jogar", "Jogo","Dragões","Kombat","KOMBAT",
                       "Kratos", "War", "Rusty","BEN 10", "GTA","Alpha","Redpill","Maquiagem","Gatos","Bolo",
                       "Grupo Menos é Mais", "Você Sabia?", "Futbol", "Placar", "BBB", "Pepsi", "Coca Cola", "Talent","Pipoca","Garage", "Desenho Animado","COD",
                       "Produtos", "Produto", "Food", "Copa", "Faroeste", "Rodada", "Eliminatórias", "Favela", "Poesia Arcústica", "Renato Cariani", "4K"];

  // Função para verificar se uma palavra-chave está presente em um elemento
  function verificaPalavrasChave(elemento) {
    var texto = elemento.textContent.toLowerCase();
    for (var i = 0; i < palavrasChave.length; i++) {
      var palavra = palavrasChave[i].toLowerCase();
      if (texto.includes(palavra)) {
        return true;
      }
    }
    return false;
  }

  // Função para remover tags "ytd-rich-item-renderer" com base nas palavras-chave
  function removeTagsComPalavrasChave() {
    var elementos = document.querySelectorAll("ytd-rich-item-renderer");
    elementos.forEach(function (elemento) {
      if (verificaPalavrasChave(elemento)) {
        //alert("Removeu: "+elemento)
        elemento.remove();
      }
    });
  }

    // Função para remover todas as tags
    function removerTagsScript() {
        document.title = "Youtube (Lite)";
        setTimeout(function(){
          const scripts = document.querySelectorAll('script');
          scripts.forEach(function(script) {
              script.parentNode.removeChild(script);
          });
          const thumbnails = document.querySelectorAll('ytd-playlist-thumbnail');
          thumbnails.forEach(function(thumbnail) {
              thumbnail.parentNode.removeChild(thumbnail);
          });
          const iconsets = document.querySelectorAll('iron-iconset-svg');
          iconsets.forEach(function(iconset) {
              iconset.parentNode.removeChild(iconset);
          });
          const renderers = document.querySelectorAll('ytd-rich-shelf-renderer');
          renderers.forEach(function(renderer) {
              renderer.parentNode.removeChild(renderer);
          });
          let xoverlays = document.querySelector('.ytp-pause-overlay');
          if (xoverlays) {
              xoverlay.remove();
          }

          // Obtém todos os elementos com o ID "video-preview"
          const elementsToRemove = document.querySelectorAll('#video-preview');
          // Itera sobre os elementos e os remove
          for (const element of elementsToRemove) {
              element.remove();
          }

           const links = document.querySelectorAll('a');
            for (const link of links) {
                link.style.border = '1px solid transparent';
                link.addEventListener('mouseover', function() {
                    link.style.border = '1px solid #9ba2ff';
                    link.style.boxShadow = '2px 3px 4px #5c3299';
                });
                link.addEventListener('mouseout', function() {
                    link.style.border = '1px solid transparent';
                    link.style.boxShadow = '';
                });
            }
      }, 500);
    }

    // Função para extrair o ID do vídeo da URL
    function getVideoIdFromUrl() {
        const url = window.location.href;
        const match = url.match(/[?&]v=([^&]+)/);
        if (match && match[1]) {
            return match[1];
        }
        return null;
    }

    // Função para criar o iframe personalizado
    function createCustomIframe(videoId) {

      // Remove todos os estilos existentes na página
      const existingStyles = document.querySelectorAll('style');
      for (const styleElement of existingStyles) {
          styleElement.parentNode.removeChild(styleElement);
      }

      // Remove todo o conteúdo da <body>
      document.body.style.backgroundColor = "#06070b";
      document.body.innerHTML = '';
      document.body.style.backgroundColor = "#06070b";

      setTimeout(function(){
        // Cria o elemento iframe personalizado
        const customIframe = document.createElement('iframe');
        const buttonIframe = document.createElement('p');
        customIframe.id = 'xplayer';
        customIframe.src = `https://www.youtube-nocookie.com/embed/${videoId}?rel=0&controls=2&color=white&iv_load_policy=3&showinfo=0&modestbranding=1&hl=pt-BR`;
        customIframe.allow = 'accelerometer; autoplay; gyroscope; picture-in-picture';
        customIframe.frameBorder = '0';
        customIframe.scrolling = 'no';
        customIframe.sandbox = 'allow-scripts allow-same-origin';
        customIframe.referrerPolicy = 'no-referrer';
        customIframe.allowFullscreen = true;
        customIframe.style.backgroundImage = 'url("")';
        customIframe.style.width = '96%';
        customIframe.style.maxWidth = '720px';
        customIframe.style.height = '85%';
        customIframe.style.maxHeight = '450px';
        customIframe.style.position = 'absolute';
        customIframe.style.border = 'solid 1px #413746';
        customIframe.style.borderRadius = '.6rem';
        customIframe.style.right = '50%';
        customIframe.style.left = '50%';
        customIframe.style.bottom = '0';
        customIframe.style.top = '0';
        customIframe.style.transform = 'translate(-50%, 2%)';
        buttonIframe.id = 'xbplayerxxx';
        buttonIframe.style.width = '97%';
        buttonIframe.style.height = '26px';
        buttonIframe.style.textAlign = 'center';
        buttonIframe.style.fontSize = '17';
        buttonIframe.style.position = 'absolute';
        buttonIframe.style.right = '50%';
        buttonIframe.style.left = '50%';
        buttonIframe.style.bottom = '0';
        buttonIframe.style.margin = '5px';
        buttonIframe.style.transform = 'translate(-50%, 0%)';

        // Adiciona o elemento customIframe à <body>
        document.body.appendChild(customIframe);
        document.body.appendChild(buttonIframe);
        setTimeout(function(){
            let xpxp = document.getElementById('xbplayerxxx');
            xpxp.innerHTML = `
            <a id="xbplayerxxx" style="padding: 4px 10px; color: rgb(155, 162, 255); font-size: 18px margin: 5px; border: 1px solid #afc2ff;" href="https://www.youtube.com/">← Voltar ao Youtube</a><a id="xbplayerxxx" style="padding: 4px 10px; color: rgb(155, 162, 255); font-size: 18px margin: 5px; border: 1px solid #afc2ff;" href="https://www.y2mate.com/pt/youtube/${videoId}" target="_blank">Download</a>`;
          }, 1500);
        // Altera o título da página para "Youtube Lite"
        document.title = "Youtube (Lite)";
      }, 500);
    }


 // Função para verificar a URL a cada 2 segundos
    function checkURL() {

        removerTagsScript();
        removeTagsComPalavrasChave();

        const currentURL = window.location.href;
        if (currentURL !== localStorage.getItem('lastCheckedURL') && currentURL.includes("/watch?v=")) {
            window.location.reload();
            localStorage.setItem('lastCheckedURL', currentURL);
            const videoId = getVideoIdFromUrl();
            if (videoId) {
                createCustomIframe(videoId);
            }
        }
    }

    // Inicia o loop para verificar a URL a cada 1 segundos
    setInterval(checkURL, 1000);

    // Verifica a URL quando o script é carregado pela primeira vez
    const videoId = getVideoIdFromUrl();
    if (videoId) {
        createCustomIframe(videoId);
    }
})();