Inject2Download

Simple media download script

当前为 2017-06-10 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Inject2Download
  3. // @namespace http://lkubuntu.wordpress.com/
  4. // @version 0.2.6.1
  5. // @description Simple media download script
  6. // @author Anonymous Meerkat
  7. // @include *
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. "use strict";
  14.  
  15. var injected_set = {};
  16.  
  17. // Helper functions
  18. function i2d_show_url(namespace, url, description) {
  19. function get_absolute_url(url) {
  20. var a = document.createElement('a');
  21. a.href = url;
  22. return a.href;
  23. }
  24.  
  25. function run_on_load(f) {
  26. if (document.readyState === "complete" || document.readyState === "loaded") {
  27. f();
  28. } else {
  29. document.addEventListener('DOMContentLoaded', f, false);
  30. }
  31. }
  32.  
  33. if (!description)
  34. description = "";
  35.  
  36. if (typeof url !== "string" || url.replace("\s", "").length === 0)
  37. return;
  38.  
  39. if (url.match(/^mediasource:/) || url.match(/^blob:/))
  40. return;
  41.  
  42. url = get_absolute_url(url);
  43.  
  44. if (!("i2d_url_list" in window))
  45. window.i2d_url_list = [];
  46.  
  47. for (var i = 0; i < i2d_url_list.length; i++) {
  48. if (i2d_url_list[i][0] === namespace &&
  49. i2d_url_list[i][1] === url &&
  50. i2d_url_list[i][2] === description)
  51. return;
  52. }
  53.  
  54.  
  55. i2d_url_list.push([namespace, url, description]);
  56.  
  57. var newurl = decodeURIComponent(url);
  58.  
  59. var text = "[" + namespace + "] " + description + ": ";
  60.  
  61. console.log("[i2d] " + text + newurl);
  62.  
  63. run_on_load(function() {
  64. var el = document.getElementById("i2d-popup");
  65. var elspan = document.getElementById("i2d-popup-x");
  66. if (!el) {
  67. el = document.createElement("div");
  68. //el.style.position = "absolute";
  69. el.style.width = "max(60%, 100em)";
  70. el.style.height = "max(60%, 100em)";
  71. el.style.maxWidth = "100%";
  72. el.style.maxHeight = "100%";
  73. el.style.background = "white";
  74. el.style.top = "0px";
  75. el.style.left = "0px";
  76. el.style.zIndex = Number.MAX_SAFE_INTEGER - 1;
  77. el.style.color = "black";
  78. el.style.overflow = "scroll";
  79. /*el.ondblclick = function() {
  80. el.parentElement.removeChild(el);
  81. };*/
  82. elspan = document.createElement("span");
  83. elspan.style.fontSize = "130%";
  84. elspan.style.cursor = "pointer";
  85. elspan.style.color = "#900";
  86. elspan.style.padding = ".1em";
  87. elspan.id = "i2d-popup-x";
  88. elspan.innerHTML = '[---close---]';
  89. elspan.style.textDecoration = "underline";
  90. el.innerHTML = "<br style='line-height:150%' />";
  91. el.id = "i2d-popup";
  92. document.body.appendChild(el);
  93.  
  94. elspan.onclick = function() {
  95. var el = document.getElementById("i2d-popup");
  96. el.parentElement.removeChild(el);
  97. };
  98. }
  99. el.innerHTML += text + "<a href='" + newurl + "' style='color:blue'>" + newurl + "</a><br />";
  100.  
  101. // XXX: why is this needed? test: http://playbb.me/embed.php?w=718&h=438&vid=at/nw/flying_witch_-_01.mp4, animeplus.tv
  102. document.body.removeChild(el);
  103. el.style.position = "absolute";
  104. document.body.appendChild(el);
  105.  
  106. if (document.getElementById("i2d-popup-x"))
  107. document.getElementById("i2d-popup-x").parentElement.removeChild(document.getElementById("i2d-popup-x"));
  108.  
  109. el.insertBefore(elspan, el.firstChild);
  110. });
  111. }
  112.  
  113.  
  114. // Injecting functions
  115. var get_script_str = function(f) {
  116. return f.toString().replace(/^function.*{|}$/g, '');
  117. };
  118.  
  119. function add_script(s, el) {
  120. var script_body = "(function() {\n" + s + "\n})();";
  121. var myscript = document.createElement('script');
  122. myscript.className = "i2d";
  123. myscript.innerHTML = script_body;
  124. if (el) {
  125. el.appendChild(myscript);
  126. } else {
  127. document.head.appendChild(myscript);
  128. }
  129. }
  130.  
  131. function inject(variable, newvalue, aliases) {
  132. console.log("[i2d] injecting " + variable);
  133. if (!aliases)
  134. aliases = [];
  135.  
  136. add_script(i2d_show_url.toString() + "\n" +
  137. "if (!(window." + variable + ".INJECTED)) {\n" +
  138. "var oldvariable = window." + variable + ";\n" +
  139. "var oldvariable_keys = Object.keys(oldvariable);\n" +
  140. "window." + variable + " = " + newvalue.toString() + ";\n" +
  141. "for (var i = 0; i < oldvariable_keys.length; i++) {\n" +
  142. " window." + variable + "[oldvariable_keys[i]] = oldvariable[oldvariable_keys[i]];\n" +
  143. "}\n" +
  144. "window." + variable + ".INJECTED = true;\n" +
  145. "var aliases = " + JSON.stringify(aliases) + ";\n" +
  146. "for (var i = 0; i < aliases.length; i++) {\n" +
  147. " if (aliases[i] in window && window[aliases[i]] == oldvariable)" +
  148. " window[aliases[i]] = window." + variable + "\n" +
  149. "}\n" +
  150. "}");
  151. }
  152.  
  153. function jquery_plugin_exists(name) {
  154. if (!("jQuery" in window) ||
  155. !("fn" in window.jQuery) ||
  156. !(name in window.jQuery.fn))
  157. return false;
  158.  
  159. return true;
  160. }
  161.  
  162. function inject_jquery_plugin(name, value) {
  163. if (!jquery_plugin_exists(name) ||
  164. window.jQuery.fn[name].INJECTED)
  165. return;
  166.  
  167. inject("jQuery.fn." + name, value);
  168. }
  169.  
  170. function i2d_onload(f) {
  171. if (document.readyState === "loading") {
  172. document.addEventListener("DOMContentLoaded", f);
  173. } else {
  174. f();
  175. }
  176. }
  177.  
  178.  
  179. // Main code
  180. function i2d_main(e) {
  181. if (e) {
  182. if (!e.tagName || e.tagName.toLowerCase() !== "script")
  183. return;
  184. if ((e.className === "i2d")) {
  185. return;
  186. }
  187. }
  188.  
  189. if ("soundManager" in window && !window.soundManager.INJECTED) {
  190. inject("soundManager.createSound", function(arg1, arg2) {
  191. if (typeof arg1 === "string")
  192. i2d_show_url("soundManager", arg2);
  193. else
  194. i2d_show_url("soundManager", arg1.url);
  195.  
  196. return oldvariable.apply(this, arguments);
  197. });
  198. }
  199.  
  200. if ("jwplayer" in window && !window.jwplayer.INJECTED) {
  201. inject("jwplayer", function() {
  202. var result = oldvariable.apply(this, arguments);
  203.  
  204. var check_sources = function(x) {
  205. if (typeof x === "object") {
  206. if (x instanceof Array) {
  207. for (var i = 0; i < x.length; i++) {
  208. check_sources(x[i]);
  209. }
  210. return;
  211. }
  212.  
  213. var label = "";
  214.  
  215. if ("title" in x)
  216. label += "[" + x.title + "]";
  217.  
  218. if ("label" in x)
  219. label += "[" + x.label + "]";
  220.  
  221. if ("kind" in x)
  222. label += "(" + x.kind + ")";
  223.  
  224. if ("streamer" in x) {
  225. i2d_show_url("jwplayer", x.streamer, "[stream]" + label);
  226. }
  227.  
  228. if ("file" in x) {
  229. i2d_show_url("jwplayer", x.file, label);
  230. }
  231.  
  232. if ("sources" in x) {
  233. check_sources(x.sources);
  234. }
  235.  
  236. if ("playlist" in x) {
  237. check_sources(x.playlist);
  238. }
  239.  
  240. if ("tracks" in x) {
  241. check_sources(x.tracks);
  242. }
  243. } else if (typeof x === "string") {
  244. i2d_show_url("jwplayer", x);
  245. }
  246. };
  247.  
  248. if ("setup" in result) {
  249. var old_jwplayer_setup = result.setup;
  250. result.setup = function() {
  251. if (typeof arguments[0] === "object") {
  252. var x = arguments[0];
  253.  
  254. if ("modes" in x) {
  255. for (var i = 0; i < x.modes.length; i++) {
  256. // TODO: support more?
  257. if ("type" in x.modes[i] && x.modes[i].type === "html5") {
  258. if ("config" in x.modes[i] && "file" in x.modes[i].config) {
  259. check_sources(x.modes[i].config);
  260. }
  261. }
  262. }
  263. }
  264.  
  265. check_sources(x);
  266. }
  267.  
  268. return old_jwplayer_setup.apply(this, arguments);
  269. };
  270. }
  271.  
  272. if ("load" in result) {
  273. var old_jwplayer_load = result.load;
  274. result.load = function() {
  275. check_sources(arguments[0]);
  276. return old_jwplayer_load.apply(this, arguments);
  277. };
  278. }
  279.  
  280. if ("on" in result) {
  281. result.on('playlistItem', function(item) {
  282. check_sources(item.item);
  283. });
  284.  
  285. var old_jwplayer_on = result.on;
  286. result.on = function() {
  287. if (arguments[0] === "adBlock")
  288. return;
  289.  
  290. return old_jwplayer_on.apply(this, arguments);
  291. };
  292. }
  293.  
  294. return result;
  295. });
  296. }
  297.  
  298. if ("flowplayer" in window && !window.flowplayer.INJECTED) {
  299. inject("flowplayer", function() {
  300. var obj_baseurl = null;
  301. var els = [];
  302.  
  303. function get_url(x) {
  304. x = decodeURIComponent(x);
  305.  
  306. if (obj_baseurl) {
  307. if (x.match(/^[a-z]*:\/\//)) {
  308. return x;
  309. } else {
  310. return obj_baseurl + "/" + x;
  311. }
  312. } else {
  313. return x;
  314. }
  315. }
  316.  
  317. function check_sources(x, els, label) {
  318. if (typeof x === "string") {
  319. if (!x.match(/\.xml$/))
  320. i2d_show_url("flowplayer", get_url(x), label);
  321.  
  322. return;
  323. }
  324.  
  325. if (x instanceof Array) {
  326. for (var i = 0; i < x.length; i++) {
  327. check_sources(x[i], els, label);
  328. }
  329. return;
  330. }
  331.  
  332. if (typeof x !== "object")
  333. return;
  334.  
  335. label = "";
  336.  
  337. if ("title" in x)
  338. label += "[" + x.title + "]";
  339.  
  340. if ("clip" in x) {
  341. if ("baseUrl" in x.clip) {
  342. obj_baseurl = x.clip.baseUrl;
  343.  
  344. for (var i = 0; i < els.length; i++) {
  345. els[i].i2d_baseurl = obj_baseurl;
  346. }
  347. }
  348.  
  349. check_sources(x.clip, els, label);
  350. }
  351.  
  352. if ("sources" in x) {
  353. check_sources(x.sources, els, label);
  354. }
  355.  
  356. if ("playlist" in x) {
  357. check_sources(x.playlist, els, label);
  358. }
  359.  
  360. if ("url" in x) {
  361. check_sources(x.url, els, label);
  362. }
  363.  
  364. if ("src" in x) {
  365. check_sources(x.src, els. label);
  366. }
  367.  
  368. if ("bitrates" in x) {
  369. for (var j = 0; j < x.bitrates.length; j++) {
  370. if ("url" in x.bitrates[j]) {
  371. var description = "";
  372. if (x.bitrates[j].isDefault)
  373. description += "default:";
  374. if (x.bitrates[j].sd)
  375. description += "sd:";
  376. if (x.bitrates[j].hd)
  377. description += "hd:";
  378. if (x.bitrates[j].bitrate)
  379. description += x.bitrates[j].bitrate;
  380.  
  381. i2d_show_url("flowplayer", get_url(x.bitrates[j].url), description);
  382. }
  383. }
  384. }
  385. }
  386.  
  387. if (arguments.length >= 1) {
  388. els = [null];
  389.  
  390. if (typeof arguments[0] === "string") {
  391. try {
  392. els[0] = document.getElementById(arguments[0]);
  393. } catch(e) {
  394. }
  395.  
  396. try {
  397. if (!els[0])
  398. els = document.querySelectorAll(arguments[0]);
  399. } catch(e) {
  400. els = [];
  401. }
  402. } else if (arguments[0] instanceof HTMLElement) {
  403. els = [arguments[0]];
  404. }
  405. }
  406.  
  407. for (var i = 0; i < els.length; i++) {
  408. if (!els[i] || !(els[i] instanceof HTMLElement))
  409. continue;
  410.  
  411. if ("i2d_baseurl" in els[i])
  412. obj_baseurl = els[i].i2d_baseurl;
  413. }
  414.  
  415. if (arguments.length >= 3 && typeof arguments[2] === "object") {
  416. check_sources(arguments[2], els);
  417. } else if (arguments.length >= 3 && typeof arguments[2] === "string") {
  418. i2d_show_url("flowplayer", get_url(arguments[2]));
  419. } else if (arguments.length === 2 && typeof arguments[1] === "object") {
  420. check_sources(arguments[1], els);
  421. } else if (arguments.length === 2 && typeof arguments[1] === "string") {
  422. i2d_show_url("flowplayer", get_url(arguments[1]));
  423. }
  424.  
  425. for (var i = 0; i < els.length; i++) {
  426. if (!els[i] || !(els[i] instanceof HTMLElement))
  427. continue;
  428.  
  429. var href = els[i].getAttribute("href");
  430. if (href) {
  431. i2d_show_url("flowplayer", get_url(href), "href");
  432. }
  433. }
  434.  
  435. var result = oldvariable.apply(this, arguments);
  436.  
  437. if (!result || typeof result !== "object")
  438. return result;
  439.  
  440. if ("addClip" in result) {
  441. var old_fplayer_addclip = result.addClip;
  442. result.addClip = function() {
  443. if (arguments.length > 0)
  444. check_sources(arguments[0], els);
  445.  
  446. return old_fplayer_addclip.apply(this, arguments);
  447. };
  448. }
  449.  
  450. if ("setPlaylist" in result) {
  451. var old_fplayer_setplaylist = result.setPlaylist;
  452. result.setPlaylist = function() {
  453. if (arguments.length > 0)
  454. check_sources(arguments[0], els);
  455.  
  456. return old_fplayer_setplaylist.apply(this, arguments);
  457. };
  458. }
  459.  
  460. if ("load" in result) {
  461. var old_fplayer_load = result.load;
  462. result.load = function() {
  463. if (arguments.length > 0)
  464. check_sources(arguments[0], els);
  465.  
  466. return old_fplayer_load.apply(this, arguments);
  467. };
  468. }
  469.  
  470. /*if ("on" in result) {
  471. result.on("load", function(e, api, video) {
  472. console.log(e);
  473. check_sources(video || api.video, els);
  474. });
  475. }*/
  476.  
  477. return result;
  478. }, ["$f"]);
  479.  
  480. add_script(get_script_str(function() {
  481. flowplayer(function(api, root) {
  482. api.on("load", function(e, api, video) {
  483. flowplayer().load(video || api.video);
  484. });
  485. });
  486. }));
  487. }
  488.  
  489. if ("videojs" in window && !window.videojs.INJECTED) {
  490. inject("videojs", function() {
  491. if (arguments.length > 0 && typeof arguments[0] === "string") {
  492. var my_el = document.getElementById(arguments[0]);
  493. if (!my_el)
  494. my_el = document.querySelector(arguments[0]);
  495.  
  496. if (my_el) {
  497. if (my_el.src) {
  498. i2d_show_url("videojs", my_el.src);
  499. }
  500.  
  501. for (var i = 0; i < my_el.children.length; i++) {
  502. if (my_el.children[i].tagName.toLowerCase() === "source") {
  503. if (my_el.children[i].src) {
  504. i2d_show_url("videojs", my_el.children[i].src, my_el.children[i].getAttribute("label"));
  505. }
  506. }
  507. }
  508. }
  509. }
  510.  
  511. var result = oldvariable.apply(this, arguments);
  512.  
  513. var old_videojs_src = result.src;
  514. result.src = function() {
  515. if (arguments.length > 0 && typeof arguments[0] === "object") {
  516. if ("src" in arguments[0]) {
  517. i2d_show_url("videojs", arguments[0].src);
  518. }
  519. }
  520.  
  521. return old_videojs_src.apply(this, arguments);
  522. };
  523.  
  524. return result;
  525. });
  526.  
  527. add_script(i2d_show_url.toString() +
  528. i2d_onload.toString() +
  529. get_script_str(function() {
  530. i2d_onload(function() {
  531. var els = document.getElementsByClassName("video-js");
  532. for (var i = 0; i < els.length; i++) {
  533. var my_el = els[i];
  534. if (my_el.tagName.toLowerCase() === "video") {
  535. if (!my_el.getAttribute('data-setup')) {
  536. continue;
  537. }
  538. if (my_el.src) {
  539. i2d_show_url("videojs", my_el.src);
  540. }
  541.  
  542. for (var j = 0; j < my_el.children.length; j++) {
  543. if (my_el.children[j].tagName.toLowerCase() === "source") {
  544. if (my_el.children[j].src) {
  545. i2d_show_url("videojs", my_el.children[j].src, my_el.children[j].getAttribute("label"));
  546. }
  547. }
  548. }
  549. }
  550. }
  551. });
  552. }));
  553. }
  554.  
  555. if ("amp" in window && !window.amp.INJECTED) {
  556. inject("amp", function() {
  557. function show_amp_source(sourceobj) {
  558. if ("protectionInfo" in sourceobj) {
  559. console.log("[amp] Cannot decode protection info");
  560. }
  561. if ("src" in sourceobj)
  562. i2d_show_url("amp", sourceobj.src);
  563. }
  564.  
  565. if (arguments.length >= 2 && typeof arguments[1] === "object") {
  566. if ("sourceList" in arguments[1]) {
  567. for (var i = 0; i < arguments[1].sourceList.length; i++) {
  568. show_amp_source(arguments[1].sourceList[i]);
  569. }
  570. }
  571. }
  572.  
  573. var result = oldvariable.apply(this, arguments);
  574.  
  575. if (!result)
  576. return result;
  577.  
  578. var old_amp_src = result.src;
  579. result.src = function() {
  580. for (var i = 0; i < arguments[0].length; i++) {
  581. show_amp_source(arguments[0][i]);
  582. }
  583.  
  584. return old_amp_src.apply(this, arguments);
  585. };
  586.  
  587. return result;
  588. });
  589. }
  590.  
  591. if ("DJPlayer" in window && !window.DJPlayer.INJECTED) {
  592. add_script(i2d_show_url.toString() + "\n" +
  593. "var oldsetmedia = window.DJPlayer.prototype.setMedia;\n" +
  594. "window.DJPlayer.prototype.setMedia = function() {\n" +
  595. " if (arguments.length > 0 && typeof arguments[0] === 'string') {\n" +
  596. " i2d_show_url('DJPlayer', arguments[0]);\n" +
  597. " }\n" +
  598. " return oldsetmedia.apply(this, arguments);\n" +
  599. "}");
  600. }
  601.  
  602. if ("bitmovin" in window && !window.bitmovin.INJECTED) {
  603. inject("bitmovin.player", function() {
  604. var result = oldvariable.apply(this, arguments);
  605.  
  606. var check_progressive = function(progressive) {
  607. if (typeof progressive === "string") {
  608. i2d_show_url("bitmovin", progressive, "progressive");
  609. } else if (progressive instanceof Array) {
  610. for (var i = 0; i < progressive.length; i++) {
  611. check_progressive(progressive[i]);
  612. }
  613. } else if (typeof progressive === "object") {
  614. var str = "";
  615. if (progressive.label)
  616. str += "[" + progressive.label + "] ";
  617. if (progressive.bitrate)
  618. str += progressive.bitrate;
  619.  
  620. i2d_show_url("bitmovin", progressive.url, str);
  621. }
  622. };
  623.  
  624. var check_sources = function(x) {
  625. if (typeof x === "object") {
  626. if ("source" in x) {
  627. var sourceobj = x.source;
  628.  
  629. if (sourceobj.progressive) {
  630. check_progressive(sourceobj.progressive);
  631. }
  632.  
  633. if (sourceobj.dash) {
  634. i2d_show_url("bitmovin", sourceobj.dash, "dash");
  635. }
  636.  
  637. if (sourceobj.hls) {
  638. i2d_show_url("bitmovin", sourceobj.hls, "hls");
  639. }
  640. }
  641. }
  642. }
  643.  
  644. if ("setup" in result) {
  645. var old_bitmovin_setup = result.setup;
  646. result.setup = function() {
  647. check_sources(arguments[0]);
  648.  
  649. return old_bitmovin_setup.apply(this, arguments);
  650. };
  651. }
  652.  
  653. if ("load" in result) {
  654. var old_bitmovin_load = result.load;
  655. result.load = function() {
  656. check_sources({source: arguments[0]});
  657.  
  658. return old_bitmovin_load.apply(this, arguments);
  659. };
  660. }
  661.  
  662. return result;
  663. }, ["bitdash"]);
  664. }
  665.  
  666. if (("location" in window) && window.location && window.location.host.search("forvo") >= 0 && "createAudioObject" in window && !window.createAudioObject.INJECTED) {
  667. inject("createAudioObject", function(id, mp3, ogg) {
  668. i2d_show_url("forvo", mp3, "mp3");
  669. i2d_show_url("forvo", ogg, "ogg");
  670.  
  671. return oldvariable.apply(this, arguments);
  672. });
  673. }
  674.  
  675. if (("location" in window) && window.location && window.location.href.search("twitter.com/i/videos") >= 0 && !("twitter" in injected_set)) {
  676. injected_set["twitter"] = true;
  677.  
  678. i2d_onload(function() {
  679. var pc = document.getElementById('playerContainer');
  680. if (!pc) {
  681. return;
  682. }
  683.  
  684. var config = pc.getAttribute('data-config');
  685. if (!config) {
  686. return;
  687. }
  688.  
  689. var config_parsed = JSON.parse(config);
  690.  
  691. if ("video_url" in config_parsed) {
  692. i2d_show_url('twitter', config_parsed.video_url);
  693. }
  694. });
  695. }
  696.  
  697. if (("location" in window) && window.location && window.location.href.search("vine.co/v/") >= 0) {
  698. var show_video_urls = function(videourls) {
  699. for (var i = 0; i < videourls.length; i++) {
  700. var videourl = videourls[i];
  701.  
  702. var formatstr = "[";
  703. formatstr += videourl.format + ":";
  704. formatstr += videourl.idStr;
  705.  
  706. if (videourl.rate > 0)
  707. formatstr += ", " + videourl.rate;
  708.  
  709. formatstr += "]";
  710.  
  711. i2d_show_url('vine', videourl.videoUrl, formatstr);
  712. }
  713. };
  714.  
  715. if (window.location.href.search("/card" ) >= 0 && !("vine_card" in injected_set)) {
  716. injected_set["vine_card"] = true;
  717.  
  718. i2d_onload(function() {
  719. var config_el = document.getElementById("configuration");
  720. if (!config_el) {
  721. return;
  722. }
  723.  
  724. var config = JSON.parse(config_el.innerHTML);
  725. if (!config || typeof config !== "object") {
  726. return;
  727. }
  728.  
  729. if (!("post" in config) || !("videoUrls" in config.post)) {
  730. return;
  731. }
  732.  
  733. show_video_urls(config.post.videoUrls);
  734. });
  735. } else if (!("vine_video" in injected_set)) {
  736. injected_set["vine_video"] = true;
  737.  
  738. i2d_onload(function() {
  739. var scripts = document.getElementsByTagName("script");
  740. if (scripts.length === 0)
  741. return;
  742.  
  743. var thescript = null;
  744. for (var i = 0; i < scripts.length; i++) {
  745. if (scripts[i].innerHTML.search("window.POST_DATA") < 0) {
  746. continue;
  747. }
  748.  
  749. thescript = scripts[i];
  750. break;
  751. }
  752.  
  753. var config;
  754. eval(thescript.innerHTML.replace("window.POST_DATA", "config"));
  755.  
  756. var videourls = config[Object.keys(config)[0]].videoUrls;
  757. show_video_urls(videourls);
  758. });
  759. }
  760. }
  761.  
  762. if ("jQuery" in window) {
  763. inject_jquery_plugin("jPlayer", function() {
  764. if (arguments.length > 0 && arguments[0] === "setMedia") {
  765. if (arguments.length > 1) {
  766. if (typeof arguments[1] === "object") {
  767. for (var i in arguments[1]) {
  768. if (i === "title" ||
  769. i === "duration" ||
  770. i === "track" /* for now */ ||
  771. i === "artist" ||
  772. i === "free")
  773. continue;
  774.  
  775. i2d_show_url("jPlayer", arguments[1][i], i);
  776. }
  777. } else if (typeof arguments[1] === "string") {
  778. i2d_show_url("jPlayer", arguments[1]);
  779. }
  780. }
  781. }
  782.  
  783. return oldvariable.apply(this, arguments);
  784. });
  785.  
  786. inject_jquery_plugin("amazingaudioplayer", function() {
  787. var result = oldvariable.apply(this, arguments);
  788.  
  789. function add_source_obj(x) {
  790. type = "";
  791. if ("type" in x) {
  792. type = x.type;
  793. }
  794.  
  795. i2d_show_url("amazingaudioplayer", x.src, type);
  796. }
  797.  
  798. function add_source(x) {
  799. if (x instanceof Array) {
  800. for (var i = 0; i < x.length; i++) {
  801. add_source_obj(x[i]);
  802. }
  803. } else {
  804. add_source_obj(x);
  805. }
  806. }
  807.  
  808. var audioplayer = jQuery(this).data("object").audioPlayer;
  809. if (audioplayer.audioItem) {
  810. add_source(audioplayer.audioItem.source);
  811. }
  812.  
  813. var oldload = audioplayer.load;
  814. audioplayer.load = function(item) {
  815. if ("source" in item) {
  816. add_source(item.source);
  817. }
  818.  
  819. return oldload.apply(this, arguments);
  820. };
  821.  
  822. return result;
  823. });
  824.  
  825. if (jquery_plugin_exists("jPlayerAudio") && !window.jQuery.fn.jPlayerAudio.INJECTED) {
  826. inject_jquery_plugin("jPlayerAudio", function() {
  827. return oldvariable.apply(this, arguments);
  828. });
  829.  
  830. add_script(i2d_show_url.toString() + "\n" +
  831. "var oldmedia=jQuery.jPlayerAudio.prototype.setMedia;\n" +
  832. "jQuery.jPlayerAudio.prototype.setMedia = function(e) {\n" +
  833. " var absolute = this._absoluteMediaUrls(e);\n" +
  834. " jQuery.each(this.formats, function(a, o) {\n" +
  835. " i2d_show_url('cleanaudioplayer', absolute[o]);\n" +
  836. " });\n" +
  837. " return oldmedia.apply(this, arguments);\n" +
  838. "}");
  839. }
  840.  
  841. if (jquery_plugin_exists("jPlayerVideo") && !window.jQuery.fn.jPlayerVideo.INJECTED) {
  842. inject_jquery_plugin("jPlayerVideo", function() {
  843. return oldvariable.apply(this, arguments);
  844. });
  845.  
  846. add_script(i2d_show_url.toString() + "\n" +
  847. "var oldmedia=jQuery.jPlayerVideo.prototype.setMedia;\n" +
  848. "jQuery.jPlayerVideo.prototype.setMedia = function(e) {\n" +
  849. " var absolute = this._absoluteMediaUrls(e);\n" +
  850. " jQuery.each(this.formats, function(a, o) {\n" +
  851. " i2d_show_url('cleanvideoplayer', absolute[o]);\n" +
  852. " });\n" +
  853. " return oldmedia.apply(this, arguments);\n" +
  854. "}");
  855. }
  856. }
  857. }
  858.  
  859. i2d_main();
  860.  
  861. window.addEventListener("afterscriptexecute", function(e) {
  862. i2d_main(e.target);
  863. });
  864.  
  865. i2d_onload(function() {
  866. var get_raws = function() {
  867. var audios = [].slice.call(document.getElementsByTagName("audio"));
  868. var videos = [].slice.call(document.getElementsByTagName("video"));
  869. var els = Array.prototype.concat(audios, videos);
  870.  
  871. for (var i = 0; i < els.length; i++) {
  872. var basename = "raw ";
  873. var el = els[i];
  874.  
  875. if (el.tagName.toLowerCase() === "video") {
  876. basename += "video";
  877. } else {
  878. basename += "audio";
  879. }
  880.  
  881. if (el.id)
  882. basename += ": #" + el.id;
  883.  
  884. var show_updates = function() {
  885. if (el.src)
  886. i2d_show_url(basename, el.src);
  887.  
  888. for (var x = 0; x < el.children.length; x++) {
  889. if (els[i].children[x].tagName.toLowerCase() !== "source" &&
  890. els[i].children[x].tagName.toLowerCase() !== "track") {
  891. continue;
  892. }
  893.  
  894. var type = "";
  895. if (el.children[x].type)
  896. type += "[" + el.children[x].type + "]";
  897.  
  898. if (el.children[x].label)
  899. type += "[" + el.children[x].label + "]";
  900.  
  901. if (el.children[x].srclang)
  902. type += "[" + el.children[x].srclang + "]";
  903.  
  904. if (el.children[x].kind)
  905. type += "(" + el.children[x].kind + ")";
  906.  
  907. if (el.children[x].src)
  908. i2d_show_url(basename, el.children[x].src, type);
  909. }
  910. };
  911.  
  912. var observer = new MutationObserver(show_updates);
  913. observer.observe(el, { attributes: true, childList: true });
  914.  
  915. show_updates();
  916. }
  917. };
  918.  
  919. get_raws();
  920.  
  921. i2d_main();
  922. });
  923. })();