Lazy Embedded Video

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

当前为 2021-07-24 提交的版本,查看 最新版本

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

QingJ © 2025

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