No Embed Youtube

replace embed iframe, object with anchor link.

当前为 2015-03-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name No Embed Youtube
  3. // @description replace embed iframe, object with anchor link.
  4. // @namespace eight04.blogspot.com
  5. // @include http*
  6. // @exclude http://www.youtube.com/*
  7. // @exclude https://www.youtube.com/*
  8. // @version 1.3.0
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. "use strict";
  13.  
  14. var xpath = "//iframe[contains(@src,'youtube.com/embed/') and not(ancestor::*[@id='YTLT-player'])]|" +
  15. "//iframe[contains(@src,'youtube.com/v/') and not(ancestor::*[@id='YTLT-player'])]|" +
  16. "//object[./param[contains(@value,'youtube.com/v/')] and not(ancestor::*[@id='YTLT-player'])]|" +
  17. "//embed[contains(@src,'youtube.com/v/') and not(ancestor::object) and not(ancestor::*[@id='YTLT-player'])]";
  18. var unEmbed = function(node){
  19. var result = document.evaluate(
  20. xpath, node, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  21. var element = null;
  22. var i = 0, j;
  23. while(element = result.snapshotItem(i++)){
  24. // iframe or embed
  25. var url = element.src;
  26. // object
  27. if(!url){
  28. for(j = 0; j < element.childNodes.length; j++){
  29. var pa = element.childNodes[j];
  30. if(pa.nodeName == "PARAM" && pa.getAttribute("name") == "movie"){
  31. url = pa.getAttribute("value");
  32. break;
  33. }
  34. }
  35. }
  36. if(!url){
  37. continue;
  38. }
  39. var id = url.match(/(embed|v)\/(.+?)(\?|&|$)/)[2];
  40. var a = document.createElement("a");
  41. var pageUrl = "http://www.youtube.com/watch?v=" + id;
  42. a.appendChild(document.createTextNode(pageUrl));
  43. a.setAttribute("href", pageUrl.replace("http:", ""));
  44. a.setAttribute("target", "_blank");
  45. a.className = "unembed";
  46. element.parentNode.replaceChild(a, element);
  47. }
  48. };
  49.  
  50. unEmbed(document.documentElement);
  51.  
  52. var thread = function(){
  53. var data = [],
  54. maxLoop = 50,
  55. pos = 0,
  56. loopCount = 0,
  57. started = false;
  58. var worker = function(){
  59. for (loopCount = 0; pos < data.length && loopCount < maxLoop; pos++, loopCount++) {
  60. unEmbed(data[pos]);
  61. }
  62. };
  63. var start = function(){
  64. if (started) return;
  65. started = true;
  66. worker();
  67. if (pos < data.length) {
  68. loopCount = 0;
  69. setTimeout(worker, 16);
  70. } else {
  71. started = false;
  72. data = [];
  73. pos = 0;
  74. }
  75. };
  76. var queue = function(node){
  77. data.push(node);
  78. };
  79. return {
  80. start: start,
  81. queue: queue
  82. };
  83. }();
  84.  
  85. var observer = function(){
  86. // Observer
  87. new MutationObserver(function(mutations){
  88. var i, j, m;
  89. for(i = 0; i < mutations.length; i++){
  90. m = mutations[i];
  91. if(m.type != "childList"){
  92. return;
  93. }
  94. for(j = 0; j < m.addedNodes.length; j++){
  95. thread.queue(m.addedNodes[j]);
  96. }
  97. }
  98. thread.start();
  99. }).observe(document.body, {
  100. childList: true,
  101. subtree: true
  102. });
  103. }();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址