// ==UserScript== // @name YouTube 脚本手机版 // @namespace http://tampermonkey.net/ // @version 0.4.4 // @description 下载视频,移除广告,自动跳过广告 // @author sl00p // @match https://m.youtube.com/* // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/389633/YouTube%20%E8%84%9A%E6%9C%AC%E6%89%8B%E6%9C%BA%E7%89%88.user.js // @updateURL https://update.greasyfork.icu/scripts/389633/YouTube%20%E8%84%9A%E6%9C%AC%E6%89%8B%E6%9C%BA%E7%89%88.meta.js // ==/UserScript== (function() { 'use strict'; setInterval(function() { let ads = ["item GoogleActiveViewElement", "companion-ad-container"]; let bCompacts = document.getElementsByClassName("slim_video_action_bar_renderer_button yt-spec-button-view-model"); let isInject = false; // Remove ads for(let idx = 0; idx < ads.length; ++idx) { let nodes = document.getElementsByClassName(ads[idx]); if(nodes && nodes.length > 0) { nodes[0].remove(); } } // Skip ads let videos = document.getElementsByTagName('video'); let adsButtom = ['ytp-ad-skip-button-container', 'ytp-ad-preview-container', 'ytp-ad-text', 'ytp-ad-timed-pie-countdown-container']; for(let idx = 0; idx < adsButtom.length; ++idx) { let buttom = document.getElementsByClassName(adsButtom[idx]); if(videos && videos.length > 0 && buttom && buttom.length > 0) { if (videos[0].currentTime && videos[0].duration) { videos[0].currentTime = videos[0].duration; } } } // Test if injected already for(let idx = 0; idx < bCompacts.length; ++idx) { console.log(bCompacts[idx].innerText.trim()) if(bCompacts[idx].innerText.trim() === "下载") { isInject = true; } } // Directly return if match shorts if(window.location.href.indexOf('shorts') !== -1) { return 0; } if(!isInject && bCompacts.length >= 3) { let bReport = bCompacts[2]; if(bReport && bReport !== undefined) { let bParent = bReport.parentElement; let bDown = bReport.cloneNode(true); bDown.getElementsByClassName("yt-spec-button-shape-next__button-text-content")[0].innerText = "下载"; bDown.getElementsByTagName("svg")[0].outerHTML = ``; bDown.onclick = function() { window.open("https://yt5s.com/en50?q=" + window.location.href); }; bParent.appendChild(bDown); } } }, 500); })();