您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
replace embed iframe, object with anchor link.
当前为
// ==UserScript== // @name No Embed Youtube // @description replace embed iframe, object with anchor link. // @namespace eight04.blogspot.com // @include http* // @exclude http://www.youtube.com/watch* // @exclude https://www.youtube.com/watch* // @version 1.0 // @grant none // @run-at document-start // ==/UserScript== /* embed code from youtube: <iframe width="420" height="315" src="//www.youtube.com/embed/MOyueLEw2xo" frameborder="0" allowfullscreen></iframe> <object width="420" height="315"><param name="movie" value="//www.youtube.com/v/MOyueLEw2xo?hl=zh_TW&version=3"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube.com/v/MOyueLEw2xo?hl=zh_TW&version=3" type="application/x-shockwave-flash" width="420" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object> */ "use strict"; if(/youtube\.com\/(v|embed)\//.test(window.location.href)){ // stop iframe loading window.location.href = "about:blank"; // is there a better way to pause page? window.stop(); alert("pause"); }else{ let xpath = "//iframe[contains(@src,'youtube.com/embed/')]|" + "//object[./param[contains(@value,'youtube.com/v/')]]|" + "//embed[contains(@src,'youtube.com/v/') and not(ancestor::object)]"; let unEmbed = function(node){ let result = document.evaluate( xpath, node, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); let i = 0; let element = null; while(element = result.snapshotItem(i++)){ // iframe or embed let url = element.src; // object if(!url){ for(let i = 0; i < element.childNodes.length; i++){ let pa = element.childNodes[i]; if(pa.getAttribute("name") == "movie"){ url = pa.getAttribute("value"); break; } } } if(!url){ console.log("can't find url!", element); continue; } let id = url.match(/(embed|v)\/(.+?)(\?|&|$)/)[2]; let a = document.createElement("a"); let pageUrl = "http://www.youtube.com/watch?v=" + id; a.appendChild(document.createTextNode(pageUrl)); a.setAttribute("href", pageUrl.replace("http:", "")); a.setAttribute("target", "_blank"); a.className = "unembed"; element.parentNode.replaceChild(a, element); } }; document.addEventListener("DOMNodeInserted", function(e){ unEmbed(e.target); // alert("pause"); }, false); }