YouTube Download

On youtube click the download link to download youtube video.

当前为 2016-06-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name YouTube Download
  3. // @namespace http://your.homepage/
  4. // @version 4.5.1
  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. var ThumbPRun = 0;
  22. var ThumbCurUrl;
  23. var WasPlaying;
  24. setInterval(function(){
  25. if(window.location.href.indexOf("you") > -1) {
  26. if ($('#watch7-headline').length > 0) {
  27. if ($('#downloadlnk').length > 0) {
  28. } else {
  29. if ($('.html5-player-chrome').length > 0) {
  30. if ($('#vidctrls').length > 0) {
  31. } else{
  32. document.querySelector('div.html5-player-chrome').id = 'vidctrls';
  33.  
  34. var c = document.createElement('img');
  35. c.src = "http://upload.wikimedia.org/wikipedia/commons/thumb/c/ca/Egypt_governorates_blank.png/597px-Egypt_governorates_blank.png";
  36. c.height = "30";
  37. c.width = "10";
  38. var b = document.createElement('img');
  39. b.src = "http://images.clipartpanda.com/square-clip-art-black-and-white-0999d59a768fa638a6f16f4a44299e29.png";
  40. b.height = "30";
  41. b.width = "30";
  42. b.title = "Download this video";
  43. b.onclick = function () {
  44. window.open("http://9xbuddy.com/download?url=" + document.URL);
  45. };
  46.  
  47. document.getElementById("vidctrls").appendChild(c);
  48. document.getElementById("vidctrls").appendChild(b);
  49. }
  50. } else {
  51. var downdiv = document.createElement("div");
  52. downdiv.id = "downdiv";
  53. var a = document.createElement('a');
  54. var linkText = document.createTextNode("Download");
  55. a.appendChild(linkText);
  56. a.id = "downloadlnk";
  57. a.title = "Download this video";
  58. a.onclick = function () {
  59. window.open("http://9xbuddy.com/download?url=" + document.URL);
  60. };
  61. var br3 = document.createElement('br');
  62. document.getElementById("watch7-headline").appendChild(br3);
  63. var br4 = document.createElement('br');
  64. document.getElementById("watch7-headline").appendChild(br4);
  65. var setimg = document.createElement('img');
  66. setimg.width = 27;
  67. setimg.length = 27;
  68. setimg.src = "https://qph.is.quoracdn.net/main-qimg-8237596d1a16264adb1900d01ea71f0a";
  69. var dwnimg = document.createElement('img');
  70. dwnimg.width = 27;
  71. dwnimg.length = 27;
  72. dwnimg.src = "http://www.clipartbest.com/cliparts/bTy/EX8/bTyEX8prc.png";
  73. var d = document.createElement('a');
  74. var linkText = document.createTextNode("Options");
  75. d.appendChild(linkText);
  76. d.id = "optionlnk";
  77. d.title = "Options";
  78. d.onclick = function () {
  79. var e = document.body;
  80. e.parentNode.removeChild(e);
  81. var body = document.createElement('body');
  82. document.getElementsByTagName('html')[0].appendChild(body);
  83. var chk1 = document.createElement('input');
  84. chk1.type = "checkbox";
  85. chk1.id = "chk1";
  86. document.getElementsByTagName('body')[0].appendChild(chk1);
  87. var label1 = document.createElement('label');
  88. //labe1l.htmlFor = "chk1";
  89. label1.appendChild(document.createTextNode('Auto HD + remove video ads'));
  90. document.getElementsByTagName('body')[0].appendChild(label1);
  91. var br = document.createElement('br');
  92. document.getElementsByTagName('body')[0].appendChild(br);
  93. var chk2 = document.createElement('input');
  94. chk2.type = "checkbox";
  95. chk2.id = "chk2";
  96. document.getElementsByTagName('body')[0].appendChild(chk2);
  97. var label2 = document.createElement('label');
  98. //labe12.htmlFor = "chk2";
  99. label2.appendChild(document.createTextNode('Loop videos'));
  100. document.getElementsByTagName('body')[0].appendChild(label2);
  101. var br4 = document.createElement('br');
  102. document.getElementsByTagName('body')[0].appendChild(br4);
  103. var chk3 = document.createElement('input');
  104. chk3.type = "checkbox";
  105. chk3.id = "chk3";
  106. document.getElementsByTagName('body')[0].appendChild(chk3);
  107. var label3 = document.createElement('label');
  108. //labe13.htmlFor = "chk2";
  109. label3.appendChild(document.createTextNode('Force Flash'));
  110. document.getElementsByTagName('body')[0].appendChild(label3);
  111. var br5 = document.createElement('br');
  112. document.getElementsByTagName('body')[0].appendChild(br5);
  113. var chk4 = document.createElement('input');
  114. chk4.type = "checkbox";
  115. chk4.id = "chk4";
  116. document.getElementsByTagName('body')[0].appendChild(chk4);
  117. var label4 = document.createElement('label');
  118. //labe1l.htmlFor = "chk1";
  119. label4.appendChild(document.createTextNode('Auto-Buffer'));
  120. document.getElementsByTagName('body')[0].appendChild(label4);
  121. var br3 = document.createElement('br');
  122. document.getElementsByTagName('body')[0].appendChild(br3);
  123. var chk5 = document.createElement('input');
  124. chk5.type = "checkbox";
  125. chk5.id = "chk5";
  126. document.getElementsByTagName('body')[0].appendChild(chk5);
  127. var label5 = document.createElement('label');
  128. //labe13.htmlFor = "chk2";
  129. label5.appendChild(document.createTextNode('Thumbnail Previews'));
  130. document.getElementsByTagName('body')[0].appendChild(label5);
  131. var br6 = document.createElement('br');
  132. document.getElementsByTagName('body')[0].appendChild(br6);
  133. var br2 = document.createElement('br');
  134. document.getElementsByTagName('body')[0].appendChild(br2);
  135. var appbtn = document.createElement('input');
  136. appbtn.type = "button";
  137. appbtn.value = "Apply";
  138. appbtn.onclick = function () {
  139. if (chk1.checked === true) {
  140. document.cookie =
  141. 'autohd=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/';
  142. } else {
  143. document.cookie = 'autohd=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/';
  144. }
  145. if (chk2.checked === true) {
  146. document.cookie =
  147. 'loop=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/';
  148. } else {
  149. document.cookie = 'loop=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/';
  150. }
  151. if (chk3.checked == true) {
  152. document.cookie =
  153. 'oldplyr=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/';
  154. } else {
  155. document.cookie = 'oldplyr=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/';
  156. }
  157. if (chk3.checked === true && chk1.checked === true) {
  158. alert("Auto-HD and Old Player are incompatible, please disable one of them.");
  159. } else {
  160. location.reload();
  161. }
  162. if (chk4.checked == true) {
  163. document.cookie =
  164. 'abuff=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
  165. } else {
  166. document.cookie = 'abuff=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'
  167. }
  168. if (chk5.checked == true) {
  169. document.cookie =
  170. 'ThumbP=test; expires=Fri, 3 Aug 2050 20:47:11 UTC; path=/'
  171. } else {
  172. document.cookie = 'ThumbP=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/'
  173. }
  174. }
  175. document.getElementsByTagName('body')[0].appendChild(appbtn);
  176. if (document.cookie.indexOf('autohd=')== -1) {
  177. chk1.checked = false;
  178. } else {
  179. chk1.checked = true;
  180. }
  181. if (document.cookie.indexOf('loop=')== -1) {
  182. chk2.checked = false;
  183. } else {
  184. chk2.checked = true;
  185. }
  186. if (document.cookie.indexOf('oldplyr=')== -1) {
  187. chk3.checked = false;
  188. } else {
  189. chk3.checked = true;
  190. }
  191. if (document.cookie.indexOf('abuff=')== -1) {
  192. chk4.checked = false;
  193. } else {
  194. chk4.checked = true;
  195. }
  196. if (document.cookie.indexOf('ThumbP=')== -1) {
  197. chk5.checked = false;
  198. } else {
  199. chk5.checked = true;
  200. }
  201. };
  202. //document.body.appendChild(a);
  203. document.getElementById("watch7-headline").appendChild(downdiv);
  204. document.getElementById("downdiv").appendChild(dwnimg);
  205. document.getElementById("downdiv").appendChild(a);
  206. document.getElementById("downdiv").appendChild(br3);
  207. document.getElementById("downdiv").appendChild(br4);
  208. document.getElementById("downdiv").appendChild(setimg);
  209. document.getElementById("downdiv").appendChild(d);
  210. document.getElementById("downloadlnk").style.fontSize = "x-large";
  211. document.getElementById("optionlnk").style.fontSize = "x-large";
  212. var br1 = document.createElement('br');
  213. document.getElementById("watch7-headline").appendChild(br1);
  214. var br2 = document.createElement('br');
  215. document.getElementById("watch7-headline").appendChild(br2);
  216. }
  217. }
  218. }
  219. }
  220.  
  221. if (document.cookie.indexOf('autohd=')== -1) {
  222. //no cookie
  223. } else {
  224. if (beforestop == false) {
  225. var myNode = document.getElementById("movie_player");
  226. while (myNode.firstChild) {
  227. myNode.removeChild(myNode.firstChild);
  228. beforestop = true;
  229. }
  230.  
  231. var url = document.URL;
  232. url = url.substring(0, url.length - 8);
  233. var vidid = url.substring(url.indexOf('=')+1);
  234. var player = document.createElement('iframe');
  235. player.id = "player1";
  236. player.width = "1920";
  237. player.height = "1080";
  238. player.src = "https://www.youtube.com/embed/" + vidid + "?rel=0&autoplay=1&VQ=HD720";
  239. player.frameborder = "0";
  240. document.getElementById("movie_player").appendChild(player);
  241. document.getElementById("player1").setAttribute("allowfullscreen", "true");
  242. setTimeout(function(){
  243. document.getElementById("player1").width = "855";
  244. document.getElementById("player1").height = "480";
  245. }, 15000);
  246. }
  247. var url = document.URL;
  248. var idtest = url.substring(url.indexOf('=')+1);
  249. if (idtest === vidid){
  250. } else {
  251. }
  252. }
  253. if (document.URL.indexOf('watch?v=') > -1) {
  254. if (document.cookie.indexOf('oldplyr=')== -1) {
  255. if (document.URL.indexOf("&nohtml5=1") > -1) {
  256. var strpos = document.URL.indexOf("&nohtml5=1");
  257. //strpos = strpos + 9;
  258. var nurl = "";
  259. for (i = 0; i <= document.URL.length; i++) {
  260. if (i >= strpos && i <= strpos + 9) {
  261. //delete by ignoring
  262. } else {
  263. nurl = nurl + document.URL.charAt(i);
  264. }
  265. }
  266. window.location.assign(nurl);
  267. console.log(nurl);
  268. }
  269. } else {
  270. if (document.URL.indexOf("&nohtml5=1") > -1) {
  271. } else {
  272. window.location.assign(document.URL + "&nohtml5=1");
  273. }
  274. }
  275. }
  276. }, 2000);
  277. setInterval(function(){
  278. if (document.cookie.indexOf('autohd=')== -1) {
  279. } else {
  280. if(window.location.href.indexOf("you") > -1) {
  281. if(window.location.href.indexOf("embed") > -1) {
  282. } else {
  283. if(window.location.href.indexOf("reldone") > -1) {
  284. } else {
  285. window.location.assign(document.URL + "#reldone");
  286. location.reload();
  287. }
  288. }
  289. }
  290. }
  291. }, 4000);
  292. //ThumbP Code
  293. setInterval(function(){
  294. if (document.cookie.indexOf('ThumbP=')== -1) {
  295. } else {
  296. if(window.location.href.indexOf("you") > -1) {
  297. if(window.location.href.indexOf("watch") > -1) { //video pages
  298. if (document.getElementsByClassName("yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related").length == ThumbPRun) {
  299. } else {
  300. var vwidth = document.getElementsByClassName("yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related")[ThumbPRun].children[0].width;
  301. var vheight = document.getElementsByClassName("yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related")[ThumbPRun].childNodes[0].height;
  302. //document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].removeChild(document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].children[0]); -delete thumbnail image (old)
  303. var Tvid = document.createElement("iframe");
  304. Tvid.src = "https://www.youtube.com/embed/" + document.getElementsByClassName("yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related")[ThumbPRun].parentNode.href.split('=')[1] + "?controls=0&iv_load_policy=3&autoplay=1&showinfo=0&vq=small#ThumbP";
  305. Tvid.width = vwidth;
  306. Tvid.height = vheight;
  307. Tvid.style.display = "none";
  308. document.getElementsByClassName("yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related")[ThumbPRun].appendChild(Tvid);
  309. document.getElementsByClassName("yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related")[ThumbPRun].onmouseout=function(){
  310. this.children[0].style.display = "inline";
  311. this.children[1].style.display = "none";
  312. if (WasPlaying === true) {
  313. document.getElementsByClassName("video-stream html5-main-video")[0].play();
  314. WasPlaying = false;
  315. }
  316. };
  317. document.getElementsByClassName("yt-uix-simple-thumb-wrap yt-uix-simple-thumb-related")[ThumbPRun].onmouseover=function(){
  318. this.children[0].style.display = "none";
  319. this.children[1].style.display = "inline";
  320. if (document.getElementsByClassName("video-stream html5-main-video")[0].paused === false) {
  321. WasPlaying = true;
  322. document.getElementsByClassName("video-stream html5-main-video")[0].pause();
  323. }
  324. };
  325. ThumbPRun = ThumbPRun + 1
  326. }
  327. } else { // other pages
  328. if (document.getElementsByClassName("yt-thumb-simple").length == ThumbPRun) {
  329. } else {
  330. var vwidth = document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].children[0].width;
  331. var vheight = document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].childNodes[0].height;
  332. //document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].removeChild(document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].children[0]); -delete thumbnail image (old)
  333. var Tvid = document.createElement("iframe");
  334. Tvid.src = "https://www.youtube.com/embed/" + document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].parentNode.parentNode.href.split('=')[1] + "?controls=0&iv_load_policy=3&autoplay=1&showinfo=0&vq=small#ThumbP";
  335. Tvid.width = vwidth;
  336. Tvid.height = vheight;
  337. Tvid.style.display = "none";
  338. document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].appendChild(Tvid);
  339. document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].onmouseout=function(){
  340. this.children[0].style.display = "inline";
  341. this.children[1].style.display = "none";
  342. };
  343. document.getElementsByClassName("yt-thumb-simple")[ThumbPRun].onmouseover=function(){
  344. this.children[0].style.display = "none";
  345. this.children[1].style.display = "inline";
  346. };
  347. ThumbPRun = ThumbPRun + 1
  348. }
  349. }
  350. }
  351. }
  352. }, 500);
  353. setInterval(function(){
  354. if (document.cookie.indexOf('ThumbP=')== -1) {
  355. } else {
  356. if(window.location.href.indexOf("embed") > -1) {
  357. } else {
  358. if (ThumbCurUrl == document.URL) {
  359.  
  360. } else {
  361. ThumbPRun = 0;
  362. ThumbCurUrl = document.URL;
  363. }
  364. }
  365. if(window.location.href.indexOf("ThumbP") > -1) {
  366. if(window.location.href.indexOf("embed") > -1) {
  367. if ($('#player:hover').length != 0) {
  368. document.getElementsByClassName("video-stream html5-main-video")[0].play();
  369. } else {
  370. document.getElementsByClassName("video-stream html5-main-video")[0].pause();
  371. }
  372. } else {
  373. }
  374. }
  375. }
  376. }, 200);
  377. setInterval(function(){
  378. if (window.location.href.indexOf("watch") > -1){
  379. if (document.cookie.indexOf('loop=')== -1){
  380. } else {
  381. var curtime = document.getElementsByClassName('ytp-time-current')[0].innerHTML;
  382. var endtime = document.getElementsByClassName('ytp-time-duration')[0].innerHTML;
  383. if (curtime === endtime){
  384. document.getElementsByClassName("ytp-play-button ytp-button")[0].click();
  385. }
  386. }
  387. }
  388. }, 1000);
  389. setInterval(function(){
  390. if (window.location.href.indexOf("embed") > -1){
  391. if (document.cookie.indexOf('loop=')== -1){
  392. } else {
  393. var curtime = document.getElementsByClassName('ytp-time-current')[0].innerHTML;
  394. var endtime = document.getElementsByClassName('ytp-time-duration')[0].innerHTML;
  395. if (curtime === endtime){
  396. document.getElementsByClassName("ytp-play-button ytp-button")[0].click();
  397. }
  398. }
  399. }
  400. }, 1000);
  401. function resetVid() {
  402. }
  403. var done = false;
  404. var cururl = document.URL;
  405. setInterval(function(){
  406. if (window.location.href.indexOf("you") > -1){
  407. if (document.cookie.indexOf('abuff=')== -1){
  408. } else {
  409. if (document.getElementsByClassName('ytp-load-progress')[0].style.transform === "scaleX(1)") {
  410. //setInterval(function(){
  411. if (done == false) {
  412. var vid = document.getElementsByClassName('video-stream html5-main-video')[0];
  413. if (vid.currentTime < 20) {
  414. document.getElementsByClassName('video-stream html5-main-video')[0].currentTime = 0;
  415. done = true;
  416. } else {
  417. var tt = document.getElementsByClassName('video-stream html5-main-video')[0].currentTime;
  418. var ttt = tt - 15;
  419. //alert(tt);
  420. //alert(ttt);
  421. document.getElementsByClassName('video-stream html5-main-video')[0].currentTime = ttt;
  422. }
  423. }
  424. //}, 1000);
  425. }
  426. if (document.getElementsByClassName('ytp-load-progress')[0].style.transform === "scaleX(1)") {
  427. } else {
  428. done = false;
  429. }
  430. if (document.getElementById("movie_player").style.display === "inline") {
  431. } else {
  432. document.getElementById("movie_player").style.display = "none";
  433. }
  434. if (cururl === document.URL) {
  435. } else {
  436. location.reload();
  437. }
  438. }
  439. }
  440. }, 2000);
  441. setInterval(function(){
  442. if (window.location.href.indexOf("you") > -1){
  443. if (document.cookie.indexOf('abuff=')== -1){
  444. } else {
  445. if (document.getElementById("movie_player").style.display === "none") {
  446. document.getElementsByClassName('video-stream html5-main-video')[0].muted = true;
  447. if (document.getElementsByClassName('ytp-load-progress')[0].style.transform === "scaleX(1)" && done == true) {
  448. document.getElementById("movie_player").style.display = "inline";
  449. document.getElementsByClassName('video-stream html5-main-video')[0].muted = false;
  450. document.getElementById("player-api").removeChild(document.getElementById("abuff-img-0"));
  451. }
  452. }
  453. }
  454. }
  455. }, 2000);
  456. //setTimeout(function(){
  457. if (window.location.href.indexOf("you") > -1){
  458. if (document.cookie.indexOf('abuff') > -1){
  459. var abuffimg = document.createElement("img");
  460. abuffimg.id = "abuff-img-0";
  461. //abuffimg.className = "player-height";
  462. abuffimg.src = "http://cfay-bus.weebly.com/files/theme/auto-buff.gif";
  463. document.getElementById("player-api").appendChild(abuffimg);
  464. document.getElementById("abuff-img-0").height = "480";
  465. document.getElementById("abuff-img-0").width = "854";
  466. }
  467. }
  468. //}, 4000);
  469. // --------------------------RUNS ON 9xbuddy TO DOWNLOAD VIDEO--------------------------------------------
  470. if(window.location.href.indexOf("buddy") > -1) {
  471. /*var iDiv = document.createElement('div');
  472.  
  473. iDiv.id = 'block';
  474. iDiv.className = 'block';
  475. document.getElementsByTagName('body')[0].appendChild(iDiv);
  476. iDiv.height = window.height();
  477. iDiv.width = window.width();
  478. $(iDiv).css({
  479. position: 'fixed',
  480. top: 0,
  481. right: 0,
  482. bottom: 0,
  483. left: 0,
  484. zIndex: 999
  485. });*/
  486.  
  487.  
  488.  
  489. //if(!$('#javaUserWarning').is(':visible')) {
  490. setInterval(function(){
  491. if ($(".download-link-list")[0]){
  492. var els = document.getElementsByClassName('download-link-download lbcolor');
  493. var element = $('.download-about-section li');
  494. var zali = element[1];
  495. var zalitext = zali.innerHTML;
  496. if (zalitext.match("VEVO")) {
  497. var li = els[1]
  498. li.id = 'dwnload';
  499. var t = $('#dwnload a').attr('href');
  500. } else {
  501. var li = els[2]
  502. li.id = 'dwnload';
  503. var t = $('#dwnload a').attr('href');
  504. }
  505. window.location = t
  506. setTimeout(function(){
  507. window.close();
  508. }, 2000);
  509. } else {
  510. //alert("test");
  511. }
  512. }, 3000);
  513. //document.getElementById("checkboxDisableJava1").checked = true;
  514.  
  515. // } else {
  516. // alert("Please check disable java applet and retry.");
  517. //}
  518. }
  519. });
  520.  
  521. // -----------------------Runs on YOUTUBE--------------------------------------------------------------
  522. //$(document).keydown(function (e) {
  523. // if (e.keyCode == 113) {
  524. //window.open("http://keepvid.com/?url=" + document.URL)
  525. // var a = document.createElement("a");
  526. //a.href = "http://catchvideo.net/?url=" + document.URL;
  527. //var evt = document.createEvent("MouseEvents");
  528. //evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
  529. //a.dispatchEvent(evt);
  530. //}
  531. //});