Lazy Embedded Video

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

目前為 2017-10-30 提交的版本,檢視 最新版本

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

QingJ © 2025

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