YouTube Download

On youtube click the download link to download youtube video.

当前为 2015-10-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Download
  3. // @namespace http://your.homepage/
  4. // @version 4.4.6
  5. // @description On youtube click the download link to download youtube video.
  6. // @author Henry Harris
  7. // @match https://www.youtube.com/*
  8. // @match http://9xbuddy.com/*
  9. // @grant none
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14.  
  15.  
  16.  
  17.  
  18. $(document).ready ( function(){
  19. // -----------------------Runs on YOUTUBE--------------------------------------------------------------
  20. var beforestop = false;
  21. setInterval(function(){
  22. if(window.location.href.indexOf("you") > -1) {
  23. if ($('#watch7-headline').length > 0) {
  24. if ($('#downloadlnk').length > 0) {
  25. } else {
  26. if ($('.html5-player-chrome').length > 0) {
  27. if ($('#vidctrls').length > 0) {
  28. } else{
  29. document.querySelector('div.html5-player-chrome').id = 'vidctrls';
  30.  
  31. var c = document.createElement('img');
  32. c.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Egypt_governorates_blank.png/597px-Egypt_governorates_blank.png";
  33. c.height = "30";
  34. c.width = "10";
  35. var b = document.createElement('img');
  36. b.src = "http://images.clipartpanda.com/square-clip-art-black-and-white-0999d59a768fa638a6f16f4a44299e29.png";
  37. b.height = "30";
  38. b.width = "30";
  39. b.title = "Download this video";
  40. b.onclick = function () {
  41. window.open("http://9xbuddy.com/download?url=" + document.URL)
  42. };
  43.  
  44. document.getElementById("vidctrls").appendChild(c);
  45. document.getElementById("vidctrls").appendChild(b);
  46. }
  47. } else {
  48. var downdiv = document.createElement("div");
  49. downdiv.id = "downdiv";
  50. var a = document.createElement('a');
  51. var linkText = document.createTextNode("Download");
  52. a.appendChild(linkText);
  53. a.id = "downloadlnk";
  54. a.title = "Download this video";
  55. a.onclick = function () {
  56. window.open("http://9xbuddy.com/download?url=" + document.URL)
  57. };
  58. var br3 = document.createElement('br');
  59. document.getElementById("watch7-headline").appendChild(br3);
  60. var br4 = document.createElement('br');
  61. document.getElementById("watch7-headline").appendChild(br4);
  62. var setimg = document.createElement('img');
  63. setimg.width = 27;
  64. setimg.length = 27;
  65. setimg.src = "https://qph.is.quoracdn.net/main-qimg-8237596d1a16264adb1900d01ea71f0a";
  66. var dwnimg = document.createElement('img');
  67. dwnimg.width = 27;
  68. dwnimg.length = 27;
  69. dwnimg.src = "http://www.clipartbest.com/cliparts/bTy/EX8/bTyEX8prc.png";
  70. var d = document.createElement('a');
  71. var linkText = document.createTextNode("Options");
  72. d.appendChild(linkText);
  73. d.id = "optionlnk";
  74. d.title = "Options";
  75. d.onclick = function () {
  76. var e = document.body;
  77. e.parentNode.removeChild(e);
  78. var body = document.createElement('body');
  79. document.getElementsByTagName('html')[0].appendChild(body);
  80. var chk1 = document.createElement('input');
  81. chk1.type = "checkbox";
  82. chk1.id = "chk1"
  83. document.getElementsByTagName('body')[0].appendChild(chk1);
  84. var label1 = document.createElement('label');
  85. //labe1l.htmlFor = "chk1";
  86. label1.appendChild(document.createTextNode('Auto HD + remove video ads'));
  87. document.getElementsByTagName('body')[0].appendChild(label1);
  88. var br = document.createElement('br');
  89. document.getElementsByTagName('body')[0].appendChild(br);
  90. var chk2 = document.createElement('input');
  91. chk2.type = "checkbox";
  92. chk2.id = "chk2"
  93. document.getElementsByTagName('body')[0].appendChild(chk2);
  94. var label2 = document.createElement('label');
  95. //labe12.htmlFor = "chk2";
  96. label2.appendChild(document.createTextNode('Loop videos'));
  97. document.getElementsByTagName('body')[0].appendChild(label2);
  98. var br4 = document.createElement('br');
  99. document.getElementsByTagName('body')[0].appendChild(br4);
  100. var chk3 = document.createElement('input');
  101. chk3.type = "checkbox";
  102. chk3.id = "chk2"
  103. document.getElementsByTagName('body')[0].appendChild(chk3);
  104. var label3 = document.createElement('label');
  105. //labe13.htmlFor = "chk2";
  106. label3.appendChild(document.createTextNode('Old Player'));
  107. document.getElementsByTagName('body')[0].appendChild(label3);
  108. var br5 = document.createElement('br');
  109. document.getElementsByTagName('body')[0].appendChild(br5);
  110. var chk4 = document.createElement('input');
  111. chk4.type = "checkbox";
  112. chk4.id = "chk4"
  113. document.getElementsByTagName('body')[0].appendChild(chk4);
  114. var label4 = document.createElement('label');
  115. //labe1l.htmlFor = "chk1";
  116. label4.appendChild(document.createTextNode('Auto-Buffer'));
  117. document.getElementsByTagName('body')[0].appendChild(label4);
  118. var br3 = document.createElement('br');
  119. document.getElementsByTagName('body')[0].appendChild(br3);
  120. var br2 = document.createElement('br');
  121. document.getElementsByTagName('body')[0].appendChild(br2);
  122. var appbtn = document.createElement('input');
  123. appbtn.type = "button";
  124. appbtn.value = "Apply"
  125. appbtn.onclick = function () {
  126. if (chk1.checked == true) {
  127. document.cookie =
  128. 'autohd=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
  129. } else {
  130. document.cookie = 'autohd=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'
  131. }
  132. if (chk2.checked == true) {
  133. document.cookie =
  134. 'loop=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
  135. } else {
  136. document.cookie = 'loop=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'
  137. }
  138. if (chk3.checked == true) {
  139. document.cookie =
  140. 'oldplyr=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
  141. } else {
  142. document.cookie = 'oldplyr=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'
  143. }
  144. if (chk3.checked == true && chk1.checked == true) {
  145. alert("Auto-HD and Old Player are incompatible, please disable one of them.");
  146. } else {
  147. location.reload();
  148. }
  149. if (chk4.checked == true) {
  150. document.cookie =
  151. 'abuff=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
  152. } else {
  153. document.cookie = 'abuff=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'
  154. }
  155. }
  156. document.getElementsByTagName('body')[0].appendChild(appbtn);
  157. if (document.cookie.indexOf('autohd=')== -1) {
  158. chk1.checked = false;
  159. } else {
  160. chk1.checked = true;
  161. }
  162. if (document.cookie.indexOf('loop=')== -1) {
  163. chk2.checked = false;
  164. } else {
  165. chk2.checked = true;
  166. }
  167. if (document.cookie.indexOf('oldplyr=')== -1) {
  168. chk3.checked = false;
  169. } else {
  170. chk3.checked = true;
  171. }
  172. if (document.cookie.indexOf('abuff=')== -1) {
  173. chk4.checked = false;
  174. } else {
  175. chk4.checked = true;
  176. }
  177. };
  178. //document.body.appendChild(a);
  179. document.getElementById("watch7-headline").appendChild(downdiv);
  180. document.getElementById("downdiv").appendChild(dwnimg);
  181. document.getElementById("downdiv").appendChild(a);
  182. document.getElementById("downdiv").appendChild(br3);
  183. document.getElementById("downdiv").appendChild(br4);
  184. document.getElementById("downdiv").appendChild(setimg);
  185. document.getElementById("downdiv").appendChild(d);
  186. document.getElementById("downloadlnk").style.fontSize = "x-large";
  187. document.getElementById("optionlnk").style.fontSize = "x-large";
  188. var br1 = document.createElement('br');
  189. document.getElementById("watch7-headline").appendChild(br1);
  190. var br2 = document.createElement('br');
  191. document.getElementById("watch7-headline").appendChild(br2);
  192. }
  193. }
  194. }
  195. }
  196.  
  197. if (document.cookie.indexOf('autohd=')== -1) {
  198. //no cookie
  199. } else {
  200. if (beforestop == false) {
  201. var myNode = document.getElementById("movie_player");
  202. while (myNode.firstChild) {
  203. myNode.removeChild(myNode.firstChild);
  204. beforestop = true;
  205. }
  206.  
  207. var url = document.URL;
  208. url = url.substring(0, url.length - 8);
  209. var vidid = url.substring(url.indexOf('=')+1);
  210. var player = document.createElement('iframe');
  211. player.id = "player1";
  212. player.width = "1920";
  213. player.height = "1080";
  214. player.src = "https://www.youtube.com/embed/" + vidid + "?rel=0&autoplay=1&VQ=HD720";
  215. player.frameborder = "0";
  216. document.getElementById("movie_player").appendChild(player);
  217. document.getElementById("player1").setAttribute("allowfullscreen", "true");
  218. setTimeout(function(){
  219. document.getElementById("player1").width = "855";
  220. document.getElementById("player1").height = "480";
  221. }, 15000);
  222. }
  223. var url = document.URL;
  224. var idtest = url.substring(url.indexOf('=')+1);
  225. if (idtest === vidid){
  226. } else {
  227. }
  228. }
  229. if (document.cookie.indexOf('oldplyr=')== -1) {
  230. //no cookie
  231. } else {
  232. if (beforestop == false) {
  233. var myNode = document.getElementById("movie_player");
  234. while (myNode.firstChild) {
  235. myNode.removeChild(myNode.firstChild);
  236. beforestop = true;
  237. }
  238.  
  239. var url = document.URL;
  240. url = url.substring(0, url.length - 8);
  241. var vidid = url.substring(url.indexOf('=')+1);
  242. var player = document.createElement('iframe');
  243. player.id = "player1";
  244. player.width = "855";
  245. player.height = "480";
  246. player.src = "https://youtube.googleapis.com/v/" + vidid + "?version=3&autoplay=1";
  247. player.frameborder = "0";
  248. document.getElementById("movie_player").appendChild(player);
  249. document.getElementById("player1").setAttribute("allowfullscreen", "true");
  250. }
  251. var url = document.URL;
  252. var idtest = url.substring(url.indexOf('=')+1);
  253. if (idtest === vidid){
  254. } else {
  255. }
  256. }
  257. }, 2000);
  258. setInterval(function(){
  259. if (document.cookie.indexOf('oldplyr=')== -1) {
  260. } else {
  261. if(window.location.href.indexOf("you") > -1) {
  262. if(window.location.href.indexOf("embed") > -1) {
  263. } else {
  264. if(window.location.href.indexOf("reldone") > -1) {
  265. } else {
  266. window.location.assign(document.URL + "#reldone");
  267. location.reload();
  268. }
  269. }
  270. }
  271. }
  272. }, 4000);
  273. setInterval(function(){
  274. if (document.cookie.indexOf('autohd=')== -1) {
  275. } else {
  276. if(window.location.href.indexOf("you") > -1) {
  277. if(window.location.href.indexOf("embed") > -1) {
  278. } else {
  279. if(window.location.href.indexOf("reldone") > -1) {
  280. } else {
  281. window.location.assign(document.URL + "#reldone");
  282. location.reload();
  283. }
  284. }
  285. }
  286. }
  287. }, 4000);
  288. setInterval(function(){
  289. if (window.location.href.indexOf("watch") > -1){
  290. if (document.cookie.indexOf('loop=')== -1){
  291. } else {
  292. var curtime = document.getElementsByClassName('ytp-time-current')[0].innerHTML;
  293. var endtime = document.getElementsByClassName('ytp-time-duration')[0].innerHTML;
  294. if (curtime === endtime){
  295. document.getElementsByClassName("ytp-play-button ytp-button")[0].click();
  296. }
  297. }
  298. }
  299. }, 1000);
  300. setInterval(function(){
  301. if (window.location.href.indexOf("embed") > -1){
  302. if (document.cookie.indexOf('loop=')== -1){
  303. } else {
  304. var curtime = document.getElementsByClassName('ytp-time-current')[0].innerHTML;
  305. var endtime = document.getElementsByClassName('ytp-time-duration')[0].innerHTML;
  306. if (curtime === endtime){
  307. document.getElementsByClassName("ytp-play-button ytp-button")[0].click();
  308. }
  309. }
  310. }
  311. }, 1000);
  312. function resetVid() {
  313. }
  314. var done = false;
  315. var cururl = document.URL;
  316. setInterval(function(){
  317. if (window.location.href.indexOf("you") > -1){
  318. if (document.cookie.indexOf('abuff=')== -1){
  319. } else {
  320. if (document.getElementsByClassName('ytp-load-progress')[0].style.transform === "scaleX(1)") {
  321. //setInterval(function(){
  322. if (done == false) {
  323. var vid = document.getElementsByClassName('video-stream html5-main-video')[0];
  324. if (vid.currentTime < 20) {
  325. document.getElementsByClassName('video-stream html5-main-video')[0].currentTime = 0;
  326. done = true;
  327. } else {
  328. var tt = document.getElementsByClassName('video-stream html5-main-video')[0].currentTime;
  329. var ttt = tt - 15;
  330. //alert(tt);
  331. //alert(ttt);
  332. document.getElementsByClassName('video-stream html5-main-video')[0].currentTime = ttt;
  333. }
  334. }
  335. //}, 1000);
  336. }
  337. if (document.getElementsByClassName('ytp-load-progress')[0].style.transform === "scaleX(1)") {
  338. } else {
  339. done = false;
  340. }
  341. if (document.getElementById("movie_player").style.visibility === "visible") {
  342. } else {
  343. document.getElementById("movie_player").style.visibility = "hidden";
  344. }
  345. if (cururl === document.URL) {
  346. } else {
  347. location.reload();
  348. }
  349. }
  350. }
  351. }, 2000);
  352. setInterval(function(){
  353. if (window.location.href.indexOf("you") > -1){
  354. if (document.cookie.indexOf('abuff=')== -1){
  355. } else {
  356. if (document.getElementById("movie_player").style.visibility === "hidden") {
  357. document.getElementsByClassName('video-stream html5-main-video')[0].muted = true;
  358. if (document.getElementsByClassName('ytp-load-progress')[0].style.transform === "scaleX(1)" && done == true) {
  359. document.getElementById("movie_player").style.visibility = "visible";
  360. document.getElementsByClassName('video-stream html5-main-video')[0].muted = false;
  361. }
  362. }
  363. }
  364. }
  365. }, 2000);
  366. // --------------------------RUNS ON 9xbuddy TO DOWNLOAD VIDEO--------------------------------------------
  367. if(window.location.href.indexOf("buddy") > -1) {
  368. /*var iDiv = document.createElement('div');
  369.  
  370. iDiv.id = 'block';
  371. iDiv.className = 'block';
  372. document.getElementsByTagName('body')[0].appendChild(iDiv);
  373. iDiv.height = window.height();
  374. iDiv.width = window.width();
  375. $(iDiv).css({
  376. position: 'fixed',
  377. top: 0,
  378. right: 0,
  379. bottom: 0,
  380. left: 0,
  381. zIndex: 999
  382. });*/
  383.  
  384.  
  385.  
  386. //if(!$('#javaUserWarning').is(':visible')) {
  387. setInterval(function(){
  388. if ($(".download-link-list")[0]){
  389. var els = document.getElementsByClassName('download-link-download lbcolor');
  390. var element = $('.download-about-section li');
  391. var zali = element[1]
  392. var zalitext = zali.innerHTML
  393. if (zalitext.match("VEVO")) {
  394. var li = els[1]
  395. li.id = 'dwnload';
  396. var t = $('#dwnload a').attr('href');
  397. } else {
  398. var li = els[2]
  399. li.id = 'dwnload';
  400. var t = $('#dwnload a').attr('href');
  401. }
  402. window.location = t
  403. setTimeout(function(){
  404. window.close();
  405. }, 2000);
  406. } else {
  407. //alert("test");
  408. }
  409. }, 3000);
  410. //document.getElementById("checkboxDisableJava1").checked = true;
  411.  
  412. // } else {
  413. // alert("Please check disable java applet and retry.");
  414. //}
  415. }
  416. });
  417.  
  418. // -----------------------Runs on YOUTUBE--------------------------------------------------------------
  419. //$(document).keydown(function (e) {
  420. // if (e.keyCode == 113) {
  421. //window.open("http://keepvid.com/?url=" + document.URL)
  422. // var a = document.createElement("a");
  423. //a.href = "http://catchvideo.net/?url=" + document.URL;
  424. //var evt = document.createEvent("MouseEvents");
  425. //evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
  426. //a.dispatchEvent(evt);
  427. //}
  428. //});