Greasy Fork镜像 支持简体中文。

Inject2Download

Simple media download script

  1. // ==UserScript==
  2. // @name Inject2Download
  3. // @namespace http://lkubuntu.wordpress.com/
  4. // @version 0.4.8
  5. // @description Simple media download script
  6. // @author Anonymous Meerkat
  7. // @include *
  8. // @grant GM_getValue
  9. // @grant GM_setValue
  10. // @grant GM.getValue
  11. // @grant GM.setValue
  12. // @grant none
  13. // @license MIT License
  14. // @run-at document-start
  15. // ==/UserScript==
  16.  
  17. // NOTE: This script now requires GM_setValue/getValue for storing preferences
  18.  
  19. (function() {
  20. "use strict";
  21.  
  22. var injected_set = {};
  23. var did_prefs = false;
  24.  
  25. function get_window() {
  26. var win = window;
  27. if (typeof unsafeWindow !== "undefined")
  28. win = unsafeWindow;
  29. return win;
  30. }
  31.  
  32. var win = get_window();
  33.  
  34. // Most of these are disabled by default in order to avoid modifying the user experience in unexpected ways
  35. var config_template = {
  36. simpleplayers: {
  37. name: "Replace with native players if possible",
  38. options: {
  39. "yes": "Yes",
  40. "flash": "Only if Flash is used",
  41. "no": "No"
  42. },
  43. default: "no"
  44. },
  45. noads: {
  46. name: "Block ads if possible (using a proper adblocker is highly recommended)",
  47. default: false
  48. },
  49. // TODO: Implement
  50. /*download: {
  51. name: "Enable downloading via the player itself if possible",
  52. default: false
  53. },*/
  54. blacklist: {
  55. name: "Blacklisted domains (one per line)",
  56. type: "textarea",
  57. default: [
  58. "translate.google.com", // Spams audio files
  59. "live.com" // Conflicts with $f
  60. ].join("\n")
  61. }
  62. };
  63.  
  64. var config = {};
  65.  
  66. for (var key in config_template) {
  67. config[key] = config_template[key].default;
  68. /*(function(key) {
  69. GM.getValue(key).then(
  70. function (data) {
  71. if (data !== undefined)
  72. config[key] = data;
  73. },
  74. function () {}
  75. );
  76. })(key);*/
  77.  
  78.  
  79. // Having both work as callbacks is possible, but introduces delay
  80. // in cases where it's not necessary
  81. if (typeof GM_getValue !== "undefined") {
  82. var data = GM_getValue(key);
  83. if (data !== undefined)
  84. config[key] = data;
  85. } else if (typeof GM !== "undefined" && GM.getValue) {
  86. GM.getValue(key).then(function (data) {
  87. if (data !== undefined) {
  88. config[key] = data;
  89. }
  90. }, function() {});
  91. }
  92. }
  93.  
  94. function check_host(host) {
  95. var ourhost = window.location.hostname.toLowerCase();
  96. host = host.replace(/^ */, "").replace(/ *$/, "");
  97. if (ourhost === host.toLowerCase() ||
  98. (ourhost.indexOf("." + host) >= 0 &&
  99. ourhost.indexOf("." + host) === (ourhost.length - host.length - 1))) {
  100. return true;
  101. }
  102.  
  103. return false;
  104. }
  105.  
  106. function normalize_url(url) {
  107. if (!url)
  108. return url;
  109.  
  110. return url.replace(/^[a-z]+:\/\//, "//");
  111. }
  112.  
  113. function check_similar_url(url1, url2) {
  114. return normalize_url(url1) === normalize_url(url2);
  115. }
  116.  
  117. var blacklisted = false;
  118. var verified_blacklisted = false;
  119. function check_blacklisted() {
  120. var blacklist = config.blacklist.split("\n");
  121. blacklisted = false;
  122. var host = window.location.hostname.toLowerCase();
  123. for (var i = 0; i < blacklist.length; i++) {
  124. var normalized = blacklist[i].replace(/^ */, "").replace(/ *$/, "");
  125. if (host === normalized.toLowerCase() ||
  126. (host.indexOf("." + normalized) >= 0 &&
  127. host.indexOf("." + normalized) === (host.length - normalized.length - 1))) {
  128. console.log("[i2d] Blacklisted: " + normalized);
  129. blacklisted = true;
  130. break;
  131. }
  132. }
  133. return blacklisted;
  134. }
  135.  
  136. // Preferences
  137. if (window.location.hostname.toLowerCase() == "anonymousmeerkat.github.io" &&
  138. window.location.href.indexOf("anonymousmeerkat.github.io/inject2download/prefs.html") >= 0 &&
  139. !did_prefs) {
  140. run_on_load(function() {
  141. var text = [
  142. "<html><head><title>Inject2Download Preferences</title></head><body style='margin:0;padding:1em'>",
  143. "<div style='width:100%'><h2>Inject2Download</h2></div>",
  144. "<div id='prefs'></div>",
  145. "<div id='save'><button id='savebtn'>Save</button><br /><span id='savetxt'></span></div>",
  146. "</body></html>"
  147. ].join("");
  148. document.documentElement.innerHTML = text;
  149.  
  150. var prefs = document.getElementById("prefs");
  151. prefs.appendChild(document.createElement("hr"));
  152. for (var key in config_template) {
  153. var template = config_template[key];
  154.  
  155. var prefdiv = document.createElement("div");
  156. prefdiv.id = "pref-" + key;
  157. prefdiv.style.paddingBottom = "1em";
  158. var title = document.createElement("div");
  159. title.style.paddingBottom = ".5em";
  160. title.innerHTML = template.name;
  161. prefdiv.appendChild(title);
  162.  
  163. if (typeof template.default === "boolean" ||
  164. "options" in template) {
  165. var options = template.options;
  166. if (typeof template.default === "boolean") {
  167. options = {
  168. "true": "Yes",
  169. "false": "No"
  170. };
  171. }
  172.  
  173. for (var option in options) {
  174. var input = document.createElement("input");
  175. input.name = key;
  176. input.value = option;
  177. input.type = "radio";
  178. input.id = key + "-" + option;
  179.  
  180. if (config[key].toString() === option)
  181. input.setAttribute("checked", true);
  182.  
  183. var label = document.createElement("label");
  184. label.setAttribute("for", input.id);
  185. label.innerHTML = options[option];
  186.  
  187. prefdiv.appendChild(input);
  188. prefdiv.appendChild(label);
  189. prefdiv.appendChild(document.createElement("br"));
  190. }
  191. } else if (template.type === "textarea") {
  192. var input = document.createElement("textarea");
  193. input.name = key;
  194. input.style.width = "30em";
  195. input.style.height = "10em";
  196. input.innerHTML = config[key];
  197.  
  198. prefdiv.appendChild(input);
  199. } else {
  200. var input = document.createElement("input");
  201. input.name = key;
  202. input.value = config[key];
  203. input.style.width = "50em";
  204.  
  205. prefdiv.appendChild(input);
  206. }
  207.  
  208. prefs.appendChild(prefdiv);
  209. prefs.appendChild(document.createElement("hr"));
  210. }
  211.  
  212. document.getElementById("savebtn").onclick = function() {
  213. for (var key in config_template) {
  214. var els = document.getElementsByName(key);
  215. var value = undefined;
  216. if (els.length > 1) {
  217. // radio
  218. for (var i = 0; i < els.length; i++) {
  219. if (els[i].checked) {
  220. value = els[i].value;
  221. if (value === "true")
  222. value = true;
  223. if (value === "false")
  224. value = false;
  225. break;
  226. }
  227. }
  228. } else {
  229. if (els[0].tagName === "INPUT") {
  230. value = els[0].value;
  231. } else if (els[0].tagName === "TEXTAREA") {
  232. value = els[0].value;
  233. }
  234. }
  235. console.log("[i2d] " + key + " = " + value);
  236.  
  237. if (typeof GM_setValue !== "undefined")
  238. GM_setValue(key, value);
  239. else if (typeof GM !== "undefined" && GM.setValue)
  240. GM.setValue(key, value);
  241. }
  242. document.getElementById("savetxt").innerHTML = "Saved!";
  243. setTimeout(function() {
  244. document.getElementById("savetxt").innerHTML = "";
  245. }, 3000);
  246. };
  247.  
  248. console.log("[i2d] Finished rendering preferences page");
  249. });
  250. did_prefs = true;
  251. }
  252.  
  253. check_blacklisted();
  254.  
  255. // Helper functions
  256. function run_on_load(f) {
  257. if (document.readyState === "complete" ||
  258. document.readyState === "interactive") {
  259. f();
  260. } else {
  261. var listener = function() {
  262. if (document.readyState === "complete" ||
  263. document.readyState === "interactive") {
  264. f();
  265.  
  266. document.removeEventListener("readystatechange", listener);
  267. }
  268. };
  269.  
  270. document.addEventListener("readystatechange", listener);
  271. //document.addEventListener('DOMContentLoaded', f, false);
  272. //window.addEventListener('load', f, false);
  273. }
  274. }
  275.  
  276. var i2d_url_list = [];
  277. function i2d_show_url(namespace, url, description) {
  278. if (!blacklisted && !verified_blacklisted) {
  279. if (check_blacklisted()) {
  280. verified_blacklisted = true;
  281. }
  282. }
  283.  
  284. if (blacklisted)
  285. return;
  286.  
  287. function get_absolute_url(url) {
  288. var a = document.createElement('a');
  289. a.href = url;
  290. return a.href;
  291. }
  292.  
  293. function run_on_load(f) {
  294. if (document.readyState === "complete" ||
  295. document.readyState === "interactive") {
  296. f();
  297. } else {
  298. var listener = function() {
  299. if (document.readyState === "complete" ||
  300. document.readyState === "interactive") {
  301. f();
  302.  
  303. document.removeEventListener("readystatechange", listener);
  304. }
  305. };
  306.  
  307. document.addEventListener("readystatechange", listener);
  308. //document.addEventListener('DOMContentLoaded', f, false);
  309. //window.addEventListener('load', f, false);
  310. }
  311. }
  312.  
  313. if (!description)
  314. description = "";
  315.  
  316. if (typeof url !== "string" || url.replace("\s", "").length === 0)
  317. return;
  318.  
  319. if (url.match(/^mediasource:/) || url.match(/^blob:/) || url.match(/^data:/))
  320. return;
  321.  
  322. url = get_absolute_url(url);
  323.  
  324. for (var i = 0; i < i2d_url_list.length; i++) {
  325. if (i2d_url_list[i][0] === namespace &&
  326. i2d_url_list[i][1] === url &&
  327. i2d_url_list[i][2] === description)
  328. return;
  329. }
  330.  
  331.  
  332. i2d_url_list.push([namespace, url, description]);
  333.  
  334. var newurl = decodeURIComponent(url);
  335.  
  336. var text = "[" + namespace + "] " + description + ": ";
  337.  
  338. console.log("[i2d] " + text + newurl);
  339.  
  340. run_on_load(function() {
  341. var el = document.getElementById("i2d-popup");
  342. var elspan = document.getElementById("i2d-popup-x");
  343. var elspan1 = document.getElementById("i2d-popup-close");
  344. var elspan2 = document.getElementById("i2d-popup-prefs");
  345. var eldiv = document.getElementById("i2d-popup-div");
  346. var eldivhold = document.getElementById("i2d-popup-div-holder");
  347. if (!el) {
  348. el = document.createElement("div");
  349. el.style.all = "initial";
  350. //el.style.position = "absolute";
  351. el.style.width = "max(60%, 100em)";
  352. el.style.height = "max(60%, 100em)";
  353. el.style.maxWidth = "100%";
  354. el.style.maxHeight = "100%";
  355. el.style.height = "auto";
  356. el.style.width = "auto";
  357. el.style.background = "white";
  358. el.style.top = "0px";
  359. el.style.left = "0px";
  360. el.style.zIndex = Number.MAX_SAFE_INTEGER - 1;
  361. el.style.color = "black";
  362. el.style.fontFamily = "sans-serif";
  363. el.style.fontSize = "16px";
  364. el.style.lineHeight = "normal";
  365. el.style.textAlign = "left";
  366. el.style.overflow = "scroll";
  367. el.style.position = "absolute";
  368.  
  369. /*el.ondblclick = function() {
  370. el.parentElement.removeChild(el);
  371. };*/
  372. eldivhold = document.createElement("div");
  373. eldivhold.id = "i2d-popup-span-holder";
  374. eldivhold.style.all = "initial";
  375. eldivhold.style.width = "100%";
  376. eldivhold.style.display = "block";
  377. eldivhold.style.overflow = "auto";
  378. eldivhold.style.paddingBottom = ".5em";
  379.  
  380. elspan = document.createElement("span");
  381. elspan.style.all = "initial";
  382. elspan.style.fontSize = "130%";
  383. elspan.style.cursor = "pointer";
  384. elspan.style.color = "#900";
  385. elspan.style.padding = ".1em";
  386. elspan.style.float = "left";
  387. elspan.style.display = "inline";
  388. elspan.id = "i2d-popup-x";
  389. elspan.innerHTML = '[hide]';
  390. elspan.style.textDecoration = "underline";
  391. eldivhold.appendChild(elspan);
  392.  
  393. elspan1 = document.createElement("span");
  394. elspan1.style.all = "initial";
  395. elspan1.style.fontSize = "130%";
  396. elspan1.style.cursor = "pointer";
  397. elspan1.style.color = "#900";
  398. elspan1.style.padding = ".1em";
  399. elspan1.style.float = "right";
  400. //elspan1.style.display = "none";
  401. elspan1.style.display = "inline";
  402. elspan1.id = "i2d-popup-close";
  403. elspan1.innerHTML = '[close]';
  404. elspan1.style.textDecoration = "underline";
  405. eldivhold.appendChild(elspan1);
  406.  
  407. elspan2 = document.createElement("a");
  408. elspan2.style.all = "initial";
  409. elspan2.style.fontSize = "130%";
  410. elspan2.style.cursor = "pointer";
  411. elspan2.style.color = "#900";
  412. elspan2.style.padding = ".1em";
  413. elspan2.style.float = "left";
  414. //elspan1.style.display = "none";
  415. elspan2.style.display = "inline";
  416. elspan2.id = "i2d-popup-prefs";
  417. elspan2.innerHTML = '[options]';
  418. elspan2.href = "https://anonymousmeerkat.github.io/inject2download/prefs.html";
  419. elspan2.setAttribute("target", "_blank");
  420. elspan2.style.textDecoration = "underline";
  421. eldivhold.appendChild(elspan2);
  422.  
  423. //el.innerHTML = "<br style='line-height:150%' />";
  424. el.id = "i2d-popup";
  425. eldiv = document.createElement("div");
  426. eldiv.style.all = "initial";
  427. eldiv.id = "i2d-popup-div";
  428. //eldiv.style.display = "none";
  429. eldiv.style.display = "block";
  430. el.appendChild(eldiv);
  431. el.insertBefore(eldivhold, el.firstChild);
  432. document.documentElement.appendChild(el);
  433.  
  434. elspan.onclick = function() {
  435. /*var el = document.getElementById("i2d-popup");
  436. el.parentElement.removeChild(el);*/
  437. var eldiv = document.getElementById("i2d-popup-div");
  438. var elspan = document.getElementById("i2d-popup-x");
  439. if (eldiv.style.display === "none") {
  440. elspan.innerHTML = '[hide]';
  441. eldiv.style.display = "block";
  442. elspan1.style.display = "inline";
  443. } else {
  444. elspan.innerHTML = '[show]';
  445. eldiv.style.display = "none";
  446. elspan1.style.display = "none";
  447. }
  448. };
  449.  
  450. elspan1.onclick = function() {
  451. var el = document.getElementById("i2d-popup");
  452. el.parentElement.removeChild(el);
  453. };
  454. }
  455. var shorturl = newurl;
  456. if (shorturl.length > 100) {
  457. shorturl = shorturl.substring(0, 99) + "&hellip;";
  458. }
  459. var el_divspan = document.createElement("span");
  460. el_divspan.style.all = "initial";
  461. el_divspan.innerHTML = text;
  462. eldiv.appendChild(el_divspan);
  463. var el_a = document.createElement("a");
  464. el_a.href = newurl;
  465. el_a.style.all = "initial";
  466. el_a.style.color = "blue";
  467. el_a.style.textDecoration = "underline";
  468. el_a.style.cursor = "pointer";
  469. el_a.title = newurl;
  470. el_a.innerHTML = shorturl;
  471. eldiv.appendChild(el_a);
  472. var el_br = document.createElement("br");
  473. el_br.style.all = "initial";
  474. eldiv.appendChild(el_br);
  475. //eldiv.innerHTML += text + "<a href='" + newurl + "' style='color:blue' title='" + newurl + "'>" + shorturl + "</a><br />";
  476.  
  477. // XXX: why is this needed? test: http://playbb.me/embed.php?w=718&h=438&vid=at/nw/flying_witch_-_01.mp4, animeplus.tv
  478. /*document.body.removeChild(el);
  479. el.style.position = "absolute";
  480. document.body.appendChild(el);*/
  481.  
  482. /*if (document.getElementById("i2d-popup-x"))
  483. document.getElementById("i2d-popup-x").parentElement.removeChild(document.getElementById("i2d-popup-x"));*/
  484.  
  485. /*el.insertBefore(elspan, el.firstChild);
  486. el.insertBefore(elspan1, el.firstChild);*/
  487. //el.insertBefore(eldivhold, el.firstChild);
  488. });
  489. }
  490.  
  491. function i2d_add_player(options) {
  492. var playlist = [];
  493. var elements = [];
  494. var ret = {};
  495.  
  496. /*var videoel = document.createElement("video");
  497. videoel.setAttribute("controls", "");
  498. options.element.appendChild(videoel);*/
  499.  
  500. if (!(options.elements instanceof Array) && !(options.elements instanceof NodeList)) {
  501. if (typeof options.elements === "string") {
  502. options.elements = document.querySelectorAll(options.elements);
  503. } else {
  504. options.elements = [options.elements];
  505. }
  506. }
  507. for (var i = 0; i < options.elements.length; i++) {
  508. (function(x) {
  509. if (!x)
  510. return;
  511. var videoel = document.createElement("video");
  512. videoel.setAttribute("controls", "");
  513. videoel.style.maxWidth = "100%";
  514. videoel.style.maxHeight = "100%";
  515. videoel.addEventListener("ended", function() {
  516. ret.next_playlist_item();
  517. });
  518. videoel.addEventListener("error", function() {
  519. ret.next_playlist_item();
  520. });
  521. /*var stylestr = "";
  522. for (var key in options.css) {
  523. stylestr += key + ":" + options.css[key] + ";"
  524. }*/
  525. for (var key in options.css) {
  526. videoel.style[key] = options.css[key];
  527. }
  528. //videoel.setAttribute("style", stylestr);
  529. if (options.replaceChildren) {
  530. x.innerHTML = "";
  531. }
  532. if (options.replace) {
  533. x.parentElement.replaceChild(videoel, x);
  534. } else {
  535. x.appendChild(videoel);
  536. }
  537. elements.push(videoel);
  538. })(options.elements[i]);
  539. }
  540. ret.add_urls = function(urls) {
  541. if (urls instanceof Array) {
  542. for (var i = 0; i < urls.length; i++) {
  543. ret.add_urls(urls[i]);
  544. }
  545. return;
  546. }
  547.  
  548. playlist.push(urls);
  549. if (playlist.length === 1) {
  550. ret.set_url(playlist[0]);
  551. }
  552. };
  553. ret.replace_urls = function(urls) {
  554. playlist = [];
  555. return ret.add_urls(urls);
  556. };
  557. var getext = function(url) {
  558. if (!url)
  559. return url;
  560.  
  561. return url.replace(/.*\.([^/.?]*)(?:\?.*)?$/, "$1").toLowerCase();
  562. };
  563. var loadscript = function(variable, url, cb) {
  564. if (!(variable in window)) {
  565. var script = document.createElement("script");
  566. script.src = url;
  567. script.onload = cb;
  568. document.head.insertBefore(script, document.head.lastChild);
  569. } else {
  570. cb();
  571. }
  572. };
  573. ret.set_url = function(url) {
  574. if (!url || typeof url !== "string")
  575. return;
  576. switch(getext(url)) {
  577. case "flv":
  578. loadscript("flvjs", "https://cdn.jsdelivr.net/npm/flv.js@latest", function() {
  579. var flvPlayer = flvjs.createPlayer({
  580. type: 'flv',
  581. url: url
  582. });
  583. for (var i = 0; i < elements.length; i++) {
  584. flvPlayer.attachMediaElement(elements[i]);
  585. }
  586. flvPlayer.load();
  587. });
  588. break;
  589. case "m3u8":
  590. loadscript("Hls", "https://cdn.jsdelivr.net/npm/hls.js@latest", function() {
  591. var hls = new Hls();
  592. hls.loadSource(url);
  593. for (var i = 0; i < elements.length; i++) {
  594. hls.attachMedia(elements[i]);
  595. }
  596. });
  597. break;
  598. default:
  599. for (var i = 0; i < elements.length; i++) {
  600. elements[i].src = url;
  601. }
  602. break;
  603. }
  604. };
  605. ret.next_playlist_item = function() {
  606. playlist = playlist.slice(1);
  607. if (playlist[0])
  608. ret.set_url(playlist[0]);
  609. };
  610. ret.setPlaying = function(playing) {
  611. for (var i = 0; i < elements.length; i++) {
  612. if (playing)
  613. elements[i].play();
  614. else
  615. elements[i].pause();
  616. }
  617. };
  618.  
  619. if (options.urls)
  620. ret.add_urls(options.urls);
  621.  
  622. return ret;
  623. }
  624.  
  625.  
  626. // Injecting functions
  627. var get_script_str = function(f) {
  628. return f.toString().replace(/^function.*{|}$/g, '');
  629. };
  630.  
  631. function add_script(s, el) {
  632. var script_body = "(function() {\n" + s + "\n})();";
  633. var myscript = document.createElement('script');
  634. myscript.className = "i2d";
  635. myscript.innerHTML = script_body;
  636. if (el) {
  637. el.appendChild(myscript);
  638. } else {
  639. document.head.appendChild(myscript);
  640. }
  641. }
  642.  
  643. function inject(variable, newvalue, aliases) {
  644. if (variable instanceof Array) {
  645. for (var i = 0; i < variable.length; i++) {
  646. inject(variable[i], newvalue, aliases);
  647. }
  648. return;
  649. }
  650.  
  651. console.log("[i2d] injecting " + variable);
  652. if (!aliases)
  653. aliases = [];
  654.  
  655. var initobjects = "";
  656. var subvariable = variable;
  657. var subindex = 0;
  658. while (true) {
  659. var index = subvariable.indexOf(".");
  660. var breakme = false;
  661. if (index < 0) {
  662. index = subvariable.length;
  663. breakme = true;
  664. }
  665. subvariable = subvariable.substr(index + 1);
  666. subindex += index + 1;
  667. var subname = variable.substr(0, subindex - 1);
  668. initobjects += "if (!" + subname + ") {" + subname + " = {};}\n";
  669. if (breakme)
  670. break;
  671. }
  672.  
  673. add_script("var config = " + JSON.stringify(config) + ";\n" +
  674. i2d_show_url.toString() + "\n" + i2d_add_player.toString() + "\n" +
  675. initobjects + "\n" +
  676. "if ((window." + variable + " !== undefined) && !(window." + variable + ".INJECTED)) {\n" +
  677. "var oldvariable = window." + variable + ";\n" +
  678. "var oldvariable_keys = Object.keys(oldvariable);\n" +
  679. "window." + variable + " = " + newvalue.toString() + ";\n" +
  680. "for (var i = 0; i < oldvariable_keys.length; i++) {\n" +
  681. " window." + variable + "[oldvariable_keys[i]] = oldvariable[oldvariable_keys[i]];\n" +
  682. "}\n" +
  683. "window." + variable + ".INJECTED = true;\n" +
  684. "var aliases = " + JSON.stringify(aliases) + ";\n" +
  685. "for (var i = 0; i < aliases.length; i++) {\n" +
  686. " if (aliases[i] in window && window[aliases[i]] == oldvariable)" +
  687. " window[aliases[i]] = window." + variable + "\n" +
  688. "}\n" +
  689. "}");
  690. }
  691.  
  692. function jquery_plugin_exists(name) {
  693. if (!("jQuery" in window) ||
  694. typeof window.jQuery !== "function" ||
  695. !("fn" in window.jQuery) ||
  696. !(name in window.jQuery.fn))
  697. return false;
  698.  
  699.  
  700. return true;
  701. }
  702.  
  703. function inject_jquery_plugin(name, value) {
  704. if (!jquery_plugin_exists(name) ||
  705. window.jQuery.fn[name].INJECTED)
  706. return;
  707.  
  708. inject("jQuery.fn." + name, value);
  709. }
  710.  
  711. var injected_urls = [];
  712.  
  713. (function(open) {
  714. window.XMLHttpRequest.prototype.open = function() {
  715. if (arguments[1]) {
  716. var src = arguments[1];
  717.  
  718. var url = null;
  719. for (var i = 0; i < injected_urls.length; i++) {
  720. if (injected_urls[i].url &&
  721. check_similar_url(injected_urls[i].url, src)) {
  722. url = injected_urls[i];
  723. break;
  724. }
  725.  
  726. if (injected_urls[i].pattern &&
  727. src.match(injected_urls[i].pattern)) {
  728. url = injected_urls[i];
  729. break;
  730. }
  731. }
  732.  
  733. if (url) {
  734. this.addEventListener("readystatechange", function() {
  735. if (this.readyState === 4) {
  736. url.func.bind(this)(src);
  737. }
  738. });
  739. }
  740. }
  741.  
  742. open.apply(this, arguments);
  743. };
  744. })(window.XMLHttpRequest.prototype.open);
  745.  
  746. function inject_url(pattern, func) {
  747. var obj = {func: func};
  748.  
  749. if (pattern instanceof RegExp) {
  750. obj.pattern = pattern;
  751. } else {
  752. obj.url = pattern;
  753. }
  754.  
  755. for (var i = 0; i < injected_urls.length; i++) {
  756. if (injected_urls[i].url === obj.url ||
  757. injected_urls[i].pattern === obj.pattern)
  758. return;
  759. }
  760.  
  761. injected_urls.push(obj);
  762. }
  763.  
  764. function can_inject(name) {
  765. if (name in window && (typeof window[name] === "object" || typeof window[name] === "function") && !window[name].INJECTED)
  766. return true;
  767. return false;
  768. }
  769.  
  770. function i2d_onload(f) {
  771. if (document.readyState === "loading") {
  772. document.addEventListener("DOMContentLoaded", f);
  773. } else {
  774. f();
  775. }
  776. }
  777.  
  778.  
  779. if (blacklisted)
  780. return;
  781.  
  782. var injected = [];
  783. var defineProp = Object.defineProperty;
  784. win.Object.defineProperty = function() {
  785. if (arguments[0] === win &&
  786. injected.indexOf(arguments[1]) >= 0) {
  787. console.log("[i2d] Intercepted Object.defineProperty for " + arguments[1]);
  788.  
  789. if (arguments[2] && arguments[2].value)
  790. win[arguments[1]] = arguments[2].value;
  791.  
  792. return;
  793. }
  794.  
  795. return defineProp.apply(this, arguments);
  796. };
  797.  
  798. var defineProps = Object.defineProperties;
  799. win.Object.defineProperties = function() {
  800. if (arguments[0] === win) {
  801. var keys = Object.keys(arguments[1]);
  802.  
  803. var newargs = [];
  804. newargs[0] = arguments[0];
  805. newargs[1] = {};
  806.  
  807. for (var i = 0; i < keys.length; i++) {
  808. if (injected.indexOf(keys[i]) >= 0) {
  809. console.log("[i2d] Intercepted Object.defineProperties for " + keys[i]);
  810. if (arguments[1][keys[i]] && arguments[1][keys[i]].value) {
  811. win[keys[i]] = arguments[1][keys[i]].value;
  812. }
  813. } else {
  814. newargs[1][keys[i]] = arguments[1][keys[i]];
  815. }
  816. }
  817.  
  818. return defineProps.apply(this, newargs);
  819. }
  820.  
  821. return defineProps.apply(this, arguments);
  822. };
  823.  
  824. var injections = [
  825. // soundManager
  826. {
  827. variables: {
  828. window: "soundManager.createSound"
  829. },
  830. replace: function(context, args) {
  831. var arg1 = args[0];
  832. var arg2 = args[1];
  833.  
  834. if (typeof arg1 === "string")
  835. i2d_show_url("soundManager", arg2);
  836. else
  837. i2d_show_url("soundManager", arg1.url);
  838.  
  839. return context.oldvariable.apply(this, args);
  840. }
  841. },
  842. // jwplayer
  843. {
  844. variables: {
  845. window: "jwplayer"
  846. },
  847. replace: function(context, args) {
  848. var result = context.oldvariable.apply(this, args);
  849.  
  850. var check_sources = function(x, options) {
  851. if (!options)
  852. options = {};
  853.  
  854. if (typeof x === "object") {
  855. if (x instanceof Array) {
  856. for (var i = 0; i < x.length; i++) {
  857. check_sources(x[i]);
  858. }
  859. return;
  860. }
  861.  
  862. var label = "";
  863.  
  864. if ("title" in x)
  865. label += "[" + x.title + "]";
  866.  
  867. if ("label" in x)
  868. label += "[" + x.label + "]";
  869.  
  870. if ("kind" in x)
  871. label += "(" + x.kind + ")";
  872.  
  873. if ("streamer" in x) {
  874. i2d_show_url("jwplayer", x.streamer, "[stream]" + label);
  875. }
  876.  
  877. if ("file" in x) {
  878. i2d_show_url("jwplayer", x.file, label);
  879. }
  880.  
  881. if ("sources" in x) {
  882. check_sources(x.sources);
  883. }
  884.  
  885. if ("playlist" in x) {
  886. check_sources(x.playlist, {playlist: true});
  887. }
  888.  
  889. if ("tracks" in x) {
  890. check_sources(x.tracks, {playlist: true});
  891. }
  892. } else if (typeof x === "string") {
  893. i2d_show_url("jwplayer", x);
  894.  
  895. if (options.playlist) {
  896. inject_url(x, function() {
  897. check_sources(JSON.parse(this.responseText), {playlist: true});
  898. });
  899. }
  900. }
  901. };
  902.  
  903. if ("setup" in result) {
  904. var old_jwplayer_setup = result.setup;
  905. result.setup = function() {
  906. if (typeof arguments[0] === "object") {
  907. var x = arguments[0];
  908.  
  909. if ("modes" in x) {
  910. for (var i = 0; i < x.modes.length; i++) {
  911. // TODO: support more?
  912. if ("type" in x.modes[i] && x.modes[i].type === "html5") {
  913. if ("config" in x.modes[i] && "file" in x.modes[i].config) {
  914. check_sources(x.modes[i].config);
  915. }
  916. }
  917. }
  918. }
  919.  
  920. check_sources(x);
  921. }
  922.  
  923. if (config.noads && "advertising" in arguments[0])
  924. delete arguments[0].advertising;
  925.  
  926. return old_jwplayer_setup.apply(this, arguments);
  927. };
  928. }
  929.  
  930. if ("load" in result) {
  931. var old_jwplayer_load = result.load;
  932. result.load = function() {
  933. check_sources(arguments[0]);
  934. return old_jwplayer_load.apply(this, arguments);
  935. };
  936. }
  937.  
  938. if ("on" in result) {
  939. result.on('playlistItem', function(item) {
  940. check_sources(item.item);
  941. });
  942.  
  943. var old_jwplayer_on = result.on;
  944. result.on = function() {
  945. if (arguments[0] === "adBlock")
  946. return;
  947.  
  948. return old_jwplayer_on.apply(this, arguments);
  949. };
  950. }
  951.  
  952. return result;
  953. }
  954. },
  955. // flowplayer
  956. {
  957. variables: {
  958. window: ["flowplayer"],
  959. window_alias: ["$f"]
  960. },
  961. check: function(variable) {
  962. if (!variable || !variable.version)
  963. return false;
  964. return true;
  965. },
  966. replace: function(context, args) {
  967. var obj_baseurl = null;
  968. var els = [];
  969.  
  970. var urls = [];
  971. var url_pairs = {};
  972. var players = {};
  973. var add_url = function() {
  974. if (Object.keys(players).length === 0) {
  975. urls.push(arguments[1]);
  976. } else {
  977. for (var key in players) {
  978. players[key].add_urls(arguments[1]);
  979. }
  980. }
  981.  
  982. return i2d_show_url.apply(this, args);
  983. };
  984. var add_url_pair = function(el) {
  985. var newargs = Array.prototype.slice.call(arguments, 1);
  986. if (!(el in players)) {
  987. if (!url_pairs[el])
  988. url_pairs[el] = [];
  989. url_pairs[el].push(newargs[1]);
  990. } else {
  991. players[el].add_urls(newargs[1]);
  992. }
  993.  
  994. return i2d_show_url.apply(this, newargs);
  995. };
  996.  
  997. function get_url(x) {
  998. x = decodeURIComponent(x);
  999.  
  1000. if (obj_baseurl) {
  1001. if (x.match(/^[a-z]*:\/\//)) {
  1002. return x;
  1003. } else {
  1004. return obj_baseurl + "/" + x;
  1005. }
  1006. } else {
  1007. return x;
  1008. }
  1009. }
  1010.  
  1011. function check_sources(x, els, label) {
  1012. if (typeof x === "string") {
  1013. if (!x.match(/\.xml$/))
  1014. add_url("flowplayer", get_url(x), label);
  1015.  
  1016. return;
  1017. }
  1018.  
  1019. if (x instanceof Array) {
  1020. for (var i = 0; i < x.length; i++) {
  1021. check_sources(x[i], els, label);
  1022. }
  1023. return;
  1024. }
  1025.  
  1026. if (typeof x !== "object")
  1027. return;
  1028.  
  1029. // test: https://flowplayer.com/docs/player/standalone/vast/overlay.html
  1030. if (config.noads && "ima" in x)
  1031. delete x.ima;
  1032.  
  1033. label = "";
  1034.  
  1035. if ("title" in x)
  1036. label += "[" + x.title + "]";
  1037.  
  1038. if ("clip" in x) {
  1039. if ("baseUrl" in x.clip) {
  1040. obj_baseurl = x.clip.baseUrl;
  1041.  
  1042. for (var i = 0; i < els.length; i++) {
  1043. els[i].i2d_baseurl = obj_baseurl;
  1044. }
  1045. }
  1046.  
  1047. check_sources(x.clip, els, label);
  1048. }
  1049.  
  1050. if ("sources" in x) {
  1051. check_sources(x.sources, els, label);
  1052. }
  1053.  
  1054. if ("playlist" in x) {
  1055. check_sources(x.playlist, els, label);
  1056. }
  1057.  
  1058. if ("url" in x) {
  1059. check_sources(x.url, els, label);
  1060. }
  1061.  
  1062. if ("src" in x) {
  1063. check_sources(x.src, els. label);
  1064. }
  1065.  
  1066. if ("bitrates" in x) {
  1067. for (var j = 0; j < x.bitrates.length; j++) {
  1068. if ("url" in x.bitrates[j]) {
  1069. var description = "";
  1070. if (x.bitrates[j].isDefault)
  1071. description += "default:";
  1072. if (x.bitrates[j].sd)
  1073. description += "sd:";
  1074. if (x.bitrates[j].hd)
  1075. description += "hd:";
  1076. if (x.bitrates[j].bitrate)
  1077. description += x.bitrates[j].bitrate;
  1078.  
  1079. add_url("flowplayer", get_url(x.bitrates[j].url), description);
  1080. }
  1081. }
  1082. }
  1083. }
  1084.  
  1085. if (args.length >= 1) {
  1086. els = [null];
  1087.  
  1088. if (typeof args[0] === "string") {
  1089. try {
  1090. els[0] = document.getElementById(args[0]);
  1091. } catch(e) {
  1092. }
  1093.  
  1094. try {
  1095. if (!els[0])
  1096. els = document.querySelectorAll(args[0]);
  1097. } catch(e) {
  1098. els = [];
  1099. }
  1100. } else if (args[0] instanceof HTMLElement) {
  1101. els = [args[0]];
  1102. }
  1103. }
  1104.  
  1105. for (var i = 0; i < els.length; i++) {
  1106. if (!els[i] || !(els[i] instanceof HTMLElement))
  1107. continue;
  1108.  
  1109. if ("i2d_baseurl" in els[i])
  1110. obj_baseurl = els[i].i2d_baseurl;
  1111. }
  1112.  
  1113. var options = {};
  1114.  
  1115. if (args.length >= 3 && typeof args[2] === "object") {
  1116. check_sources(args[2], els);
  1117. options = args[2];
  1118. } else if (args.length >= 3 && typeof args[2] === "string") {
  1119. add_url("flowplayer", get_url(args[2]));
  1120. } else if (args.length === 2 && typeof args[1] === "object") {
  1121. check_sources(args[1], els);
  1122. options = args[1];
  1123. } else if (args.length === 2 && typeof args[1] === "string") {
  1124. add_url("flowplayer", get_url(args[1]));
  1125. }
  1126.  
  1127. var isflash = false;
  1128. if (args.length >= 2 && typeof args[1] === "string" && args[1].toLowerCase().match(/\.swf$/)) {
  1129. isflash = true;
  1130. }
  1131.  
  1132. for (var i = 0; i < els.length; i++) {
  1133. if (!els[i] || !(els[i] instanceof HTMLElement))
  1134. continue;
  1135.  
  1136. var href = els[i].getAttribute("href");
  1137. if (href) {
  1138. add_url_pair(els[i], "flowplayer", get_url(href), "href");
  1139. }
  1140. }
  1141.  
  1142. var oldvariable = context.oldvariable;
  1143. if (config.simpleplayers === "yes" ||
  1144. (config.simpleplayers === "flash" && isflash)) {
  1145. oldvariable = function() {
  1146. var css = {width: "100%", height: "100%"};
  1147. for (var key in options.screen) {
  1148. var val = options.screen[key];
  1149. switch(key) {
  1150. case "height":
  1151. case "width":
  1152. case "bottom":
  1153. case "top":
  1154. case "left":
  1155. case "right":
  1156. if (typeof val === "number") {
  1157. css[key] = val + "px";
  1158. } else {
  1159. css[key] = val;
  1160. }
  1161. break;
  1162. default:
  1163. css[key] = val;
  1164. break;
  1165. }
  1166. }
  1167. for (var i = 0; i < els.length; i++) {
  1168. var player_urls = url_pairs[els[i]] || [];
  1169. for (var x = 0; x < urls.length; x++) {
  1170. player_urls.push(urls[x]);
  1171. }
  1172. players[els[i]] = i2d_add_player({
  1173. elements: els[i],
  1174. replaceChildren: true,
  1175. urls: player_urls,
  1176. css: css
  1177. });
  1178. }
  1179.  
  1180. var allp = function(name) {
  1181. for (var key in players) {
  1182. players[key][name].apply(this, Array.prototype.slice.apply(args, 1));
  1183. }
  1184. };
  1185.  
  1186. var res = {};
  1187. var fns = [
  1188. "addClip",
  1189. "setPlaylist",
  1190. "load",
  1191. "playlist",
  1192. "play",
  1193. "ipad"
  1194. ];
  1195. for (var i = 0; i < fns.length; i++) {
  1196. res[fns[i]] = function(){};
  1197. }
  1198.  
  1199. return res;
  1200. };
  1201. }
  1202.  
  1203. var result = oldvariable.apply(this, args);
  1204.  
  1205. if (!result || typeof result !== "object")
  1206. return result;
  1207.  
  1208. if ("addClip" in result) {
  1209. var old_fplayer_addclip = result.addClip;
  1210. result.addClip = function() {
  1211. if (arguments.length > 0)
  1212. check_sources(arguments[0], els);
  1213.  
  1214. return old_fplayer_addclip.apply(this, arguments);
  1215. };
  1216. }
  1217.  
  1218. if ("setPlaylist" in result) {
  1219. var old_fplayer_setplaylist = result.setPlaylist;
  1220. result.setPlaylist = function() {
  1221. if (arguments.length > 0)
  1222. check_sources(arguments[0], els);
  1223.  
  1224. return old_fplayer_setplaylist.apply(this, arguments);
  1225. };
  1226. }
  1227.  
  1228. if ("load" in result) {
  1229. var old_fplayer_load = result.load;
  1230. result.load = function() {
  1231. if (arguments.length > 0)
  1232. check_sources(arguments[0], els);
  1233.  
  1234. return old_fplayer_load.apply(this, arguments);
  1235. };
  1236. }
  1237.  
  1238. if ("play" in result) {
  1239. var old_fplayer_play = result.play;
  1240. result.play = function() {
  1241. if (arguments.length > 0)
  1242. check_sources(arguments[0], els);
  1243.  
  1244. return old_fplayer_play.apply(this, arguments);
  1245. };
  1246. }
  1247.  
  1248. /*if ("on" in result) {
  1249. result.on("load", function(e, api, video) {
  1250. console.log(e);
  1251. check_sources(video || api.video, els);
  1252. });
  1253. }*/
  1254.  
  1255. return result;
  1256. },
  1257. after_inject: function(context) {
  1258. context.win.flowplayer(function(api, root) {
  1259. api.on("load", function(e, api, video) {
  1260. context.win.flowplayer().load(video || api.video);
  1261. });
  1262. });
  1263. }
  1264. },
  1265. // flowplayer (jQuery)
  1266. {
  1267. variables: {
  1268. jquery: "flowplayer"
  1269. },
  1270. replace: function(context, args) {
  1271. var newargs = Array.from(args);
  1272. newargs.unshift(jQuery(this)[0]);
  1273. return context.win.flowplayer.apply(this, newargs);
  1274. }
  1275. },
  1276. // video.js
  1277. {
  1278. variables: {
  1279. window: "videojs"
  1280. },
  1281. replace: function(context, args) {
  1282. if (args.length > 0 && typeof args[0] === "string") {
  1283. var my_el = document.getElementById(args[0]);
  1284. if (!my_el)
  1285. my_el = document.querySelector(args[0]);
  1286.  
  1287. if (my_el) {
  1288. if (my_el.src) {
  1289. i2d_show_url("videojs", my_el.src);
  1290. }
  1291.  
  1292. for (var i = 0; i < my_el.children.length; i++) {
  1293. if (my_el.children[i].tagName.toLowerCase() === "source") {
  1294. if (my_el.children[i].src) {
  1295. i2d_show_url("videojs", my_el.children[i].src, my_el.children[i].getAttribute("label"));
  1296. }
  1297. }
  1298. }
  1299. }
  1300. }
  1301.  
  1302. var parse_obj = function(obj) {
  1303. if (obj instanceof Array) {
  1304. for (var i = 0; i < obj.length; i++) {
  1305. parse_obj(obj[i]);
  1306. }
  1307. } else if (typeof obj === "string") {
  1308. // TODO
  1309. } else if (typeof obj === "object") {
  1310. if ("src" in obj) {
  1311. var type;
  1312. if ("type" in obj) {
  1313. type = obj.type;
  1314. }
  1315.  
  1316. i2d_show_url("videojs", obj.src, type);
  1317. }
  1318.  
  1319. if ("sources" in obj) {
  1320. parse_obj(obj.sources);
  1321. }
  1322. }
  1323. };
  1324.  
  1325. var result = context.oldvariable.apply(this, args);
  1326.  
  1327. var old_videojs_src = result.src;
  1328. result.src = function() {
  1329. if (arguments.length > 0 && typeof arguments[0] === "object") {
  1330. /*if ("src" in arguments[0]) {
  1331. i2d_show_url("videojs", arguments[0].src);
  1332. }*/
  1333. parse_obj(arguments[0]);
  1334. }
  1335.  
  1336. return old_videojs_src.apply(this, arguments);
  1337. };
  1338.  
  1339. var old_videojs_playlist = result.playlist;
  1340. result.playlist = function() {
  1341. if (arguments.length > 0) {
  1342. parse_obj(arguments[0]);
  1343. }
  1344.  
  1345. return old_videojs_playlist.apply(this, arguments);
  1346. }
  1347.  
  1348. return result;
  1349. }
  1350. },
  1351. // amp
  1352. {
  1353. variables: {
  1354. window: "amp"
  1355. },
  1356. replace: function(context, args) {
  1357. function show_amp_source(sourceobj) {
  1358. if ("protectionInfo" in sourceobj) {
  1359. console.log("[amp] Cannot decode protection info");
  1360. }
  1361. if ("src" in sourceobj)
  1362. i2d_show_url("amp", sourceobj.src);
  1363. }
  1364.  
  1365. if (args.length >= 2 && typeof args[1] === "object") {
  1366. if ("sourceList" in args[1]) {
  1367. for (var i = 0; i < args[1].sourceList.length; i++) {
  1368. show_amp_source(args[1].sourceList[i]);
  1369. }
  1370. }
  1371. }
  1372.  
  1373. var result = context.oldvariable.apply(this, args);
  1374.  
  1375. if (!result)
  1376. return result;
  1377.  
  1378. var old_amp_src = result.src;
  1379. result.src = function() {
  1380. for (var i = 0; i < args[0].length; i++) {
  1381. show_amp_source(args[0][i]);
  1382. }
  1383.  
  1384. return old_amp_src.apply(this, args);
  1385. };
  1386.  
  1387. return result;
  1388. }
  1389. },
  1390. // DJPlayer
  1391. {
  1392. variables: {
  1393. window: "DJPlayer"
  1394. },
  1395. proto: {
  1396. setMedia: function(context, args) {
  1397. if (args.length > 0 && typeof args[0] === 'string') {
  1398. i2d_show_url('DJPlayer', args[0]);
  1399. }
  1400.  
  1401. return context.oldvariable.apply(this, args);
  1402. }
  1403. }
  1404. },
  1405. // Bitmovin
  1406. {
  1407. variables: {
  1408. window: ["bitmovin.player", "bitdash", "bitmovinPlayer"]
  1409. },
  1410. replace: function(context, args) {
  1411. var result = context.oldvariable.apply(this, args);
  1412.  
  1413. var check_progressive = function(progressive) {
  1414. if (typeof progressive === "string") {
  1415. i2d_show_url("bitmovin", progressive, "progressive");
  1416. } else if (progressive instanceof Array) {
  1417. for (var i = 0; i < progressive.length; i++) {
  1418. check_progressive(progressive[i]);
  1419. }
  1420. } else if (typeof progressive === "object") {
  1421. var str = "";
  1422. if (progressive.label)
  1423. str += "[" + progressive.label + "] ";
  1424. if (progressive.bitrate)
  1425. str += progressive.bitrate;
  1426.  
  1427. i2d_show_url("bitmovin", progressive.url, str);
  1428. }
  1429. };
  1430.  
  1431. var check_sources = function(x) {
  1432. if (typeof x === "object") {
  1433. if ("source" in x) {
  1434. var sourceobj = x.source;
  1435.  
  1436. if (sourceobj.progressive) {
  1437. check_progressive(sourceobj.progressive);
  1438. }
  1439.  
  1440. if (sourceobj.dash) {
  1441. i2d_show_url("bitmovin", sourceobj.dash, "dash");
  1442. }
  1443.  
  1444. if (sourceobj.hls) {
  1445. i2d_show_url("bitmovin", sourceobj.hls, "hls");
  1446. }
  1447. }
  1448. }
  1449. };
  1450.  
  1451. if ("setup" in result) {
  1452. var old_bitmovin_setup = result.setup;
  1453. result.setup = function() {
  1454. check_sources(arguments[0]);
  1455.  
  1456. return old_bitmovin_setup.apply(this, arguments);
  1457. };
  1458. }
  1459.  
  1460. if ("load" in result) {
  1461. var old_bitmovin_load = result.load;
  1462. result.load = function() {
  1463. check_sources({source: arguments[0]});
  1464.  
  1465. return old_bitmovin_load.apply(this, arguments);
  1466. };
  1467. }
  1468.  
  1469. return result;
  1470. }
  1471. },
  1472. // createjs.Sound
  1473. {
  1474. variables: {
  1475. window: "createjs.Sound.registerSound"
  1476. },
  1477. replace: function(context, args) {
  1478. var url = null;
  1479. var name = null;
  1480. if (typeof args[0] === "string")
  1481. url = args[0];
  1482. else {
  1483. url = args[0].src;
  1484. if (args[0].id)
  1485. name = args[0].id;
  1486. }
  1487.  
  1488. if (args[1] && typeof args[1] === "string")
  1489. name = args[1];
  1490.  
  1491. i2d_show_url("createjs", url, name);
  1492.  
  1493. return context.oldvariable.apply(this, args);
  1494. }
  1495. },
  1496. // createjs.Sound (via queue)
  1497. {
  1498. variables: {
  1499. window: "createjs.LoadQueue"
  1500. },
  1501. common: {
  1502. checkArgs: function(args) {
  1503. var url = null;
  1504. var name = null;
  1505. var type = null;
  1506.  
  1507. if (typeof args[0] === "string")
  1508. url = args[0];
  1509. else {
  1510. url = args[0].src;
  1511. if (args[0].id)
  1512. name = args[0].id;
  1513. type = args[0].type;
  1514. }
  1515.  
  1516. if (args[1] && typeof args[1] === "string")
  1517. name = args[1];
  1518.  
  1519. if (!type) {
  1520. var ext = url.replace(/.*\.([a-z0-9]+)(?:[?#&].*)?$/, "$1");
  1521. if (!ext ||
  1522. // https://github.com/CreateJS/PreloadJS/blob/fd0f5790a4940892fa19972d6214be36f58eec85/src/preloadjs/utils/RequestUtils.js#L100
  1523. (ext !== "ogg" &&
  1524. ext !== "mp3" &&
  1525. ext !== "webm")) {
  1526. type = null;
  1527. } else {
  1528. type = "sound";
  1529. }
  1530. }
  1531.  
  1532. if (type === "sound")
  1533. i2d_show_url("createjs", url, name);
  1534. }
  1535. },
  1536. proto: {
  1537. loadFile: function(context, args) {
  1538. context.common.checkArgs(args);
  1539. return context.oldvariable.apply(this, args);
  1540. },
  1541. loadManifest: function(context, args) {
  1542. if (args[0] instanceof Array) {
  1543. for (var i = 0; i < args[0].length; i++) {
  1544. context.common.checkArgs([args[0][i]]);
  1545. }
  1546. } else {
  1547. context.common.checkArgs(args);
  1548. }
  1549.  
  1550. return context.oldvariable.apply(this, args);
  1551. }
  1552. }
  1553. },
  1554. // DASH.js
  1555. {
  1556. variables: {
  1557. window: "dashjs.MediaPlayer"
  1558. },
  1559. replace: function(context, args) {
  1560. var outer_result = context.oldvariable.apply(this, args);
  1561.  
  1562. var oldcreate = outer_result.create;
  1563. outer_result.create = function() {
  1564. var result = oldcreate.apply(this, arguments);
  1565.  
  1566. var old_attachsource = result.attachSource;
  1567. result.attachSource = function(url) {
  1568. i2d_show_url("dash.js", url);
  1569. return old_attachsource.apply(this, arguments);
  1570. };
  1571.  
  1572. return result;
  1573. };
  1574.  
  1575. return outer_result;
  1576. }
  1577. },
  1578. // hls.js
  1579. {
  1580. variables: {
  1581. window: "Hls"
  1582. },
  1583. proto: {
  1584. loadSource: function(context, args) {
  1585. var url = args[0];
  1586. i2d_show_url("hls.js", url);
  1587. return context.oldvariable.apply(this, args);
  1588. }
  1589. }
  1590. },
  1591. // flv.js
  1592. {
  1593. variables: {
  1594. window: "flvjs.createPlayer"
  1595. },
  1596. replace: function(context, args) {
  1597. var options = args[0];
  1598. if (options) {
  1599. if ("url" in options) {
  1600. i2d_show_url("flv.js", options.url);
  1601. }
  1602. }
  1603. return context.oldvariable.apply(this, args);
  1604. }
  1605. },
  1606. // Kollus
  1607. {
  1608. variables: {
  1609. window: "KollusMediaContainer.createInstance"
  1610. },
  1611. replace: function(context, args) {
  1612. var options = args[0];
  1613.  
  1614. if (options) {
  1615. if ("mediaurl" in options) {
  1616. var types = [];
  1617. if (options.isencrypted)
  1618. types.push("encrypted");
  1619. if (options.isaudiofiles)
  1620. types.push("audio");
  1621. else
  1622. types.push("video");
  1623. i2d_show_url("kollus", options.mediaurl, types.join(":"));
  1624. }
  1625. }
  1626.  
  1627. // Replace flash with HTML5, but it doesn't work for HLS
  1628. if (config.simpleplayers === "yes" ||
  1629. config.simpleplayers === "flash") {
  1630. var value = (new KollusMediaContainer(options));
  1631. var old_launchFlashPlayer = value.launchFlashPlayer;
  1632. value.launchFlashPlayer = function() {
  1633. if (options.isencrypted) {
  1634. return old_launchflashplayer.apply(this, arguments);
  1635. } else if (options.isaudiofile) {
  1636. return value.launchHTML5AudioPlayer();
  1637. } else {
  1638. return value.launchHTML5Player();
  1639. }
  1640. };
  1641. value.isURLHasM3U8 = function(){return false;};
  1642. value = value.initialize();
  1643.  
  1644. return value;
  1645. } else {
  1646. return context.oldvariable.apply(this, args);
  1647. }
  1648. }
  1649. },
  1650. // Soundcloud
  1651. {
  1652. run_when: [{
  1653. host: "soundcloud.com"
  1654. }],
  1655. urls: [
  1656. {
  1657. regex: /api\.soundcloud\.com\/.*?\/tracks\/[0-9]*\/streams/,
  1658. callback: function(url) {
  1659. var track = url.match(/\/tracks\/([0-9]*)\//);
  1660. var parsed = JSON.parse(this.responseText);
  1661. for (var item in parsed) {
  1662. i2d_show_url("soundcloud", parsed[item], "[" + item + "] " + track[1]);
  1663. }
  1664. }
  1665. }
  1666. ]
  1667. },
  1668. // Mixcloud
  1669. {
  1670. run_when: [{
  1671. host: "mixcloud.com"
  1672. }],
  1673. urls: [
  1674. {
  1675. regex: /^(?:https?:\/\/www\.mixcloud\.com)?\/graphql(?:\?.*)?$/,
  1676. callback: function(url) {
  1677. var mixcloud_key = atob("SUZZT1VXQU5UVEhFQVJUSVNUU1RPR0VUUEFJRERPTk9URE9XTkxPQURGUk9NTUlYQ0xPVUQ=");
  1678. var key_length = mixcloud_key.length;
  1679.  
  1680. try {
  1681. var parsed = this.response;
  1682. var viewer = parsed.data.viewer;
  1683. if (!viewer)
  1684. viewer = parsed.data.changePlayerQueue.viewer;
  1685. var queue = viewer.playerQueue;
  1686.  
  1687. var cloudcast;
  1688. if (queue.queue) {
  1689. var currentIndex = 0;
  1690. if (queue.currentIndex)
  1691. currentIndex = queue.currentIndex;
  1692. cloudcast = queue.queue[currentIndex].cloudcast;
  1693. }
  1694.  
  1695. var info = cloudcast.streamInfo;
  1696. for (var key in info) {
  1697. var value = atob(info[key]);
  1698. var newval = [];
  1699. for (var i = 0; i < value.length; i++) {
  1700. newval[i] = value.charCodeAt(i) ^ mixcloud_key.charCodeAt(i % mixcloud_key.length);
  1701. }
  1702. var newvalue = String.fromCharCode.apply(String, newval);
  1703. if (newvalue.match(/^https?:\/\//)) {
  1704. i2d_show_url("mixcloud", newvalue, "[" + key + "] " + cloudcast.slug);
  1705. }
  1706. }
  1707. } catch (e) {
  1708. }
  1709. }
  1710. }
  1711. ]
  1712. },
  1713. // Forvo
  1714. {
  1715. run_when: [{
  1716. host: "forvo.com"
  1717. }],
  1718. variables: {
  1719. window: "createAudioObject"
  1720. },
  1721. replace: function(context, args) {
  1722. var id = args[0];
  1723. var mp3 = args[1];
  1724. var ogg = args[2];
  1725.  
  1726. i2d_show_url("forvo", mp3, "mp3");
  1727. i2d_show_url("forvo", ogg, "ogg");
  1728.  
  1729. return context.oldvariable.apply(this, args);
  1730. }
  1731. },
  1732. // Twitter
  1733. {
  1734. run_when: [{
  1735. host: "twitter.com",
  1736. url_regex: /:\/\/[^/]*\/i\/videos/
  1737. }],
  1738. onload: function() {
  1739. var pc = document.getElementById('playerContainer');
  1740. if (!pc) {
  1741. return;
  1742. }
  1743.  
  1744. var config = pc.getAttribute('data-config');
  1745. if (!config) {
  1746. return;
  1747. }
  1748.  
  1749. var config_parsed = JSON.parse(config);
  1750.  
  1751. if ("video_url" in config_parsed) {
  1752. i2d_show_url('twitter', config_parsed.video_url);
  1753. }
  1754. }
  1755. },
  1756. // TODO: Reimplement vine
  1757.  
  1758. // jPlayer
  1759. {
  1760. variables: {
  1761. jquery: "jPlayer"
  1762. },
  1763. replace: function(context, args) {
  1764. if (args.length > 0 && args[0] === "setMedia") {
  1765. if (args.length > 1) {
  1766. if (typeof args[1] === "object") {
  1767. for (var i in args[1]) {
  1768. if (i === "title" ||
  1769. i === "duration" ||
  1770. i === "track" /* for now */ ||
  1771. i === "artist" ||
  1772. i === "free")
  1773. continue;
  1774.  
  1775. i2d_show_url("jPlayer", args[1][i], i);
  1776. }
  1777. } else if (typeof args[1] === "string") {
  1778. i2d_show_url("jPlayer", args[1]);
  1779. }
  1780. }
  1781. }
  1782.  
  1783. return context.oldvariable.apply(this, args);
  1784. }
  1785. },
  1786. // amazingaudioplayer
  1787. {
  1788. variables: {
  1789. jquery: "amazingaudioplayer"
  1790. },
  1791. replace: function(context, args) {
  1792. var result = context.oldvariable.apply(this, args);
  1793.  
  1794. function add_source_obj(x) {
  1795. type = "";
  1796. if ("type" in x) {
  1797. type = x.type;
  1798. }
  1799.  
  1800. i2d_show_url("amazingaudioplayer", x.src, type);
  1801. }
  1802.  
  1803. function add_source(x) {
  1804. if (x instanceof Array) {
  1805. for (var i = 0; i < x.length; i++) {
  1806. add_source_obj(x[i]);
  1807. }
  1808. } else {
  1809. add_source_obj(x);
  1810. }
  1811. }
  1812.  
  1813. var audioplayer = jQuery(this).data("object").audioPlayer;
  1814. if (audioplayer.audioItem) {
  1815. add_source(audioplayer.audioItem.source);
  1816. }
  1817.  
  1818. var oldload = audioplayer.load;
  1819. audioplayer.load = function(item) {
  1820. if ("source" in item) {
  1821. add_source(item.source);
  1822. }
  1823.  
  1824. return oldload.apply(this, arguments);
  1825. };
  1826.  
  1827. return result;
  1828. }
  1829. },
  1830. // jPlayer{Audio,Video}
  1831. {
  1832. variables: {
  1833. jquery: ["jPlayerAudio", "jPlayerVideo"]
  1834. },
  1835. proto: {
  1836. setMedia: function(context, args) {
  1837. var e = args[0];
  1838. var label = "cleanaudioplayer";
  1839. if (oldvariablename === "jPlayerVideo")
  1840. label = "cleanvideoplayer";
  1841.  
  1842. var absolute = this._absoluteMediaUrls(e);
  1843. jQuery.each(this.formats, function(a, o) {
  1844. i2d_show_url(label, absolute[o]);
  1845. });
  1846. return context.oldvariable.apply(this, args);
  1847. }
  1848. }
  1849. }
  1850. ];
  1851.  
  1852. var props = {};
  1853.  
  1854. function defineprop(lastobj_win, lastobj_props, oursplit) {
  1855. // TODO: Implement window_alias
  1856. if (!lastobj_win || !lastobj_props) {
  1857. console.log("lastobj_win === null || lastobj_props === null");
  1858. return;
  1859. }
  1860.  
  1861. if (!(oursplit in lastobj_props)) {
  1862. console.log(oursplit + " not in lastobj_props");
  1863. return;
  1864. }
  1865.  
  1866. var our_obj = lastobj_win[oursplit] || undefined;
  1867. var our_prop = lastobj_props[oursplit];
  1868.  
  1869. var recurse = function() {
  1870. for (var key in our_prop) {
  1871. if (!key.match(/^\$\$[A-Z]+$/)) {
  1872. defineprop(our_obj, our_prop, key);
  1873. }
  1874. }
  1875. };
  1876.  
  1877. if (!our_prop.$$INJECTED) {
  1878. if (our_obj !== undefined) {
  1879. if (our_prop.$$CHECK) {
  1880. if (!our_prop.$$CHECK(our_obj)) {
  1881. return;
  1882. }
  1883. }
  1884.  
  1885. if (our_prop.$$PROCESS) {
  1886. lastobj_win[oursplit] = our_prop.$$PROCESS(our_obj);
  1887. our_obj = lastobj_win[oursplit];
  1888. }
  1889.  
  1890. recurse();
  1891. }
  1892.  
  1893. try {
  1894. defineProp(lastobj_win, oursplit, {
  1895. get: function() {
  1896. return our_obj;
  1897. },
  1898. set: function(n) {
  1899. if (n === our_obj)
  1900. return;
  1901.  
  1902. //console.log(oursplit + " = ", n);
  1903.  
  1904. if (our_prop.$$PROCESS)
  1905. our_obj = our_prop.$$PROCESS(n);
  1906. else
  1907. our_obj = n;
  1908.  
  1909. recurse();
  1910. }
  1911. });
  1912. our_prop.$$INJECTED = true;
  1913. } catch (e) {
  1914. console.error(e);
  1915. }
  1916. }
  1917. }
  1918.  
  1919. function check_injection(injection, variable, variablename) {
  1920. if ("check" in injection) {
  1921. if (!injection.check(variable)) {
  1922. console.log("[i2d] Not injecting " + variablename);
  1923. return false;
  1924. }
  1925. }
  1926.  
  1927. return true;
  1928. }
  1929.  
  1930. function apply_injection(injection, variable, variablename, win) {
  1931. if (!check_injection(injection, variable, variablename))
  1932. return variable;
  1933.  
  1934. console.log("[i2d] Injecting " + variablename);
  1935.  
  1936. if ("replace" in injection) {
  1937. var context = {
  1938. oldvariable: variable,
  1939. oldvariablename: variablename,
  1940. win: win,
  1941. common: injection.common
  1942. };
  1943.  
  1944. var result = function() {
  1945. return injection.replace.bind(this)(context, arguments);
  1946. };
  1947.  
  1948. for (var key in variable) {
  1949. result[key] = variable[key];
  1950. }
  1951.  
  1952. return result;
  1953. } else if ("proto" in injection) {
  1954. for (var proto in injection.proto) {
  1955. (function(proto) {
  1956. var context = {
  1957. oldvariable: variable.prototype[proto],
  1958. oldvariablename: proto,
  1959. win: win,
  1960. common: injection.common
  1961. };
  1962.  
  1963. variable.prototype[proto] = function() {
  1964. return injection.proto[proto].bind(this)(context, arguments);
  1965. };
  1966. })(proto);
  1967. }
  1968. }
  1969.  
  1970. return variable;
  1971. }
  1972.  
  1973. function do_injection(injection) {
  1974. if ("run_when" in injection) {
  1975. var run_when = injection.run_when;
  1976. if (!(run_when instanceof Array)) {
  1977. run_when = [run_when];
  1978. }
  1979.  
  1980. for (var i = 0; i < run_when.length; i++) {
  1981. if ("host" in run_when[i]) {
  1982. if (!check_host(run_when[i].host))
  1983. return false;
  1984. }
  1985.  
  1986. if ("url_regex" in run_when[i]) {
  1987. if (!window.location.href.match(run_when[i].url_regex))
  1988. return false;
  1989. }
  1990. }
  1991. }
  1992.  
  1993. var win = get_window();
  1994.  
  1995. function do_window_injection(winvar) {
  1996. if (!(winvar instanceof Array))
  1997. winvar = [winvar];
  1998.  
  1999. for (var i = 0; i < winvar.length; i++) {
  2000. (function() {
  2001. var varname = winvar[i];
  2002. var dotsplit = varname.split(".");
  2003. var lastobj = win;
  2004.  
  2005. injected.push(dotsplit[0]);
  2006.  
  2007. var process = function(v) {
  2008. return apply_injection(injection, v, dotsplit[dotsplit.length - 1], win);
  2009. };
  2010.  
  2011. var check = function(v) {
  2012. return check_injection(injection, v, dotsplit[dotsplit.length - 1]);
  2013. };
  2014.  
  2015. var lastprop = props;
  2016. for (var x = 0; x < dotsplit.length; x++) {
  2017. var oursplit = dotsplit[x];
  2018. if (!lastprop[oursplit])
  2019. lastprop[oursplit] = {};
  2020.  
  2021. lastprop[oursplit].$$INJECTED = false;
  2022.  
  2023. if (x === dotsplit.length - 1) {
  2024. lastprop[oursplit].$$PROCESS = process;
  2025. lastprop[oursplit].$$CHECK = check;
  2026. }
  2027.  
  2028. lastprop = lastprop[oursplit];
  2029. }
  2030.  
  2031. /*defineprop(lastobj, dotsplit, 0, function(v) {
  2032. return apply_injection(injection, v, dotsplit[dotsplit.length - 1], win);
  2033. });*/
  2034. })();
  2035. }
  2036. }
  2037.  
  2038. if ("variables" in injection) {
  2039. if ("window" in injection.variables) {
  2040. var winvar = injection.variables.window;
  2041.  
  2042. do_window_injection(winvar);
  2043.  
  2044. /*if (!(winvar instanceof Array))
  2045. winvar = [winvar];
  2046.  
  2047. for (var i = 0; i < winvar.length; i++) {
  2048. var varname = winvar[i];
  2049. var dotsplit = varname.split(".");
  2050. var lastobj = win;
  2051.  
  2052. defineprop(lastobj, dotsplit, 0, function(v) {
  2053. return apply_injection(injection, v, dotsplit[dotsplit.length - 1], win);
  2054. });
  2055. }*/
  2056. }
  2057.  
  2058. if ("jquery" in injection.variables) {
  2059. var jqvar = injection.variables.jquery;
  2060. if (!(jqvar instanceof Array))
  2061. jqvar = [jqvar];
  2062.  
  2063. var winvar = [];
  2064. for (var i = 0; i < jqvar.length; i++) {
  2065. winvar.push("jQuery.fn." + jqvar[i]);
  2066. }
  2067.  
  2068. do_window_injection(winvar);
  2069. }
  2070. }
  2071.  
  2072. if ("onload" in injection) {
  2073. i2d_onload(injection.onload);
  2074. }
  2075.  
  2076. if ("urls" in injection) {
  2077. for (var i = 0; i < injection.urls.length; i++) {
  2078. inject_url(injection.urls[i].regex, injection.urls[i].callback);
  2079. }
  2080. }
  2081. }
  2082.  
  2083. function do_all_injections() {
  2084. for (var i = 0; i < injections.length; i++) {
  2085. do_injection(injections[i]);
  2086. }
  2087.  
  2088. var win = get_window();
  2089. for (var key in props) {
  2090. defineprop(win, props, key);
  2091. }
  2092. }
  2093. do_all_injections();
  2094.  
  2095.  
  2096. /*window.addEventListener("afterscriptexecute", function(e) {
  2097. i2d_main(e.target);
  2098. });*/
  2099.  
  2100. var process_raw_tag = function(el) {
  2101. var basename = "raw ";
  2102.  
  2103. if (el.tagName.toLowerCase() === "video") {
  2104. basename += "video";
  2105. } else {
  2106. basename += "audio";
  2107. }
  2108.  
  2109. if (el.id)
  2110. basename += ": #" + el.id;
  2111.  
  2112. var show_updates = function() {
  2113. if (el.src)
  2114. i2d_show_url(basename, el.src);
  2115.  
  2116. for (var x = 0; x < el.children.length; x++) {
  2117. if (el.children[x].tagName.toLowerCase() !== "source" &&
  2118. el.children[x].tagName.toLowerCase() !== "track") {
  2119. continue;
  2120. }
  2121.  
  2122. var type = "";
  2123. if (el.children[x].type)
  2124. type += "[" + el.children[x].type + "]";
  2125.  
  2126. if (el.children[x].label)
  2127. type += "[" + el.children[x].label + "]";
  2128.  
  2129. if (el.children[x].srclang)
  2130. type += "[" + el.children[x].srclang + "]";
  2131.  
  2132. if (el.children[x].kind)
  2133. type += "(" + el.children[x].kind + ")";
  2134.  
  2135. if (el.children[x].src)
  2136. i2d_show_url(basename, el.children[x].src, type);
  2137. }
  2138. };
  2139.  
  2140. var observer = new MutationObserver(show_updates);
  2141. observer.observe(el, { attributes: true, childList: true });
  2142.  
  2143. show_updates();
  2144. };
  2145.  
  2146. var process_el = function(el) {
  2147. if (el.nodeName === "SCRIPT") {
  2148. //i2d_main(el);
  2149. } else if (el.nodeName === "VIDEO" ||
  2150. el.nodeName === "AUDIO") {
  2151. process_raw_tag(el);
  2152. }
  2153.  
  2154. if (el.children) {
  2155. for (var i = 0; i < el.children.length; i++) {
  2156. process_el(el.children[i]);
  2157. }
  2158. }
  2159. };
  2160.  
  2161. var script_observer_cb = function(mutations, observer) {
  2162. for (var i = 0; i < mutations.length; i++) {
  2163. if (mutations[i].addedNodes) {
  2164. for (var x = 0; x < mutations[i].addedNodes.length; x++) {
  2165. var addednode = mutations[i].addedNodes[x];
  2166. process_el(addednode);
  2167. }
  2168. }
  2169. if (mutations[i].removedNodes) {
  2170. for (var x = 0; x < mutations[i].removedNodes.length; x++) {
  2171. if (mutations[i].removedNodes[x].nodeName === "SCRIPT") {
  2172. //i2d_main(mutations[i].removedNodes[x]);
  2173. }
  2174. }
  2175. }
  2176. }
  2177. };
  2178.  
  2179. var script_observer = new MutationObserver(script_observer_cb);
  2180.  
  2181. script_observer.observe(document, {childList: true, subtree: true});
  2182.  
  2183. i2d_onload(function() {
  2184. var get_raws = function() {
  2185. var audios = [].slice.call(document.getElementsByTagName("audio"));
  2186. var videos = [].slice.call(document.getElementsByTagName("video"));
  2187. var els = Array.prototype.concat(audios, videos);
  2188.  
  2189. for (var i = 0; i < els.length; i++) {
  2190. var basename = "raw ";
  2191. var el = els[i];
  2192.  
  2193. if (el.tagName.toLowerCase() === "video") {
  2194. basename += "video";
  2195. } else {
  2196. basename += "audio";
  2197. }
  2198.  
  2199. if (el.id)
  2200. basename += ": #" + el.id;
  2201.  
  2202. var show_updates = function() {
  2203. if (el.src)
  2204. i2d_show_url(basename, el.src);
  2205.  
  2206. for (var x = 0; x < el.children.length; x++) {
  2207. if (els[i].children[x].tagName.toLowerCase() !== "source" &&
  2208. els[i].children[x].tagName.toLowerCase() !== "track") {
  2209. continue;
  2210. }
  2211.  
  2212. var type = "";
  2213. if (el.children[x].type)
  2214. type += "[" + el.children[x].type + "]";
  2215.  
  2216. if (el.children[x].label)
  2217. type += "[" + el.children[x].label + "]";
  2218.  
  2219. if (el.children[x].srclang)
  2220. type += "[" + el.children[x].srclang + "]";
  2221.  
  2222. if (el.children[x].kind)
  2223. type += "(" + el.children[x].kind + ")";
  2224.  
  2225. if (el.children[x].src)
  2226. i2d_show_url(basename, el.children[x].src, type);
  2227. }
  2228. };
  2229.  
  2230. var observer = new MutationObserver(show_updates);
  2231. observer.observe(el, { attributes: true, childList: true });
  2232.  
  2233. show_updates();
  2234. }
  2235. };
  2236.  
  2237. //get_raws();
  2238.  
  2239. //i2d_main();
  2240. });
  2241. })();

QingJ © 2025

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