Inject2Download

Simple media download script

目前为 2017-12-31 提交的版本,查看 最新版本

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