Ripsave - Simple Reddit Video Downloader (with sound)

Lets you download reddit videos with sound using ripsave

目前為 2019-06-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Ripsave - Simple Reddit Video Downloader (with sound)
// @namespace    1N07
// @version      0.3.2
// @description  Lets you download reddit videos with sound using ripsave
// @author       1N07
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @match        https://www.reddit.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var baseUrl = "https://ripsave.com/download?video=";

    AddButtons();
    setInterval(AddButtons, 200);

    function AddButtons() {
        let target = $("div[data-test-id=post-content] .reddit-video-player-root:not(.addedDLButt)");
        if(target.length > 0) {
            let bar = target.parent().parent().next();
            let saveButt = bar.find("button[role=menuitem]:contains('save'):first");
            saveButt.after(saveButt.clone().addClass("downloadVid"));
            let dlButt = bar.find(".downloadVid");
            dlButt.find("i.icon").removeClass("icon-save").addClass("icon-downvote");
            dlButt.find("span:last").html('Download');

            dlButt.click(function(e){
                e.preventDefault();
                let dlUrl = window.location.href.split("#")[0].split("?")[0];
                window.open(baseUrl + dlUrl, "_blank");
            });

            target.addClass("addedDLButt");
        }

        let target2 = $("div.scrollerItem .reddit-video-player-root").not(".addedDLButt");
        target2.each(function(){
            let bar = $(this).parent().parent().parent().next();
            let saveButt = bar.find("button[role=menuitem]:contains('save'):first");
            saveButt.after(saveButt.clone().addClass("downloadVid"));
            let dlButt = bar.find(".downloadVid");
            dlButt.find("i.icon").removeClass("icon-save").addClass("icon-downvote");
            dlButt.find("span:last").html('Download');

            dlButt.click(function(e){
                e.preventDefault();
                let dlUrl = $(this).parent().parent().prev().prev().find("a[data-click-id=body]:first").prop("href").split("#")[0].split("?")[0];
                window.open(baseUrl + dlUrl, "_blank");
            });

            $(this).addClass("addedDLButt");
        });
    }

})();