Greasy Fork镜像 还支持 简体中文。

Lazy Embedded Video

Lazy load embedded videos from Youtube/Dailymotion/Vimeo/Rutube/Twitch/Ustream/Coub/Vine/Facebook

目前為 2017-09-29 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Lazy Embedded Video
  3. // @namespace zeusex81@gmail.com
  4. // @description Lazy load embedded videos from Youtube/Dailymotion/Vimeo/Rutube/Twitch/Ustream/Coub/Vine/Facebook
  5. // @version 3.1
  6. // @include *
  7. // @icon https://i.imgur.com/rf0mFDM.png
  8. // @license MIT
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. var a = document.createElement("A");
  16. try { a.href = top.location.href; }
  17. catch(e) { a.href = document.referrer || location.href; }
  18. if(a.hostname != location.hostname || /^([^.]+\.)?(youtube|dailymotion|vimeo|rutube|twitch|ustream|coub|vine|facebook)\.[^.]+$/.test(a.hostname))
  19. return;
  20. var getValue = typeof(GM_getValue) != "undefined" ? GM_getValue :
  21. function(name, value) { return localStorage.getItem(name) || value; };
  22. var setValue = typeof(GM_setValue) != "undefined" ? GM_setValue :
  23. function(name, value) { localStorage.setItem(name, value); };
  24. var settings = JSON.parse(getValue("zeusLEV", '[false,true,[]]'));
  25. if(settings[2].includes(location.hostname))
  26. return;
  27. window.addEventListener("message", function(e) {
  28. if(e.data.startsWith("zeusLEV CSP")) {
  29. iframes[parseInt(e.data.substr(11))].dataset.LEV_CSP = true;
  30. return;
  31. }
  32. settings = JSON.parse(getValue("zeusLEV", '[false,true,[]]'));
  33. switch(e.data) {
  34. case "zeusLEV autoplay false" : settings[0] = false; break;
  35. case "zeusLEV autoplay true" : settings[0] = true; break;
  36. case "zeusLEV flash false" : settings[1] = false; break;
  37. case "zeusLEV flash true" : settings[1] = true; break;
  38. case "zeusLEV reset" : settings[2] = []; break;
  39. case "zeusLEV whitelist" :
  40. observer.disconnect();
  41. cancelAnimationFrame(animation);
  42. if(!settings[2].includes(location.hostname))
  43. settings[2].push(location.hostname);
  44. for(var i = 0; i < iframes.length; i++)
  45. iframes[i].removeAttribute("srcdoc");
  46. break;
  47. default : return;
  48. }
  49. setValue("zeusLEV", JSON.stringify(settings));
  50. });
  51. var html, iframes = [];
  52. var createHtml = function(url, src, api, background_img) {
  53. /(.*\/\/(?:[^.\/]+\.)?([^.\/]+)\.[^.\/]+)\//i.test(url);
  54. var provider_url = RegExp.$1, provider_name = RegExp.$2, data_convert = "", button_color = "";
  55. api += '&callback=jsonpCallback';
  56. if(api.includes("yahooapis"))
  57. data_convert += 'data = data.query.results.json;';
  58. switch(provider_name) {
  59. case "youtube" :
  60. button_color = "#c22";
  61. data_convert += 'data = {'+
  62. 'thumbnail_url: (data.items[0].snippet.thumbnails.maxres || data.items[0].snippet.thumbnails.standard || '+
  63. 'data.items[0].snippet.thumbnails.high || data.items[0].snippet.thumbnails.medium || '+
  64. 'data.items[0].snippet.thumbnails.default).url,'+
  65. 'title: data.items[0].snippet.title,'+
  66. 'author_url: "//www.youtube.com/channel/"+data.items[0].snippet.channelId,'+
  67. 'author_name: data.items[0].snippet.channelTitle,'+
  68. 'duration: data.items[0].contentDetails ? /PT(\\d+H)?(\\d+M)?(\\d+S)?/i.test(data.items[0].contentDetails.duration) && '+
  69. '(parseInt(RegExp.$1||0)*3600+parseInt(RegExp.$2||0)*60+parseInt(RegExp.$3||0)) || "LIVE" : "PLAYLIST"'+
  70. '};';
  71. // data_convert += 'if(data.thumbnail_url) {'+
  72. // 'var img = new Image();'+
  73. // 'img.onload = function() {'+
  74. // 'var valid = this.naturalWidth > 120;'+
  75. // 'if(this.src.includes("hqdefault_live")) {'+
  76. // 'this.src = this.src.replace("hqdefault"+(valid ? "" : "_live"), "maxresdefault");'+
  77. // '} else if(valid) {'+
  78. // 'document.body.style.backgroundImage = "url("+this.src+")";'+
  79. // '} else if(this.src.includes("maxresdefault")) {'+
  80. // 'this.src = this.src.replace("maxresdefault", "sddefault");'+
  81. // '} else {'+
  82. // 'document.body.style.backgroundImage = "url("+this.src.replace("sddefault", "hqdefault")+")";'+
  83. // '}'+
  84. // '};'+
  85. // 'img.src = removeProtocol(data.thumbnail_url.replace(/\\w+.jpg$/, "hqdefault_live.jpg"));'+
  86. // 'delete data.thumbnail_url;'+
  87. // '}';
  88. break;
  89. case "dailymotion" :
  90. button_color = "#fd5";
  91. // data_convert += 'if(data.thumbnail_url) data.thumbnail_url = data.thumbnail_url.replace(/\\/x240[^.]+/i, "");';
  92. data_convert += 'data.author_url = data["owner.url"];'+
  93. 'data.author_name = data["owner.screenname"];'+
  94. 'if(!data.duration) data.duration = "LIVE";';
  95. break;
  96. case "vimeo" :
  97. button_color = "#5af";
  98. data_convert += 'if(data.thumbnail_url) data.thumbnail_url = data.thumbnail_url.replace(/_\\d+x\\d+/i, "");';
  99. break;
  100. case "rutube" :
  101. button_color = "#444";
  102. data_convert += 'if(data.thumbnail_url) data.thumbnail_url = data.thumbnail_url.replace(/\\?.+/i, "");';
  103. break;
  104. case "twitch" :
  105. button_color = "#548";
  106. var id = url.match(/[^\/]+$/)[0];
  107. if(src.includes("channel")) { // channel live
  108. data_convert += 'var script = document.getElementById("api");'+
  109. 'if(script.src.includes("/users")) {'+
  110. 'if(data.users[0]) {'+
  111. 'var script2 = document.createElement("SCRIPT");'+
  112. 'script2.id = "api";'+
  113. 'script2.src = "'+api+'".replace("{api}", "streams")+"&channel="+data.users[0]._id;'+
  114. 'document.body.replaceChild(script2, script);'+
  115. '}'+
  116. 'return;'+
  117. '} else if(script.src.includes("/streams")) {'+
  118. 'if(data.streams.length == 0) {'+
  119. 'document.getElementById("space").insertAdjacentHTML("afterend", "<div id=duration>offline</div>");'+
  120. 'var script2 = document.createElement("SCRIPT");'+
  121. 'script2.id = "api";'+
  122. 'script2.src = "'+api+'".replace("{api}", "channels/"+script.src.match(/[^=]+$/)[0]);'+
  123. 'document.body.replaceChild(script2, script);'+
  124. 'return;'+
  125. '}'+
  126. 'if(data.streams[0].preview)'+
  127. 'data.streams[0].channel.video_banner = data.streams[0].preview.template.replace("{width}x{height}", "0x0");'+
  128. 'else delete data.streams[0].channel.video_banner;'+
  129. 'data = data.streams[0].channel;'+
  130. '}'+
  131. 'data.title = data.status || "Untitled Broadcast";'+
  132. 'if(data.video_banner) data.thumbnail_url = data.video_banner;'+
  133. 'if(data.url) data.author_url = data.url;'+
  134. 'if(data.display_name) data.author_name = data.display_name;'+
  135. 'if(data.game) data.duration = \'playing <a target=_blank href="'+provider_url+
  136. '/directory/game/\'+data.game+\'">\'+data.game+\'</a>\';'+
  137. 'if(document.getElementById("duration")) delete data.duration;';
  138. if(background_img)
  139. api = api.replace("{api}", "users")+'&login='+id;
  140. else
  141. api = api.replace("{api}", "streams")+'&channel='+id;
  142. } else { // video recorded
  143. api = api.replace("{api}", "videos/"+id);
  144. data_convert += 'if(data.preview) data.thumbnail_url = data.preview.template.replace("{width}x{height}", "0x0");'+
  145. 'if(data.channel) data.author_url = data.channel.url;'+
  146. 'if(data.channel) data.author_name = data.channel.display_name;'+
  147. 'if(data.length) data.duration = data.length;';
  148. }
  149. break;
  150. case "ustream" :
  151. button_color = "#f82";
  152. if(background_img) // channel live
  153. data_convert += 'delete data.thumbnail_url;';
  154. break;
  155. case "coub" :
  156. button_color = "#04f";
  157. data_convert += 'if(data.channel_url) data.author_url = data.channel_url;';
  158. break;
  159. case "vine" :
  160. button_color = "#0b8";
  161. break;
  162. case "facebook" :
  163. button_color = "#ccc";
  164. data_convert += 'data.title = /<a.*?>(.+)<\\/a><p>/i.test(data.html) ? RegExp.$1 : "Untitled";';
  165. break;
  166. }
  167. if(!html) html = [
  168. '<!doctype html>'+
  169. '<html>'+
  170. '<head>'+
  171. '<title>Lazy Embedded Video</title>'+
  172. '<style>'+
  173. 'html { height:100%; } '+
  174. 'body { margin:0; height:100%; color:white; font:14px sans-serif; '+
  175. 'background:black center/100% no-repeat; } '+
  176. 'a { color:inherit; font-weight:bold; text-decoration:none; } '+
  177. 'a:hover { text-decoration:underline; } '+
  178. '#interface { position:absolute; width:100%; height:100%; overflow:hidden; opacity:0.9; '+
  179. '-moz-user-select:none; -webkit-user-select:none; -ms-user-select:none; user-select:none; } '+
  180. '#playButton { display:flex; height:100%; cursor:pointer; } '+
  181. '#playButton > div { width:70px; height:70px; margin:auto; border-radius:50%; background-color:black; } '+
  182. '#playButton:hover > div { background-color:', button_color, '; } '+
  183. '#playButton > div > div { width:0; height:0; margin:20px 0 0 25px; border:solid transparent; '+
  184. 'border-width:14px 0px 14px 28px; border-left-color:white; } '+
  185. '#infobar { position:absolute; top:0px; width:100%; height:32px; display:flex; '+
  186. 'box-sizing:border-box; background:black; border:0px solid grey; border-bottom-width:1px; } '+
  187. '#author, #title, #duration { overflow:hidden; white-space:nowrap; margin:auto 8px; } '+
  188. '#author { flex-shrink:0; max-width:30%; color:', button_color ,'; } '+
  189. '#space { flex-grow:1; } '+
  190. '#duration { flex-shrink:0; } '+
  191. '#settingsButton { flex-basis:32px; font:bold 20px sans-serif; text-align:center; cursor:pointer; } '+
  192. '#settingsButton:hover { color:', button_color, '; } '+
  193. '#settingsButton.active { background-color:', button_color, '; color:black; } '+
  194. '#settingsPanel { position:absolute; right:0px; top:31px; max-height:100%; margin:0px; list-style:none; padding:8px; '+
  195. 'border:solid grey; border-width:0px 0px 1px 1px; background-color:', button_color ,'; color:black; cursor:default; visibility:hidden; } '+
  196. '#settingsPanel.active { visibility:visible; } '+
  197. '#settingsPanel label { display:inline-block; width:144px; vertical-align:top; } '+
  198. '#settingsPanel button { width:100%; }'+
  199. '</style>'+
  200. '</head>'+
  201. '<body>'+
  202. '<div id=interface>'+
  203. '<div id=playButton onclick="location.replace(\'', src, '\');"><div><div></div></div></div>'+
  204. '<div id=infobar>'+
  205. '<a id=author target=_blank onmouseenter="this.title = this.scrollWidth > this.clientWidth ? this.textContent : \'\';" href="', provider_url, '">', provider_name, '</a>'+
  206. '<a id=title target=_blank onmouseenter="this.title = this.scrollWidth > this.clientWidth ? this.textContent : \'\';" href="', url, '">', url, '</a>'+
  207. '<div id=space></div>'+
  208. '<span id=settingsButton>⚙</span>'+
  209. '</div>'+
  210. '<ul id=settingsPanel>'+
  211. '<li><label>Allow autoplay:</label><input class=setting type=checkbox', '', '></li>'+
  212. '<li><label>Legacy Flash support:</label><input class=setting type=checkbox', '', '></li>'+
  213. '<li><button class=setting>Whitelist this site</button>'+
  214. '<li><button class=setting>Clear whitelist</button>'+
  215. '</ul>'+
  216. '</div>'+
  217. '<script>'+
  218. 'parent.postMessage("zeusLEV CSP ', iframes.length, '", "'+location.href+'");'+
  219. 'var settingsButton = document.getElementById("settingsButton");'+
  220. 'var settingsPanel = document.getElementById("settingsPanel");'+
  221. 'settingsButton.onclick = function() {'+
  222. 'settingsButton.classList.toggle("active");'+
  223. 'settingsPanel.classList.toggle("active");'+
  224. '};'+
  225. '[].slice.call(settingsPanel.getElementsByClassName("setting")).forEach(function(e, i) {'+
  226. 'switch(i) {'+
  227. 'case 0: e.onchange = function() { parent.postMessage("zeusLEV autoplay "+e.checked, "'+location.href+'"); }; break;'+
  228. 'case 1: e.onchange = function() { parent.postMessage("zeusLEV flash "+e.checked , "'+location.href+'"); }; break;'+
  229. 'case 2: e.onclick = function() { parent.postMessage("zeusLEV whitelist" , "'+location.href+'"); }; break;'+
  230. 'case 3: e.onclick = function() { parent.postMessage("zeusLEV reset" , "'+location.href+'"); }; break;'+
  231. '}'+
  232. '});'+
  233. 'var loaded = false;'+
  234. 'function removeProtocol(url) { return url.replace(/^[a-z]+:/i, ""); }'+
  235. 'function jsonpCallback(data) {',
  236. data_convert,
  237. 'loaded = true;'+
  238. 'if(data.thumbnail_url) document.body.style.backgroundImage = "url("+removeProtocol(data.thumbnail_url)+")";'+
  239. 'if(data.url) document.getElementById("title").href = removeProtocol(data.url);'+
  240. 'if(data.title) document.getElementById("title").textContent = data.title;'+
  241. 'if(data.author_url) document.getElementById("author").href = removeProtocol(data.author_url);'+
  242. 'if(data.author_name) document.getElementById("author").textContent = data.author_name;'+
  243. 'if(data.duration) document.getElementById("space").insertAdjacentHTML("afterend",'+
  244. '"<div id=duration>"+(Number(data.duration) ? new Date(data.duration*1000).toISOString().substr(11,8) : data.duration)+"</div>");'+
  245. '}'+
  246. '</script>'+
  247. '<script id=api src="', api, '"></script>'+
  248. '<script>'+
  249. 'if(!loaded)'+
  250. 'document.body.style.backgroundImage = "', background_img, '";'+
  251. '</script>'+
  252. '</body>'+
  253. '</html>'
  254. ];
  255. html[ 1] = button_color;
  256. html[ 3] = button_color;
  257. html[ 5] = button_color;
  258. html[ 7] = button_color;
  259. html[ 9] = button_color;
  260. html[11] = src;
  261. html[13] = provider_url;
  262. html[15] = provider_name;
  263. html[17] = url;
  264. html[19] = url;
  265. html[21] = settings[0] ? ' checked' : '';
  266. html[23] = settings[1] ? ' checked' : '';
  267. html[25] = iframes.length;
  268. html[27] = data_convert;
  269. html[29] = api;
  270. html[31] = background_img;
  271. };
  272. var createOembed = function(api, url) { return api+encodeURIComponent(url); };
  273. // var createNOembed = function(api, url) { return createOembed("https://noembed.com/embed?url=", url); };
  274. var createYOembed = function(api, url) { return createOembed("//query.yahooapis.com/v1/public/yql?format=json&q=",
  275. 'SELECT * FROM json WHERE url="'+createOembed(location.protocol+api,url)+'"'); };
  276. var createLazyVideo = function(elem) {
  277. var id, args, url, src = elem.src || elem.data || elem.dataset.src;
  278. if(!src || elem.dataset.LEV_processed) return;
  279. elem.dataset.LEV_processed = 1;
  280. a.href = src;
  281. switch(a.hostname.match(/([^.]+)\.[^.]+$/)[1]) {
  282. case "youtube" :
  283. if(/\/(?:p\/|embed\/videoseries)([^&]*)/i.test(a.pathname)) {
  284. id = RegExp.$1 || (/[?&]list=([^&]+)/i.test(a.search) && RegExp.$1);
  285. if(!id || (settings[0] && a.search.includes("autoplay=1"))) return;
  286. args = "?autoplay=1";
  287. if(/[?&](v=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  288. if(/[?&](index=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  289. if(/[?&](start=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  290. createHtml(url =
  291. /[?&]v=([^&]+)/i.test(a.search) ? "//www.youtube.com/watch"+args+"&list="+id : "//www.youtube.com/playlist?list="+id,
  292. "//www.youtube.com/embed/videoseries"+args+"&list="+id,
  293. "https://www.googleapis.com/youtube/v3/playlists?part=snippet&fields=items/snippet(channelId,title,thumbnails,channelTitle)&key=AIzaSyDLowtdhRBblJhyDhtiPaIbwRKT_PSyHWE&id="+id,
  294. /[?&]v=([^&]+)/i.test(a.search) ? "url(//i.ytimg.com/vi/"+RegExp.$1+"/hqdefault.jpg)" : null
  295. );
  296. } else if(/\/(?:v|embed)\/([^&]*)/i.test(a.pathname)) {
  297. id = RegExp.$1 || (/[?&]v=([^&]+)/i.test(a.search) && RegExp.$1);
  298. if(!id || (settings[0] && a.search.includes("autoplay=1"))) return;
  299. args = "?autoplay=1";
  300. if(/[?&](start=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  301. createHtml(url =
  302. "//www.youtube.com/watch"+args+"&v="+id,
  303. "//www.youtube.com/embed/"+id+args,
  304. // createNOembed("//www.youtube.com/oembed?format=json&url=", location.protocol+url),
  305. "https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&fields=items(snippet(channelId,title,thumbnails,channelTitle),contentDetails/duration)&key=AIzaSyDLowtdhRBblJhyDhtiPaIbwRKT_PSyHWE&id="+id,
  306. "url(//i.ytimg.com/vi/"+id+"/hqdefault.jpg)"
  307. );
  308. }
  309. break;
  310. case "dailymotion" :
  311. if(/\/(?:swf|embed)\/(?:video\/)?([^&_]+)/i.test(a.pathname)) id = RegExp.$1;
  312. if(!id || (settings[0] && a.search.includes("autoplay=1"))) return;
  313. args = "?autoplay=1";
  314. // if(/[?&](mute=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  315. if(/[?&](start=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  316. createHtml(url =
  317. "//www.dailymotion.com/video/"+id+args,
  318. "//www.dailymotion.com/embed/video/"+id+args,
  319. // createOembed("//www.dailymotion.com/services/oembed?format=json&url=", location.protocol+url),
  320. "https://api.dailymotion.com/video/"+id+"?fields=owner.screenname,owner.url,title,url,duration,thumbnail_url",
  321. "url(//www.dailymotion.com/thumbnail/video/"+id+")"
  322. );
  323. break;
  324. case "vimeo" :
  325. if(/\/(?:moogaloop\.swf|video\/)([^&]*)/i.test(a.pathname))
  326. id = RegExp.$1 || (/[?&]clip_id=([^&]+)/i.test(a.search) && RegExp.$1);
  327. if(!id || (settings[0] && a.search.includes("autoplay=1"))) return;
  328. args = "?autoplay=1";
  329. if(/[?&](loop=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  330. if(/(\#t=[\dhms]+)/i.test(a.hash)) args += RegExp.$1;
  331. createHtml(url =
  332. "//vimeo.com/"+id+args,
  333. "//player.vimeo.com/video/"+id+args,
  334. createOembed("//vimeo.com/api/oembed.json?url=", url)
  335. );
  336. break;
  337. case "rutube" :
  338. if(/\/play\/embed\/([^&.\/]+)/i.test(a.pathname)) id = RegExp.$1;
  339. if(!id || (settings[0] && a.search.includes("autoStart=1"))) return;
  340. args = "?autoStart=1";
  341. if(/[?&](bmstart=[^&]+)/i.test(a.search)) args += "&"+RegExp.$1;
  342. createHtml(url =
  343. "//rutube.ru/"+(isNaN(id) ? "video/"+id+"/" : "tracks/"+id+".html/")+args,
  344. "//rutube.ru/play/embed/"+id+args,
  345. createOembed("//rutube.ru/api/oembed/?format=jsonp&url=", url)
  346. );
  347. break;
  348. case "twitch" :
  349. if(/[?&](channel|video)=([^&]+)/i.test(a.search)) {args = RegExp.$1; id = RegExp.$2;}
  350. else if(/[?&](stream=.+&channelId)=([^&]+)/i.test(a.search)) {args = RegExp.$1; id = RegExp.$2;}
  351. else if(/\/(.+)\/embed/i.test(a.pathname)) {args = "channel"; id = RegExp.$1;}
  352. if(!id || (settings[0] && a.search.includes("autoplay=true"))) return;
  353. createHtml(url =
  354. "//www.twitch.tv/"+(args=="video" ? id.replace("v","c/v/") : args=="channel" ? id :
  355. args.replace("stream=", "streams/").replace("&channelId", "/channel/")+id),
  356. "//player.twitch.tv/?autoplay=true&"+args+"="+id,
  357. "https://api.twitch.tv/kraken/{api}?client_id=0&api_version=5",
  358. args=="channel" ? "url(//static-cdn.jtvnw.net/previews-ttv/live_user_"+id+"-0x0.jpg)" : null
  359. );
  360. break;
  361. case "ustream" :
  362. if(/(?:\/embed)?\/(channel\/|recorded\/)?([^&]+)/i.test(a.pathname)) {args = RegExp.$1 || "channel/"; id = RegExp.$2;}
  363. if(!id || (settings[0] && a.search.includes("autoplay=1"))) return;
  364. createHtml(url =
  365. "//www.ustream.tv/"+args+id,
  366. "//www.ustream.tv/embed/"+(args=="channel/" ? "" : args)+id+"?html5ui=1&autoplay=1",
  367. createYOembed("//www.ustream.tv/oembed?format=json&url=", url),
  368. args=="channel/" && !isNaN(id) ? "url(//static-cdn1.ustream.tv/i/channel/live/1_"+id+",640x360,b:0.jpg)" : null
  369. );
  370. break;
  371. case "coub" :
  372. if(/\/embed\/([^&]+)/i.test(a.pathname)) id = RegExp.$1;
  373. if(!id || (settings[0] && a.search.includes("autostart=true"))) return;
  374. createHtml(url =
  375. "//coub.com/view/"+id,
  376. "//coub.com/embed/"+id+"?startWithHD=true&autostart=true",
  377. createYOembed("//coub.com/api/oembed.json?url=", url)
  378. );
  379. break;
  380. case "vine" :
  381. if(/\/v\/([^&]+)\/embed\/([^&]+)/i.test(a.pathname)) {args = RegExp.$2; id = RegExp.$1;}
  382. if(!id) return;
  383. createHtml(url =
  384. "//vine.co/v/"+id,
  385. "//vine.co/v/"+id+"/embed/"+args+"?audio=1",
  386. createOembed("//vine.co/oembed.json?url=", url)
  387. );
  388. break;
  389. case "facebook" :
  390. if(a.pathname.endsWith("/plugins/video.php") && /[?&]href=([^&]+)/i.test(a.search)) {
  391. url = decodeURIComponent(RegExp.$1).replace(/^[a-z]+:/i, '');
  392. if(/\/videos.*?\/(\d+)/i.test(url)) id = RegExp.$1;
  393. }
  394. if(!id || (settings[0] && a.search.includes("autoplay=1"))) return;
  395. createHtml(
  396. url,
  397. "//www.facebook.com/plugins/video.php?autoplay=1&href="+encodeURIComponent(location.protocol+url),
  398. createOembed("//www.facebook.com/plugins/video/oembed.json/?url=", location.protocol+url),
  399. "url(//graph.facebook.com/"+id+"/picture)"
  400. );
  401. break;
  402. default :
  403. return;
  404. }
  405. if(elem.tagName != "IFRAME") {
  406. if(elem.parentNode.tagName == "OBJECT")
  407. elem = elem.parentNode;
  408. var iframe = document.createElement("IFRAME");
  409. iframe.src = src;
  410. iframe.id = elem.id;
  411. iframe.name = elem.name;
  412. iframe.className = elem.className;
  413. iframe.style.cssText = elem.style.cssText;
  414. iframe.width = elem.width;
  415. iframe.height = elem.height;
  416. iframe.frameBorder = elem.border;
  417. iframe.align = elem.align;
  418. elem.parentNode.replaceChild(iframe, elem);
  419. elem = iframe;
  420. }
  421. elem.dataset.LEV_processed = 2;
  422. elem.allowFullscreen = true;
  423. elem.srcdoc = html.join("");
  424. iframes.push(elem);
  425. setTimeout(function() {
  426. if(!elem.dataset.LEV_CSP)
  427. elem.removeAttribute("srcdoc");
  428. }, 1000);
  429. };
  430. var refresh = true, observer, animation;
  431. var update = function() {
  432. if(!document.body) {
  433. } else if(!observer) {
  434. observer = new MutationObserver(function() { refresh = true; });
  435. observer.observe(document.body, {childList: true, attributes: false, characterData: false, subtree: true});
  436. } else if(refresh) {
  437. for(var i = 0, j, nodes; i < 3; i++) {
  438. nodes = document.getElementsByTagName(["IFRAME", "EMBED", "OBJECT"][i]);
  439. for(j = 0; j < nodes.length; j++)
  440. createLazyVideo(nodes[j]);
  441. if(!settings[1]) break;
  442. }
  443. refresh = false;
  444. }
  445. animation = requestAnimationFrame(update);
  446. };
  447. update();
  448. })();

QingJ © 2025

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