Inject2Download

Simple media download script

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

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