Luke's VidDownloader

Allows you to download videos from reddit and youtube easily!

  1. // ==UserScript==
  2. // @name Luke's VidDownloader
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.8
  5. // @description Allows you to download videos from reddit and youtube easily!
  6. // @author You
  7. // @match https://www.reddit.com/r/*
  8. // @match https://www.youtube.com/*
  9. // @grant none
  10. // @run-at document-idle
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict'
  15. // Behave differently on different sites.
  16. const loc = window.location.href;
  17. if(loc.startsWith('https://www.reddit.com/r/')) {
  18. window.setInterval(function(){
  19. try {
  20. const a = document.getElementById('downloadfromplugin').id;
  21. } catch(e) {
  22. try {
  23. const videolink = window.location.href;
  24. const buttonZone = document.getElementsByClassName('PWY92ySDjTYrTAiutq4ty')[0];
  25. buttonZone.innerHTML += `<button id="downloadfromplugin" class="_2snJGyyGyyH38duHobOUKE m9hgq8-2 dAQykt b1zwxr-0 hxpTao" role="menuitem"><span class="m9hgq8-0 inRMrM"><i class="icon icon-embed _3MSdPVJwGxrpakz-e1MQhO s1htoir6-0 bpvrMF"></i></span><span class="m9hgq8-1 dRGkl">Download</span></button>`;
  26. const added = document.getElementById('downloadfromplugin');
  27.  
  28. added.addEventListener('click', function () {
  29. window.location.href = "https://viddit.red/?url=" + videolink;
  30. });
  31. } catch(error) {}
  32. }
  33. }, 200);
  34. }
  35. if(loc.toLowerCase().includes('youtube.com/watch?v=')) {
  36. const toStop = window.setInterval(function() {
  37. const viewCountElements = document.getElementsByClassName('yt-view-count-renderer');
  38. if(viewCountElements.length >= 1) {
  39. window.clearInterval(toStop);
  40. enableYoutubeLink();
  41. }
  42. }, 1000);
  43. }
  44. })();
  45. function enableYoutubeLink() {
  46. const loc = window.location.href;
  47. const viewCount = document.getElementsByClassName('yt-view-count-renderer')[0];
  48. const link = loc.replace('youtube', 'youtubepp');
  49. //viewCount.innerHTML = viewCount.innerHTML + ' <a href="' + link + '">(Download This Video)</a>';
  50. viewCount.innerHTML = viewCount.innerHTML + ' <button onclick="window.location.href=\'' + link + '\'">Download This Video</button>';
  51. }