Lazy Embedded Video

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

当前为 2017-10-13 提交的版本,查看 最新版本

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

QingJ © 2025

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