Inject2Download

Simple media download script

目前为 2016-09-06 提交的版本,查看 最新版本

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