Inject2Download

Simple media download script

当前为 2017-11-18 提交的版本,查看 最新版本

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