Guest User

replaces v.redd.it links with the fallback video

a guest
Aug 21st, 2017
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         v.redd.it replacer
  3. // @version      0.1
  4. // @description  replaces v.redd.it links with the fallback url so it becomes a direct link
  5. // @author       Xpopy
  6. // @require      http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
  7. // @match        https://www.reddit.com/
  8. // @match        https://www.reddit.com/r/*
  9. // @grant        none
  10. // @run-at       document-end
  11. // ==/UserScript==
  12.  
  13. this.$ = this.jQuery = jQuery.noConflict(true);
  14.  
  15. (function() {
  16.     'use strict';
  17.  
  18.     //If you want to automatically remove the player, change the below line from "false" to "true"
  19.     var block_player = false;
  20.  
  21.  
  22.     $('.title[data-href-url^="https://v.redd.it"]').each(function() {
  23.  
  24.  
  25.         var link = this;
  26.         var outbound_url = $(this).attr('data-outbound-url');
  27.         var postID = outbound_url.split('?', 1)[0].split('_', 2)[1];
  28.         var parentPost = link.closest(".thing.link");
  29.         var subreddit = $(parentPost).attr('data-subreddit');
  30.         var url = "https://www.reddit.com/r/" + subreddit + "/comments/" + postID + "/.json";
  31.  
  32.         if(block_player){
  33.             $(parentPost).find('.expando-button').click();
  34.         }
  35.  
  36.         $.getJSON( url, function(data) {
  37.             var newLink = data[0].data.children[0].data.media.reddit_video.fallback_url;
  38.             console.log(link);
  39.             link.setAttribute('href', newLink);
  40.             link.setAttribute('data-outbound-url', newLink);
  41.             link.setAttribute('data-href-url', newLink);
  42.             parentPost.setAttribute('data-url', newLink);
  43.         });
  44.     });
  45. })();
Add Comment
Please, Sign In to add comment