Inject2Download

Simple media download script

当前为 2018-03-01 提交的版本,查看 最新版本

  1. // NOTE: This script now requires GM_setValue/getValue for storing preferences
  2.  
  3. // ==UserScript==
  4. // @name Inject2Download
  5. // @namespace http://lkubuntu.wordpress.com/
  6. // @version 0.3.0
  7. // @description Simple media download script
  8. // @author Anonymous Meerkat
  9. // @include *
  10. // @grant GM_getValue
  11. // @grant GM_setValue
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. "use strict";
  17.  
  18. var injected_set = {};
  19. var did_prefs = false;
  20.  
  21. if (unsafeWindow)
  22. window = unsafeWindow;
  23.  
  24. // Most of these are disabled by default in order to avoid modifying the user experience in unexpected ways
  25. var config_template = {
  26. simpleplayers: {
  27. name: "Replace with native players if possible",
  28. options: {
  29. "yes": "Yes",
  30. "flash": "Only if Flash is used",
  31. "no": "No"
  32. },
  33. default: "no"
  34. },
  35. noads: {
  36. name: "Block ads if possible (using a proper adblocker is highly recommended)",
  37. default: false
  38. },
  39. // TODO: Implement
  40. /*download: {
  41. name: "Enable downloading via the player itself if possible",
  42. default: false
  43. },*/
  44. blacklist: {
  45. name: "Blacklisted domains (one per line)",
  46. type: "textarea",
  47. default: ""
  48. }
  49. };
  50.  
  51. var config = {};
  52.  
  53. for (var key in config_template) {
  54. config[key] = config_template[key].default;
  55. /*(function(key) {
  56. GM.getValue(key).then(
  57. function (data) {
  58. if (data !== undefined)
  59. config[key] = data;
  60. },
  61. function () {}
  62. );
  63. })(key);*/
  64. var data = GM_getValue(key);
  65. if (data !== undefined)
  66. config[key] = data;
  67. }
  68.  
  69. var blacklist = config.blacklist.split("\n");
  70. var blacklisted = false;
  71. var host = window.location.hostname.toLowerCase();
  72. for (var i = 0; i < blacklist.length; i++) {
  73. var normalized = blacklist[i].replace(/^ */, "").replace(/ *$/, "");
  74. if (host === normalized.toLowerCase() ||
  75. host.indexOf("." + normalized) === (host.length - normalized.length - 1)) {
  76. console.log("[i2d] Blacklisted");
  77. blacklisted = true;
  78. break;
  79. }
  80. }
  81.  
  82. // Preferences
  83. if (window.location.hostname.toLowerCase() == "anonymousmeerkat.github.io" &&
  84. window.location.href.indexOf("anonymousmeerkat.github.io/inject2download/prefs.html") >= 0 &&
  85. !did_prefs) {
  86. run_on_load(function() {
  87. var text = [
  88. "<html><head><title>Inject2Download Preferences</title></head><body style='margin:0;padding:1em'>",
  89. "<div style='width:100%'><h2>Inject2Download</h2></div>",
  90. "<div id='prefs'></div>",
  91. "<div id='save'><button id='savebtn'>Save</button><br /><span id='savetxt'></span></div>",
  92. "</body></html>"
  93. ].join("");
  94. document.documentElement.innerHTML = text;
  95.  
  96. var prefs = document.getElementById("prefs");
  97. prefs.appendChild(document.createElement("hr"));
  98. for (var key in config_template) {
  99. var template = config_template[key];
  100.  
  101. var prefdiv = document.createElement("div");
  102. prefdiv.id = "pref-" + key;
  103. prefdiv.style.paddingBottom = "1em";
  104. var title = document.createElement("div");
  105. title.style.paddingBottom = ".5em";
  106. title.innerHTML = template.name;
  107. prefdiv.appendChild(title);
  108.  
  109. if (typeof template.default === "boolean" ||
  110. "options" in template) {
  111. var options = template.options;
  112. if (typeof template.default === "boolean") {
  113. options = {
  114. "true": "Yes",
  115. "false": "No"
  116. };
  117. }
  118.  
  119. for (var option in options) {
  120. var input = document.createElement("input");
  121. input.name = key;
  122. input.value = option;
  123. input.type = "radio";
  124. input.id = key + "-" + option;
  125.  
  126. if (config[key].toString() === option)
  127. input.setAttribute("checked", true);
  128.  
  129. var label = document.createElement("label");
  130. label.setAttribute("for", input.id);
  131. label.innerHTML = options[option];
  132.  
  133. prefdiv.appendChild(input);
  134. prefdiv.appendChild(label);
  135. prefdiv.appendChild(document.createElement("br"));
  136. }
  137. } else if (template.type === "textarea") {
  138. var input = document.createElement("textarea");
  139. input.name = key;
  140. input.style.width = "30em";
  141. input.style.height = "10em";
  142. input.innerHTML = config[key];
  143.  
  144. prefdiv.appendChild(input);
  145. } else {
  146. var input = document.createElement("input");
  147. input.name = key;
  148. input.value = config[key];
  149. input.style.width = "50em";
  150.  
  151. prefdiv.appendChild(input);
  152. }
  153.  
  154. prefs.appendChild(prefdiv);
  155. prefs.appendChild(document.createElement("hr"));
  156. }
  157.  
  158. document.getElementById("savebtn").onclick = function() {
  159. for (var key in config_template) {
  160. var els = document.getElementsByName(key);
  161. var value = undefined;
  162. if (els.length > 1) {
  163. // radio
  164. for (var i = 0; i < els.length; i++) {
  165. if (els[i].checked) {
  166. value = els[i].value;
  167. if (value === "true")
  168. value = true;
  169. if (value === "false")
  170. value = false;
  171. break;
  172. }
  173. }
  174. } else {
  175. if (els[0].tagName === "INPUT") {
  176. value = els[0].value;
  177. } else if (els[0].tagName === "TEXTAREA") {
  178. value = els[0].value;
  179. }
  180. }
  181. console.log("[i2d] " + key + " = " + value);
  182. GM_setValue(key, value);
  183. }
  184. document.getElementById("savetxt").innerHTML = "Saved!";
  185. setTimeout(function() {
  186. document.getElementById("savetxt").innerHTML = "";
  187. }, 3000);
  188. };
  189.  
  190. console.log("[i2d] Finished rendering preferences page");
  191. });
  192. did_prefs = true;
  193. }
  194.  
  195. // Helper functions
  196. function run_on_load(f) {
  197. if (document.readyState === "complete" ||
  198. document.readyState === "interactive") {
  199. f();
  200. } else {
  201. var listener = function() {
  202. if (document.readyState === "complete" ||
  203. document.readyState === "interactive") {
  204. f();
  205.  
  206. document.removeEventListener("readystatechange", listener);
  207. }
  208. };
  209.  
  210. document.addEventListener("readystatechange", listener);
  211. //document.addEventListener('DOMContentLoaded', f, false);
  212. //window.addEventListener('load', f, false);
  213. }
  214. }
  215.  
  216. function i2d_show_url(namespace, url, description) {
  217. function get_absolute_url(url) {
  218. var a = document.createElement('a');
  219. a.href = url;
  220. return a.href;
  221. }
  222.  
  223. function run_on_load(f) {
  224. if (document.readyState === "complete" ||
  225. document.readyState === "interactive") {
  226. f();
  227. } else {
  228. var listener = function() {
  229. if (document.readyState === "complete" ||
  230. document.readyState === "interactive") {
  231. f();
  232.  
  233. document.removeEventListener("readystatechange", listener);
  234. }
  235. };
  236.  
  237. document.addEventListener("readystatechange", listener);
  238. //document.addEventListener('DOMContentLoaded', f, false);
  239. //window.addEventListener('load', f, false);
  240. }
  241. }
  242.  
  243. if (!description)
  244. description = "";
  245.  
  246. if (typeof url !== "string" || url.replace("\s", "").length === 0)
  247. return;
  248.  
  249. if (url.match(/^mediasource:/) || url.match(/^blob:/))
  250. return;
  251.  
  252. url = get_absolute_url(url);
  253.  
  254. if (!("i2d_url_list" in window))
  255. window.i2d_url_list = [];
  256.  
  257. for (var i = 0; i < i2d_url_list.length; i++) {
  258. if (i2d_url_list[i][0] === namespace &&
  259. i2d_url_list[i][1] === url &&
  260. i2d_url_list[i][2] === description)
  261. return;
  262. }
  263.  
  264.  
  265. i2d_url_list.push([namespace, url, description]);
  266.  
  267. var newurl = decodeURIComponent(url);
  268.  
  269. var text = "[" + namespace + "] " + description + ": ";
  270.  
  271. console.log("[i2d] " + text + newurl);
  272.  
  273. run_on_load(function() {
  274. var el = document.getElementById("i2d-popup");
  275. var elspan = document.getElementById("i2d-popup-x");
  276. var elspan1 = document.getElementById("i2d-popup-close");
  277. var elspan2 = document.getElementById("i2d-popup-prefs");
  278. var eldiv = document.getElementById("i2d-popup-div");
  279. var eldivhold = document.getElementById("i2d-popup-div-holder");
  280. if (!el) {
  281. el = document.createElement("div");
  282. el.style.all = "initial";
  283. //el.style.position = "absolute";
  284. el.style.width = "max(60%, 100em)";
  285. el.style.height = "max(60%, 100em)";
  286. el.style.maxWidth = "100%";
  287. el.style.maxHeight = "100%";
  288. el.style.height = "auto";
  289. el.style.width = "auto";
  290. el.style.background = "white";
  291. el.style.top = "0px";
  292. el.style.left = "0px";
  293. el.style.zIndex = Number.MAX_SAFE_INTEGER - 1;
  294. el.style.color = "black";
  295. el.style.fontFamily = "sans-serif";
  296. el.style.fontSize = "16px";
  297. el.style.lineHeight = "normal";
  298. el.style.textAlign = "left";
  299. el.style.overflow = "scroll";
  300.  
  301. /*el.ondblclick = function() {
  302. el.parentElement.removeChild(el);
  303. };*/
  304. eldivhold = document.createElement("div");
  305. eldivhold.id = "i2d-popup-span-holder";
  306. eldivhold.style.all = "initial";
  307. eldivhold.style.width = "100%";
  308. eldivhold.style.display = "block";
  309. eldivhold.style.overflow = "auto";
  310. eldivhold.style.paddingBottom = ".5em";
  311.  
  312. elspan = document.createElement("span");
  313. elspan.style.all = "initial";
  314. elspan.style.fontSize = "130%";
  315. elspan.style.cursor = "pointer";
  316. elspan.style.color = "#900";
  317. elspan.style.padding = ".1em";
  318. elspan.style.float = "left";
  319. elspan.style.display = "inline";
  320. elspan.id = "i2d-popup-x";
  321. elspan.innerHTML = '[hide]';
  322. elspan.style.textDecoration = "underline";
  323. eldivhold.appendChild(elspan);
  324.  
  325. elspan1 = document.createElement("span");
  326. elspan1.style.all = "initial";
  327. elspan1.style.fontSize = "130%";
  328. elspan1.style.cursor = "pointer";
  329. elspan1.style.color = "#900";
  330. elspan1.style.padding = ".1em";
  331. elspan1.style.float = "right";
  332. //elspan1.style.display = "none";
  333. elspan1.style.display = "inline";
  334. elspan1.id = "i2d-popup-close";
  335. elspan1.innerHTML = '[close]';
  336. elspan1.style.textDecoration = "underline";
  337. eldivhold.appendChild(elspan1);
  338.  
  339. elspan2 = document.createElement("a");
  340. elspan2.style.all = "initial";
  341. elspan2.style.fontSize = "130%";
  342. elspan2.style.cursor = "pointer";
  343. elspan2.style.color = "#900";
  344. elspan2.style.padding = ".1em";
  345. elspan2.style.float = "left";
  346. //elspan1.style.display = "none";
  347. elspan2.style.display = "inline";
  348. elspan2.id = "i2d-popup-prefs";
  349. elspan2.innerHTML = '[options]';
  350. elspan2.href = "https://anonymousmeerkat.github.io/inject2download/prefs.html";
  351. elspan2.setAttribute("target", "_blank");
  352. elspan2.style.textDecoration = "underline";
  353. eldivhold.appendChild(elspan2);
  354.  
  355. //el.innerHTML = "<br style='line-height:150%' />";
  356. el.id = "i2d-popup";
  357. eldiv = document.createElement("div");
  358. eldiv.style.all = "initial";
  359. eldiv.id = "i2d-popup-div";
  360. //eldiv.style.display = "none";
  361. eldiv.style.display = "block";
  362. el.appendChild(eldiv);
  363. el.insertBefore(eldivhold, el.firstChild);
  364. document.body.appendChild(el);
  365.  
  366. elspan.onclick = function() {
  367. /*var el = document.getElementById("i2d-popup");
  368. el.parentElement.removeChild(el);*/
  369. var eldiv = document.getElementById("i2d-popup-div");
  370. var elspan = document.getElementById("i2d-popup-x");
  371. if (eldiv.style.display === "none") {
  372. elspan.innerHTML = '[hide]';
  373. eldiv.style.display = "block";
  374. elspan1.style.display = "inline";
  375. } else {
  376. elspan.innerHTML = '[show]';
  377. eldiv.style.display = "none";
  378. elspan1.style.display = "none";
  379. }
  380. };
  381.  
  382. elspan1.onclick = function() {
  383. var el = document.getElementById("i2d-popup");
  384. el.parentElement.removeChild(el);
  385. };
  386. }
  387. var shorturl = newurl;
  388. if (shorturl.length > 100) {
  389. shorturl = shorturl.substring(0, 99) + "&hellip;";
  390. }
  391. var el_divspan = document.createElement("span");
  392. el_divspan.style.all = "initial";
  393. el_divspan.innerHTML = text;
  394. eldiv.appendChild(el_divspan);
  395. var el_a = document.createElement("a");
  396. el_a.href = newurl;
  397. el_a.style.all = "initial";
  398. el_a.style.color = "blue";
  399. el_a.style.textDecoration = "underline";
  400. el_a.style.cursor = "pointer";
  401. el_a.title = newurl;
  402. el_a.innerHTML = shorturl;
  403. eldiv.appendChild(el_a);
  404. var el_br = document.createElement("br");
  405. el_br.style.all = "initial";
  406. eldiv.appendChild(el_br);
  407. //eldiv.innerHTML += text + "<a href='" + newurl + "' style='color:blue' title='" + newurl + "'>" + shorturl + "</a><br />";
  408.  
  409. // XXX: why is this needed? test: http://playbb.me/embed.php?w=718&h=438&vid=at/nw/flying_witch_-_01.mp4, animeplus.tv
  410. document.body.removeChild(el);
  411. el.style.position = "absolute";
  412. document.body.appendChild(el);
  413.  
  414. /*if (document.getElementById("i2d-popup-x"))
  415. document.getElementById("i2d-popup-x").parentElement.removeChild(document.getElementById("i2d-popup-x"));*/
  416.  
  417. /*el.insertBefore(elspan, el.firstChild);
  418. el.insertBefore(elspan1, el.firstChild);*/
  419. //el.insertBefore(eldivhold, el.firstChild);
  420. });
  421. }
  422.  
  423. function i2d_add_player(options) {
  424. var playlist = [];
  425. var elements = [];
  426. var ret = {};
  427.  
  428. /*var videoel = document.createElement("video");
  429. videoel.setAttribute("controls", "");
  430. options.element.appendChild(videoel);*/
  431.  
  432. if (!(options.elements instanceof Array) && !(options.elements instanceof NodeList)) {
  433. if (typeof options.elements === "string") {
  434. options.elements = document.querySelectorAll(options.elements);
  435. } else {
  436. options.elements = [options.elements];
  437. }
  438. }
  439. for (var i = 0; i < options.elements.length; i++) {
  440. (function(x) {
  441. if (!x)
  442. return;
  443. var videoel = document.createElement("video");
  444. videoel.setAttribute("controls", "");
  445. videoel.style.maxWidth = "100%";
  446. videoel.style.maxHeight = "100%";
  447. videoel.addEventListener("ended", function() {
  448. ret.next_playlist_item();
  449. });
  450. videoel.addEventListener("error", function() {
  451. ret.next_playlist_item();
  452. });
  453. /*var stylestr = "";
  454. for (var key in options.css) {
  455. stylestr += key + ":" + options.css[key] + ";"
  456. }*/
  457. for (var key in options.css) {
  458. videoel.style[key] = options.css[key];
  459. }
  460. //videoel.setAttribute("style", stylestr);
  461. if (options.replaceChildren) {
  462. x.innerHTML = "";
  463. }
  464. if (options.replace) {
  465. x.parentElement.replaceChild(videoel, x);
  466. } else {
  467. x.appendChild(videoel);
  468. }
  469. elements.push(videoel);
  470. })(options.elements[i]);
  471. }
  472. ret.add_urls = function(urls) {
  473. if (urls instanceof Array) {
  474. for (var i = 0; i < urls.length; i++) {
  475. ret.add_urls(urls[i]);
  476. }
  477. return;
  478. }
  479.  
  480. playlist.push(urls);
  481. if (playlist.length === 1) {
  482. ret.set_url(playlist[0]);
  483. }
  484. };
  485. ret.replace_urls = function(urls) {
  486. playlist = [];
  487. return ret.add_urls(urls);
  488. };
  489. var getext = function(url) {
  490. return url.replace(/.*\.([^/.?]*)(?:\?.*)?$/, "$1").toLowerCase();
  491. };
  492. var loadscript = function(variable, url, cb) {
  493. if (!(variable in window)) {
  494. var script = document.createElement("script");
  495. script.src = url;
  496. script.onload = cb;
  497. document.head.insertBefore(script, document.head.lastChild);
  498. } else {
  499. cb();
  500. }
  501. };
  502. ret.set_url = function(url) {
  503. if (!url)
  504. return;
  505. switch(getext(url)) {
  506. case "flv":
  507. loadscript("flvjs", "https://cdn.jsdelivr.net/npm/flv.js@latest", function() {
  508. var flvPlayer = flvjs.createPlayer({
  509. type: 'flv',
  510. url: url
  511. });
  512. for (var i = 0; i < elements.length; i++) {
  513. flvPlayer.attachMediaElement(elements[i]);
  514. }
  515. flvPlayer.load();
  516. });
  517. break;
  518. case "m3u8":
  519. loadscript("Hls", "https://cdn.jsdelivr.net/npm/hls.js@latest", function() {
  520. var hls = new Hls();
  521. hls.loadSource(url);
  522. for (var i = 0; i < elements.length; i++) {
  523. hls.attachMedia(elements[i]);
  524. }
  525. });
  526. break;
  527. default:
  528. for (var i = 0; i < elements.length; i++) {
  529. elements[i].src = url;
  530. }
  531. break;
  532. }
  533. };
  534. ret.next_playlist_item = function() {
  535. playlist = playlist.slice(1);
  536. if (playlist[0])
  537. ret.set_url(playlist[0]);
  538. };
  539. ret.setPlaying = function(playing) {
  540. for (var i = 0; i < elements.length; i++) {
  541. if (playing)
  542. elements[i].play();
  543. else
  544. elements[i].pause();
  545. }
  546. };
  547.  
  548. if (options.urls)
  549. ret.add_urls(options.urls);
  550.  
  551. return ret;
  552. }
  553.  
  554.  
  555. // Injecting functions
  556. var get_script_str = function(f) {
  557. return f.toString().replace(/^function.*{|}$/g, '');
  558. };
  559.  
  560. function add_script(s, el) {
  561. var script_body = "(function() {\n" + s + "\n})();";
  562. var myscript = document.createElement('script');
  563. myscript.className = "i2d";
  564. myscript.innerHTML = script_body;
  565. if (el) {
  566. el.appendChild(myscript);
  567. } else {
  568. document.head.appendChild(myscript);
  569. }
  570. }
  571.  
  572. function inject(variable, newvalue, aliases) {
  573. if (variable instanceof Array) {
  574. for (var i = 0; i < variable.length; i++) {
  575. inject(variable[i], newvalue, aliases);
  576. }
  577. return;
  578. }
  579.  
  580. console.log("[i2d] injecting " + variable);
  581. if (!aliases)
  582. aliases = [];
  583.  
  584. var initobjects = "";
  585. var subvariable = variable;
  586. var subindex = 0;
  587. while (true) {
  588. var index = subvariable.indexOf(".");
  589. var breakme = false;
  590. if (index < 0) {
  591. index = subvariable.length;
  592. breakme = true;
  593. }
  594. subvariable = subvariable.substr(index + 1);
  595. subindex += index + 1;
  596. var subname = variable.substr(0, subindex - 1);
  597. initobjects += "if (!" + subname + ") {" + subname + " = {};}\n";
  598. if (breakme)
  599. break;
  600. }
  601.  
  602. add_script("var config = " + JSON.stringify(config) + ";\n" +
  603. i2d_show_url.toString() + "\n" + i2d_add_player.toString() + "\n" +
  604. initobjects + "\n" +
  605. "if ((window." + variable + " !== undefined) && !(window." + variable + ".INJECTED)) {\n" +
  606. "var oldvariable = window." + variable + ";\n" +
  607. "var oldvariable_keys = Object.keys(oldvariable);\n" +
  608. "window." + variable + " = " + newvalue.toString() + ";\n" +
  609. "for (var i = 0; i < oldvariable_keys.length; i++) {\n" +
  610. " window." + variable + "[oldvariable_keys[i]] = oldvariable[oldvariable_keys[i]];\n" +
  611. "}\n" +
  612. "window." + variable + ".INJECTED = true;\n" +
  613. "var aliases = " + JSON.stringify(aliases) + ";\n" +
  614. "for (var i = 0; i < aliases.length; i++) {\n" +
  615. " if (aliases[i] in window && window[aliases[i]] == oldvariable)" +
  616. " window[aliases[i]] = window." + variable + "\n" +
  617. "}\n" +
  618. "}");
  619. }
  620.  
  621. function jquery_plugin_exists(name) {
  622. if (!("jQuery" in window) ||
  623. typeof window.jQuery !== "function" ||
  624. !("fn" in window.jQuery) ||
  625. !(name in window.jQuery.fn))
  626. return false;
  627.  
  628.  
  629. return true;
  630. }
  631.  
  632. function inject_jquery_plugin(name, value) {
  633. if (!jquery_plugin_exists(name) ||
  634. window.jQuery.fn[name].INJECTED)
  635. return;
  636.  
  637. inject("jQuery.fn." + name, value);
  638. }
  639.  
  640. function inject_url(pattern, func) {
  641. // https://stackoverflow.com/questions/629671/how-can-i-intercept-xmlhttprequests-from-a-greasemonkey-script
  642. console.log("[i2d] injecting URL: " + pattern);
  643. (function(open) {
  644. window.XMLHttpRequest.prototype.open = function() {
  645. if (arguments[1] &&
  646. arguments[1].match(pattern)) {
  647. var url = arguments[1];
  648. this.addEventListener("readystatechange", function() {
  649. if (this.readyState === 4) {
  650. func.bind(this)(url);
  651. }
  652. });
  653. }
  654. open.apply(this, arguments);
  655. };
  656. })(window.XMLHttpRequest.prototype.open);
  657. }
  658.  
  659. function i2d_onload(f) {
  660. if (document.readyState === "loading") {
  661. document.addEventListener("DOMContentLoaded", f);
  662. } else {
  663. f();
  664. }
  665. }
  666.  
  667.  
  668. if (blacklisted)
  669. return;
  670.  
  671.  
  672. // Main code
  673. function i2d_main(e) {
  674. if (e) {
  675. if (!e.tagName || e.tagName.toLowerCase() !== "script")
  676. return;
  677. if ((e.className === "i2d")) {
  678. return;
  679. }
  680.  
  681. /*var ourscript = document.createElement("script");
  682. ourscript.className = "i2d";
  683. ourscript.innerHTML = "i2d_main();" + i2d_main;
  684. e.parentElement.insertBefore(ourscript, e.nextSibling);*/
  685.  
  686. var old_onload = e.onload;
  687. e.onload = function() {
  688. i2d_main();
  689. if (old_onload)
  690. return old_onload.apply(this, arguments);
  691. };
  692. }
  693.  
  694. if ("soundManager" in window && !window.soundManager.INJECTED) {
  695. inject("soundManager.createSound", function(arg1, arg2) {
  696. if (typeof arg1 === "string")
  697. i2d_show_url("soundManager", arg2);
  698. else
  699. i2d_show_url("soundManager", arg1.url);
  700.  
  701. return oldvariable.apply(this, arguments);
  702. });
  703. }
  704.  
  705. // TODO: Implement simple player
  706. if ("jwplayer" in window && !window.jwplayer.INJECTED) {
  707. inject("jwplayer", function() {
  708. var result = oldvariable.apply(this, arguments);
  709.  
  710. var check_sources = function(x) {
  711. if (typeof x === "object") {
  712. if (x instanceof Array) {
  713. for (var i = 0; i < x.length; i++) {
  714. check_sources(x[i]);
  715. }
  716. return;
  717. }
  718.  
  719. var label = "";
  720.  
  721. if ("title" in x)
  722. label += "[" + x.title + "]";
  723.  
  724. if ("label" in x)
  725. label += "[" + x.label + "]";
  726.  
  727. if ("kind" in x)
  728. label += "(" + x.kind + ")";
  729.  
  730. if ("streamer" in x) {
  731. i2d_show_url("jwplayer", x.streamer, "[stream]" + label);
  732. }
  733.  
  734. if ("file" in x) {
  735. i2d_show_url("jwplayer", x.file, label);
  736. }
  737.  
  738. if ("sources" in x) {
  739. check_sources(x.sources);
  740. }
  741.  
  742. if ("playlist" in x) {
  743. check_sources(x.playlist);
  744. }
  745.  
  746. if ("tracks" in x) {
  747. check_sources(x.tracks);
  748. }
  749. } else if (typeof x === "string") {
  750. i2d_show_url("jwplayer", x);
  751. }
  752. };
  753.  
  754. if ("setup" in result) {
  755. var old_jwplayer_setup = result.setup;
  756. result.setup = function() {
  757. if (typeof arguments[0] === "object") {
  758. var x = arguments[0];
  759.  
  760. if ("modes" in x) {
  761. for (var i = 0; i < x.modes.length; i++) {
  762. // TODO: support more?
  763. if ("type" in x.modes[i] && x.modes[i].type === "html5") {
  764. if ("config" in x.modes[i] && "file" in x.modes[i].config) {
  765. check_sources(x.modes[i].config);
  766. }
  767. }
  768. }
  769. }
  770.  
  771. check_sources(x);
  772. }
  773.  
  774. if (config.noads && "advertising" in arguments[0])
  775. delete arguments[0].advertising;
  776.  
  777. return old_jwplayer_setup.apply(this, arguments);
  778. };
  779. }
  780.  
  781. if ("load" in result) {
  782. var old_jwplayer_load = result.load;
  783. result.load = function() {
  784. check_sources(arguments[0]);
  785. return old_jwplayer_load.apply(this, arguments);
  786. };
  787. }
  788.  
  789. if ("on" in result) {
  790. result.on('playlistItem', function(item) {
  791. check_sources(item.item);
  792. });
  793.  
  794. var old_jwplayer_on = result.on;
  795. result.on = function() {
  796. if (arguments[0] === "adBlock")
  797. return;
  798.  
  799. return old_jwplayer_on.apply(this, arguments);
  800. };
  801. }
  802.  
  803. return result;
  804. });
  805. }
  806.  
  807. if ("flowplayer" in window && !window.flowplayer.INJECTED) {
  808. inject("flowplayer", function() {
  809. var obj_baseurl = null;
  810. var els = [];
  811.  
  812. var urls = [];
  813. var url_pairs = {};
  814. var players = {};
  815. var add_url = function() {
  816. if (Object.keys(players).length === 0) {
  817. urls.push(arguments[1]);
  818. } else {
  819. for (var key in players) {
  820. players[key].add_urls(arguments[1]);
  821. }
  822. }
  823.  
  824. return i2d_show_url.apply(this, arguments);
  825. };
  826. var add_url_pair = function(el) {
  827. var newargs = Array.prototype.slice.call(arguments, 1);
  828. if (!(el in players)) {
  829. if (!url_pairs[el])
  830. url_pairs[el] = [];
  831. url_pairs[el].push(newargs[1]);
  832. } else {
  833. players[el].add_urls(newargs[1]);
  834. }
  835.  
  836. return i2d_show_url.apply(this, newargs);
  837. };
  838.  
  839. function get_url(x) {
  840. x = decodeURIComponent(x);
  841.  
  842. if (obj_baseurl) {
  843. if (x.match(/^[a-z]*:\/\//)) {
  844. return x;
  845. } else {
  846. return obj_baseurl + "/" + x;
  847. }
  848. } else {
  849. return x;
  850. }
  851. }
  852.  
  853. function check_sources(x, els, label) {
  854. if (typeof x === "string") {
  855. if (!x.match(/\.xml$/))
  856. add_url("flowplayer", get_url(x), label);
  857.  
  858. return;
  859. }
  860.  
  861. if (x instanceof Array) {
  862. for (var i = 0; i < x.length; i++) {
  863. check_sources(x[i], els, label);
  864. }
  865. return;
  866. }
  867.  
  868. if (typeof x !== "object")
  869. return;
  870.  
  871. // test: https://flowplayer.com/docs/player/standalone/vast/overlay.html
  872. if (config.noads && "ima" in x)
  873. delete x.ima;
  874.  
  875. label = "";
  876.  
  877. if ("title" in x)
  878. label += "[" + x.title + "]";
  879.  
  880. if ("clip" in x) {
  881. if ("baseUrl" in x.clip) {
  882. obj_baseurl = x.clip.baseUrl;
  883.  
  884. for (var i = 0; i < els.length; i++) {
  885. els[i].i2d_baseurl = obj_baseurl;
  886. }
  887. }
  888.  
  889. check_sources(x.clip, els, label);
  890. }
  891.  
  892. if ("sources" in x) {
  893. check_sources(x.sources, els, label);
  894. }
  895.  
  896. if ("playlist" in x) {
  897. check_sources(x.playlist, els, label);
  898. }
  899.  
  900. if ("url" in x) {
  901. check_sources(x.url, els, label);
  902. }
  903.  
  904. if ("src" in x) {
  905. check_sources(x.src, els. label);
  906. }
  907.  
  908. if ("bitrates" in x) {
  909. for (var j = 0; j < x.bitrates.length; j++) {
  910. if ("url" in x.bitrates[j]) {
  911. var description = "";
  912. if (x.bitrates[j].isDefault)
  913. description += "default:";
  914. if (x.bitrates[j].sd)
  915. description += "sd:";
  916. if (x.bitrates[j].hd)
  917. description += "hd:";
  918. if (x.bitrates[j].bitrate)
  919. description += x.bitrates[j].bitrate;
  920.  
  921. add_url("flowplayer", get_url(x.bitrates[j].url), description);
  922. }
  923. }
  924. }
  925. }
  926.  
  927. if (arguments.length >= 1) {
  928. els = [null];
  929.  
  930. if (typeof arguments[0] === "string") {
  931. try {
  932. els[0] = document.getElementById(arguments[0]);
  933. } catch(e) {
  934. }
  935.  
  936. try {
  937. if (!els[0])
  938. els = document.querySelectorAll(arguments[0]);
  939. } catch(e) {
  940. els = [];
  941. }
  942. } else if (arguments[0] instanceof HTMLElement) {
  943. els = [arguments[0]];
  944. }
  945. }
  946.  
  947. for (var i = 0; i < els.length; i++) {
  948. if (!els[i] || !(els[i] instanceof HTMLElement))
  949. continue;
  950.  
  951. if ("i2d_baseurl" in els[i])
  952. obj_baseurl = els[i].i2d_baseurl;
  953. }
  954.  
  955. var options = {};
  956.  
  957. if (arguments.length >= 3 && typeof arguments[2] === "object") {
  958. check_sources(arguments[2], els);
  959. options = arguments[2];
  960. } else if (arguments.length >= 3 && typeof arguments[2] === "string") {
  961. add_url("flowplayer", get_url(arguments[2]));
  962. } else if (arguments.length === 2 && typeof arguments[1] === "object") {
  963. check_sources(arguments[1], els);
  964. options = arguments[1];
  965. } else if (arguments.length === 2 && typeof arguments[1] === "string") {
  966. add_url("flowplayer", get_url(arguments[1]));
  967. }
  968.  
  969. var isflash = false;
  970. if (arguments.length >= 2 && typeof arguments[1] === "string" && arguments[1].toLowerCase().match(/\.swf$/)) {
  971. isflash = true;
  972. }
  973.  
  974. for (var i = 0; i < els.length; i++) {
  975. if (!els[i] || !(els[i] instanceof HTMLElement))
  976. continue;
  977.  
  978. var href = els[i].getAttribute("href");
  979. if (href) {
  980. add_url_pair(els[i], "flowplayer", get_url(href), "href");
  981. }
  982. }
  983.  
  984. if (config.simpleplayers === "yes" ||
  985. (config.simpleplayers === "flash" && isflash)) {
  986. oldvariable = function() {
  987. var css = {width: "100%", height: "100%"};
  988. for (var key in options.screen) {
  989. var val = options.screen[key];
  990. switch(key) {
  991. case "height":
  992. case "width":
  993. case "bottom":
  994. case "top":
  995. case "left":
  996. case "right":
  997. if (typeof val === "number") {
  998. css[key] = val + "px";
  999. } else {
  1000. css[key] = val;
  1001. }
  1002. break;
  1003. default:
  1004. css[key] = val;
  1005. break;
  1006. }
  1007. }
  1008. for (var i = 0; i < els.length; i++) {
  1009. var player_urls = url_pairs[els[i]] || [];
  1010. for (var x = 0; x < urls.length; x++) {
  1011. player_urls.push(urls[x]);
  1012. }
  1013. players[els[i]] = i2d_add_player({
  1014. elements: els[i],
  1015. replaceChildren: true,
  1016. urls: player_urls,
  1017. css: css
  1018. });
  1019. }
  1020.  
  1021. var allp = function(name) {
  1022. for (var key in players) {
  1023. players[key][name].apply(this, Array.prototype.slice.apply(arguments, 1));
  1024. }
  1025. };
  1026.  
  1027. var res = {};
  1028. var fns = [
  1029. "addClip",
  1030. "setPlaylist",
  1031. "load",
  1032. "playlist",
  1033. "play",
  1034. "ipad"
  1035. ];
  1036. for (var i = 0; i < fns.length; i++) {
  1037. res[fns[i]] = function(){};
  1038. }
  1039.  
  1040. return res;
  1041. };
  1042. }
  1043.  
  1044. var result = oldvariable.apply(this, arguments);
  1045.  
  1046. if (!result || typeof result !== "object")
  1047. return result;
  1048.  
  1049. if ("addClip" in result) {
  1050. var old_fplayer_addclip = result.addClip;
  1051. result.addClip = function() {
  1052. if (arguments.length > 0)
  1053. check_sources(arguments[0], els);
  1054.  
  1055. return old_fplayer_addclip.apply(this, arguments);
  1056. };
  1057. }
  1058.  
  1059. if ("setPlaylist" in result) {
  1060. var old_fplayer_setplaylist = result.setPlaylist;
  1061. result.setPlaylist = function() {
  1062. if (arguments.length > 0)
  1063. check_sources(arguments[0], els);
  1064.  
  1065. return old_fplayer_setplaylist.apply(this, arguments);
  1066. };
  1067. }
  1068.  
  1069. if ("load" in result) {
  1070. var old_fplayer_load = result.load;
  1071. result.load = function() {
  1072. if (arguments.length > 0)
  1073. check_sources(arguments[0], els);
  1074.  
  1075. return old_fplayer_load.apply(this, arguments);
  1076. };
  1077. }
  1078.  
  1079. if ("play" in result) {
  1080. var old_fplayer_play = result.play;
  1081. result.play = function() {
  1082. if (arguments.length > 0)
  1083. check_sources(arguments[0], els);
  1084.  
  1085. return old_fplayer_play.apply(this, arguments);
  1086. };
  1087. }
  1088.  
  1089. /*if ("on" in result) {
  1090. result.on("load", function(e, api, video) {
  1091. console.log(e);
  1092. check_sources(video || api.video, els);
  1093. });
  1094. }*/
  1095.  
  1096. return result;
  1097. }, ["$f"]);
  1098.  
  1099. add_script(get_script_str(function() {
  1100. flowplayer(function(api, root) {
  1101. api.on("load", function(e, api, video) {
  1102. flowplayer().load(video || api.video);
  1103. });
  1104. });
  1105. }));
  1106. }
  1107.  
  1108. if ("videojs" in window && !window.videojs.INJECTED) {
  1109. inject("videojs", function() {
  1110. if (arguments.length > 0 && typeof arguments[0] === "string") {
  1111. var my_el = document.getElementById(arguments[0]);
  1112. if (!my_el)
  1113. my_el = document.querySelector(arguments[0]);
  1114.  
  1115. if (my_el) {
  1116. if (my_el.src) {
  1117. i2d_show_url("videojs", my_el.src);
  1118. }
  1119.  
  1120. for (var i = 0; i < my_el.children.length; i++) {
  1121. if (my_el.children[i].tagName.toLowerCase() === "source") {
  1122. if (my_el.children[i].src) {
  1123. i2d_show_url("videojs", my_el.children[i].src, my_el.children[i].getAttribute("label"));
  1124. }
  1125. }
  1126. }
  1127. }
  1128. }
  1129.  
  1130. var result = oldvariable.apply(this, arguments);
  1131.  
  1132. var old_videojs_src = result.src;
  1133. result.src = function() {
  1134. if (arguments.length > 0 && typeof arguments[0] === "object") {
  1135. if ("src" in arguments[0]) {
  1136. i2d_show_url("videojs", arguments[0].src);
  1137. }
  1138. }
  1139.  
  1140. return old_videojs_src.apply(this, arguments);
  1141. };
  1142.  
  1143. return result;
  1144. });
  1145.  
  1146. add_script(i2d_show_url.toString() +
  1147. i2d_onload.toString() +
  1148. get_script_str(function() {
  1149. i2d_onload(function() {
  1150. var els = document.getElementsByClassName("video-js");
  1151. for (var i = 0; i < els.length; i++) {
  1152. var my_el = els[i];
  1153. if (my_el.tagName.toLowerCase() === "video") {
  1154. if (!my_el.getAttribute('data-setup')) {
  1155. continue;
  1156. }
  1157. if (my_el.src) {
  1158. i2d_show_url("videojs", my_el.src);
  1159. }
  1160.  
  1161. for (var j = 0; j < my_el.children.length; j++) {
  1162. if (my_el.children[j].tagName.toLowerCase() === "source") {
  1163. if (my_el.children[j].src) {
  1164. i2d_show_url("videojs", my_el.children[j].src, my_el.children[j].getAttribute("label"));
  1165. }
  1166. }
  1167. }
  1168. }
  1169. }
  1170. });
  1171. }));
  1172. }
  1173.  
  1174. if ("amp" in window && !window.amp.INJECTED) {
  1175. inject("amp", function() {
  1176. function show_amp_source(sourceobj) {
  1177. if ("protectionInfo" in sourceobj) {
  1178. console.log("[amp] Cannot decode protection info");
  1179. }
  1180. if ("src" in sourceobj)
  1181. i2d_show_url("amp", sourceobj.src);
  1182. }
  1183.  
  1184. if (arguments.length >= 2 && typeof arguments[1] === "object") {
  1185. if ("sourceList" in arguments[1]) {
  1186. for (var i = 0; i < arguments[1].sourceList.length; i++) {
  1187. show_amp_source(arguments[1].sourceList[i]);
  1188. }
  1189. }
  1190. }
  1191.  
  1192. var result = oldvariable.apply(this, arguments);
  1193.  
  1194. if (!result)
  1195. return result;
  1196.  
  1197. var old_amp_src = result.src;
  1198. result.src = function() {
  1199. for (var i = 0; i < arguments[0].length; i++) {
  1200. show_amp_source(arguments[0][i]);
  1201. }
  1202.  
  1203. return old_amp_src.apply(this, arguments);
  1204. };
  1205.  
  1206. return result;
  1207. });
  1208. }
  1209.  
  1210. if ("DJPlayer" in window && !window.DJPlayer.INJECTED) {
  1211. add_script(i2d_show_url.toString() + "\n" +
  1212. "var oldsetmedia = window.DJPlayer.prototype.setMedia;\n" +
  1213. "window.DJPlayer.prototype.setMedia = function() {\n" +
  1214. " if (arguments.length > 0 && typeof arguments[0] === 'string') {\n" +
  1215. " i2d_show_url('DJPlayer', arguments[0]);\n" +
  1216. " }\n" +
  1217. " return oldsetmedia.apply(this, arguments);\n" +
  1218. "}");
  1219. }
  1220.  
  1221. if ("bitmovin" in window && !window.bitmovin.INJECTED) {
  1222. inject(["bitmovin.player", "bitdash", "bitmovinPlayer"], function() {
  1223. var result = oldvariable.apply(this, arguments);
  1224.  
  1225. var check_progressive = function(progressive) {
  1226. if (typeof progressive === "string") {
  1227. i2d_show_url("bitmovin", progressive, "progressive");
  1228. } else if (progressive instanceof Array) {
  1229. for (var i = 0; i < progressive.length; i++) {
  1230. check_progressive(progressive[i]);
  1231. }
  1232. } else if (typeof progressive === "object") {
  1233. var str = "";
  1234. if (progressive.label)
  1235. str += "[" + progressive.label + "] ";
  1236. if (progressive.bitrate)
  1237. str += progressive.bitrate;
  1238.  
  1239. i2d_show_url("bitmovin", progressive.url, str);
  1240. }
  1241. };
  1242.  
  1243. var check_sources = function(x) {
  1244. if (typeof x === "object") {
  1245. if ("source" in x) {
  1246. var sourceobj = x.source;
  1247.  
  1248. if (sourceobj.progressive) {
  1249. check_progressive(sourceobj.progressive);
  1250. }
  1251.  
  1252. if (sourceobj.dash) {
  1253. i2d_show_url("bitmovin", sourceobj.dash, "dash");
  1254. }
  1255.  
  1256. if (sourceobj.hls) {
  1257. i2d_show_url("bitmovin", sourceobj.hls, "hls");
  1258. }
  1259. }
  1260. }
  1261. };
  1262.  
  1263. if ("setup" in result) {
  1264. var old_bitmovin_setup = result.setup;
  1265. result.setup = function() {
  1266. check_sources(arguments[0]);
  1267.  
  1268. return old_bitmovin_setup.apply(this, arguments);
  1269. };
  1270. }
  1271.  
  1272. if ("load" in result) {
  1273. var old_bitmovin_load = result.load;
  1274. result.load = function() {
  1275. check_sources({source: arguments[0]});
  1276.  
  1277. return old_bitmovin_load.apply(this, arguments);
  1278. };
  1279. }
  1280.  
  1281. return result;
  1282. });
  1283. }
  1284.  
  1285. if ("dashjs" in window && window.dashjs.MediaPlayer && !window.dashjs.MediaPlayer.INJECTED) {
  1286. inject("dashjs.MediaPlayer", function() {
  1287. var outer_result = oldvariable.apply(this, arguments);
  1288.  
  1289. var oldcreate = outer_result.create;
  1290. outer_result.create = function() {
  1291. var result = oldcreate.apply(this, arguments);
  1292.  
  1293. var old_attachsource = result.attachSource;
  1294. result.attachSource = function(url) {
  1295. i2d_show_url("dash.js", url);
  1296. return old_attachsource.apply(this, arguments);
  1297. };
  1298.  
  1299. return result;
  1300. };
  1301.  
  1302. return outer_result;
  1303. });
  1304. }
  1305.  
  1306. if ("Hls" in window && window.Hls && !window.Hls.INJECTED) {
  1307. console.log("[i2d] injecting Hls");
  1308. var old_loadsource = window.Hls.prototype.loadSource;
  1309. window.Hls.prototype.loadSource = function(url) {
  1310. i2d_show_url("hls.js", url);
  1311. return old_loadsource.apply(this, arguments);
  1312. };
  1313. window.Hls.INJECTED = true;
  1314. }
  1315.  
  1316. if ("flvjs" in window && window.flvjs.createPlayer && !window.flvjs.createPlayer.INJECTED) {
  1317. inject("flvjs.createPlayer", function(options) {
  1318. if (options) {
  1319. if ("url" in options) {
  1320. i2d_show_url("flv.js", options.url);
  1321. }
  1322. }
  1323. return oldvariable.apply(this, arguments);
  1324. });
  1325. }
  1326.  
  1327. if ("KollusMediaContainer" in window && window.KollusMediaContainer && !window.KollusMediaContainer.INJECTED) {
  1328. inject("KollusMediaContainer.createInstance", function(options) {
  1329. if (options) {
  1330. if ("mediaurl" in options) {
  1331. var types = [];
  1332. if (options.isencrypted)
  1333. types.push("encrypted");
  1334. if (options.isaudiofiles)
  1335. types.push("audio");
  1336. else
  1337. types.push("video");
  1338. i2d_show_url("kollus", options.mediaurl, types.join(":"));
  1339. }
  1340. }
  1341.  
  1342. // Replace flash with HTML5, but it doesn't work for HLS
  1343. if (config.simpleplayers === "yes" ||
  1344. config.simpleplayers === "flash") {
  1345. var value = (new KollusMediaContainer(options));
  1346. var old_launchFlashPlayer = value.launchFlashPlayer;
  1347. value.launchFlashPlayer = function() {
  1348. if (options.isencrypted) {
  1349. return old_launchflashplayer.apply(this, arguments);
  1350. } else if (options.isaudiofile) {
  1351. return value.launchHTML5AudioPlayer();
  1352. } else {
  1353. return value.launchHTML5Player();
  1354. }
  1355. };
  1356. value.isURLHasM3U8 = function(){return false;};
  1357. value = value.initialize();
  1358.  
  1359. return value;
  1360. } else {
  1361. return oldvariable.apply(this, arguments);
  1362. }
  1363. });
  1364. }
  1365.  
  1366. if (("location" in window) && window.location && window.location.host.search("soundcloud.com") >= 0 && !("soundcloud" in injected_set)) {
  1367. injected_set["soundcloud"] = true;
  1368.  
  1369. inject_url(/api\.soundcloud\.com\/.*?\/tracks\/[0-9]*\/streams/, function(url) {
  1370. var track = url.match(/\/tracks\/([0-9]*)\//);
  1371. var parsed = JSON.parse(this.responseText);
  1372. for (var item in parsed) {
  1373. i2d_show_url("soundcloud", parsed[item], "[" + item + "] " + track[1]);
  1374. }
  1375. });
  1376. }
  1377.  
  1378. if (("location" in window) && window.location && window.location.host.search("forvo") >= 0 && "createAudioObject" in window && !window.createAudioObject.INJECTED) {
  1379. inject("createAudioObject", function(id, mp3, ogg) {
  1380. i2d_show_url("forvo", mp3, "mp3");
  1381. i2d_show_url("forvo", ogg, "ogg");
  1382.  
  1383. return oldvariable.apply(this, arguments);
  1384. });
  1385. }
  1386.  
  1387. if (("location" in window) && window.location && window.location.href.search("twitter.com/i/videos") >= 0 && !("twitter" in injected_set)) {
  1388. injected_set["twitter"] = true;
  1389.  
  1390. i2d_onload(function() {
  1391. var pc = document.getElementById('playerContainer');
  1392. if (!pc) {
  1393. return;
  1394. }
  1395.  
  1396. var config = pc.getAttribute('data-config');
  1397. if (!config) {
  1398. return;
  1399. }
  1400.  
  1401. var config_parsed = JSON.parse(config);
  1402.  
  1403. if ("video_url" in config_parsed) {
  1404. i2d_show_url('twitter', config_parsed.video_url);
  1405. }
  1406. });
  1407. }
  1408.  
  1409. if (("location" in window) && window.location && window.location.href.search("vine.co/v/") >= 0) {
  1410. var show_video_urls = function(videourls) {
  1411. for (var i = 0; i < videourls.length; i++) {
  1412. var videourl = videourls[i];
  1413.  
  1414. var formatstr = "[";
  1415. formatstr += videourl.format + ":";
  1416. formatstr += videourl.idStr;
  1417.  
  1418. if (videourl.rate > 0)
  1419. formatstr += ", " + videourl.rate;
  1420.  
  1421. formatstr += "]";
  1422.  
  1423. i2d_show_url('vine', videourl.videoUrl, formatstr);
  1424. }
  1425. };
  1426.  
  1427. if (window.location.href.search("/card" ) >= 0 && !("vine_card" in injected_set)) {
  1428. injected_set["vine_card"] = true;
  1429.  
  1430. i2d_onload(function() {
  1431. var config_el = document.getElementById("configuration");
  1432. if (!config_el) {
  1433. return;
  1434. }
  1435.  
  1436. var config = JSON.parse(config_el.innerHTML);
  1437. if (!config || typeof config !== "object") {
  1438. return;
  1439. }
  1440.  
  1441. if (!("post" in config) || !("videoUrls" in config.post)) {
  1442. return;
  1443. }
  1444.  
  1445. show_video_urls(config.post.videoUrls);
  1446. });
  1447. } else if (!("vine_video" in injected_set)) {
  1448. injected_set["vine_video"] = true;
  1449.  
  1450. i2d_onload(function() {
  1451. var scripts = document.getElementsByTagName("script");
  1452. if (scripts.length === 0)
  1453. return;
  1454.  
  1455. var thescript = null;
  1456. for (var i = 0; i < scripts.length; i++) {
  1457. if (scripts[i].innerHTML.search("window.POST_DATA") < 0) {
  1458. continue;
  1459. }
  1460.  
  1461. thescript = scripts[i];
  1462. break;
  1463. }
  1464.  
  1465. var config;
  1466. eval(thescript.innerHTML.replace("window.POST_DATA", "config"));
  1467.  
  1468. var videourls = config[Object.keys(config)[0]].videoUrls;
  1469. show_video_urls(videourls);
  1470. });
  1471. }
  1472. }
  1473.  
  1474. if ("jQuery" in window) {
  1475. inject_jquery_plugin("jPlayer", function() {
  1476. if (arguments.length > 0 && arguments[0] === "setMedia") {
  1477. if (arguments.length > 1) {
  1478. if (typeof arguments[1] === "object") {
  1479. for (var i in arguments[1]) {
  1480. if (i === "title" ||
  1481. i === "duration" ||
  1482. i === "track" /* for now */ ||
  1483. i === "artist" ||
  1484. i === "free")
  1485. continue;
  1486.  
  1487. i2d_show_url("jPlayer", arguments[1][i], i);
  1488. }
  1489. } else if (typeof arguments[1] === "string") {
  1490. i2d_show_url("jPlayer", arguments[1]);
  1491. }
  1492. }
  1493. }
  1494.  
  1495. return oldvariable.apply(this, arguments);
  1496. });
  1497.  
  1498. inject_jquery_plugin("amazingaudioplayer", function() {
  1499. var result = oldvariable.apply(this, arguments);
  1500.  
  1501. function add_source_obj(x) {
  1502. type = "";
  1503. if ("type" in x) {
  1504. type = x.type;
  1505. }
  1506.  
  1507. i2d_show_url("amazingaudioplayer", x.src, type);
  1508. }
  1509.  
  1510. function add_source(x) {
  1511. if (x instanceof Array) {
  1512. for (var i = 0; i < x.length; i++) {
  1513. add_source_obj(x[i]);
  1514. }
  1515. } else {
  1516. add_source_obj(x);
  1517. }
  1518. }
  1519.  
  1520. var audioplayer = jQuery(this).data("object").audioPlayer;
  1521. if (audioplayer.audioItem) {
  1522. add_source(audioplayer.audioItem.source);
  1523. }
  1524.  
  1525. var oldload = audioplayer.load;
  1526. audioplayer.load = function(item) {
  1527. if ("source" in item) {
  1528. add_source(item.source);
  1529. }
  1530.  
  1531. return oldload.apply(this, arguments);
  1532. };
  1533.  
  1534. return result;
  1535. });
  1536.  
  1537. if (jquery_plugin_exists("jPlayerAudio") && !window.jQuery.fn.jPlayerAudio.INJECTED) {
  1538. inject_jquery_plugin("jPlayerAudio", function() {
  1539. return oldvariable.apply(this, arguments);
  1540. });
  1541.  
  1542. add_script(i2d_show_url.toString() + "\n" +
  1543. "var oldmedia=jQuery.jPlayerAudio.prototype.setMedia;\n" +
  1544. "jQuery.jPlayerAudio.prototype.setMedia = function(e) {\n" +
  1545. " var absolute = this._absoluteMediaUrls(e);\n" +
  1546. " jQuery.each(this.formats, function(a, o) {\n" +
  1547. " i2d_show_url('cleanaudioplayer', absolute[o]);\n" +
  1548. " });\n" +
  1549. " return oldmedia.apply(this, arguments);\n" +
  1550. "}");
  1551. }
  1552.  
  1553. if (jquery_plugin_exists("jPlayerVideo") && !window.jQuery.fn.jPlayerVideo.INJECTED) {
  1554. inject_jquery_plugin("jPlayerVideo", function() {
  1555. return oldvariable.apply(this, arguments);
  1556. });
  1557.  
  1558. add_script(i2d_show_url.toString() + "\n" +
  1559. "var oldmedia=jQuery.jPlayerVideo.prototype.setMedia;\n" +
  1560. "jQuery.jPlayerVideo.prototype.setMedia = function(e) {\n" +
  1561. " var absolute = this._absoluteMediaUrls(e);\n" +
  1562. " jQuery.each(this.formats, function(a, o) {\n" +
  1563. " i2d_show_url('cleanvideoplayer', absolute[o]);\n" +
  1564. " });\n" +
  1565. " return oldmedia.apply(this, arguments);\n" +
  1566. "}");
  1567. }
  1568.  
  1569. inject_jquery_plugin("flowplayer", function() {
  1570. var newargs = Array.from(arguments);
  1571. newargs.unshift(jQuery(this)[0]);
  1572. return window.flowplayer.apply(this, newargs);
  1573. });
  1574. }
  1575. }
  1576.  
  1577. i2d_main();
  1578.  
  1579. window.addEventListener("afterscriptexecute", function(e) {
  1580. i2d_main(e.target);
  1581. });
  1582.  
  1583. var process_raw_tag = function(el) {
  1584. var basename = "raw ";
  1585.  
  1586. if (el.tagName.toLowerCase() === "video") {
  1587. basename += "video";
  1588. } else {
  1589. basename += "audio";
  1590. }
  1591.  
  1592. if (el.id)
  1593. basename += ": #" + el.id;
  1594.  
  1595. var show_updates = function() {
  1596. if (el.src)
  1597. i2d_show_url(basename, el.src);
  1598.  
  1599. for (var x = 0; x < el.children.length; x++) {
  1600. if (el.children[x].tagName.toLowerCase() !== "source" &&
  1601. el.children[x].tagName.toLowerCase() !== "track") {
  1602. continue;
  1603. }
  1604.  
  1605. var type = "";
  1606. if (el.children[x].type)
  1607. type += "[" + el.children[x].type + "]";
  1608.  
  1609. if (el.children[x].label)
  1610. type += "[" + el.children[x].label + "]";
  1611.  
  1612. if (el.children[x].srclang)
  1613. type += "[" + el.children[x].srclang + "]";
  1614.  
  1615. if (el.children[x].kind)
  1616. type += "(" + el.children[x].kind + ")";
  1617.  
  1618. if (el.children[x].src)
  1619. i2d_show_url(basename, el.children[x].src, type);
  1620. }
  1621. };
  1622.  
  1623. var observer = new MutationObserver(show_updates);
  1624. observer.observe(el, { attributes: true, childList: true });
  1625.  
  1626. show_updates();
  1627. };
  1628.  
  1629. var process_el = function(el) {
  1630. if (el.nodeName === "SCRIPT") {
  1631. i2d_main(el);
  1632. } else if (el.nodeName === "VIDEO" ||
  1633. el.nodeName === "AUDIO") {
  1634. process_raw_tag(el);
  1635. }
  1636.  
  1637. if (el.children) {
  1638. for (var i = 0; i < el.children.length; i++) {
  1639. process_el(el.children[i]);
  1640. }
  1641. }
  1642. };
  1643.  
  1644. var script_observer_cb = function(mutations, observer) {
  1645. for (var i = 0; i < mutations.length; i++) {
  1646. if (mutations[i].addedNodes) {
  1647. for (var x = 0; x < mutations[i].addedNodes.length; x++) {
  1648. var addednode = mutations[i].addedNodes[x];
  1649. process_el(addednode);
  1650. }
  1651. }
  1652. if (mutations[i].removedNodes) {
  1653. for (var x = 0; x < mutations[i].removedNodes.length; x++) {
  1654. if (mutations[i].removedNodes[x].nodeName === "SCRIPT")
  1655. i2d_main(mutations[i].removedNodes[x]);
  1656. }
  1657. }
  1658. }
  1659. };
  1660.  
  1661. var script_observer = new MutationObserver(script_observer_cb);
  1662.  
  1663. script_observer.observe(document, {childList: true, subtree: true});
  1664.  
  1665. i2d_onload(function() {
  1666. var get_raws = function() {
  1667. var audios = [].slice.call(document.getElementsByTagName("audio"));
  1668. var videos = [].slice.call(document.getElementsByTagName("video"));
  1669. var els = Array.prototype.concat(audios, videos);
  1670.  
  1671. for (var i = 0; i < els.length; i++) {
  1672. var basename = "raw ";
  1673. var el = els[i];
  1674.  
  1675. if (el.tagName.toLowerCase() === "video") {
  1676. basename += "video";
  1677. } else {
  1678. basename += "audio";
  1679. }
  1680.  
  1681. if (el.id)
  1682. basename += ": #" + el.id;
  1683.  
  1684. var show_updates = function() {
  1685. if (el.src)
  1686. i2d_show_url(basename, el.src);
  1687.  
  1688. for (var x = 0; x < el.children.length; x++) {
  1689. if (els[i].children[x].tagName.toLowerCase() !== "source" &&
  1690. els[i].children[x].tagName.toLowerCase() !== "track") {
  1691. continue;
  1692. }
  1693.  
  1694. var type = "";
  1695. if (el.children[x].type)
  1696. type += "[" + el.children[x].type + "]";
  1697.  
  1698. if (el.children[x].label)
  1699. type += "[" + el.children[x].label + "]";
  1700.  
  1701. if (el.children[x].srclang)
  1702. type += "[" + el.children[x].srclang + "]";
  1703.  
  1704. if (el.children[x].kind)
  1705. type += "(" + el.children[x].kind + ")";
  1706.  
  1707. if (el.children[x].src)
  1708. i2d_show_url(basename, el.children[x].src, type);
  1709. }
  1710. };
  1711.  
  1712. var observer = new MutationObserver(show_updates);
  1713. observer.observe(el, { attributes: true, childList: true });
  1714.  
  1715. show_updates();
  1716. }
  1717. };
  1718.  
  1719. //get_raws();
  1720.  
  1721. i2d_main();
  1722. });
  1723. })();