Inject2Download

Simple media download script

当前为 2018-06-28 提交的版本,查看 最新版本

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