Greasy Fork 还支持 简体中文。

Reddit Video Downloader

Adds button to direct link or download the stupidly hard to save or share directly reddit videos. Designed to work on new Reddit only. Buttons appear when viewing the specific post -- does not work on preview/expand on post listing pages.

目前為 2022-03-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Reddit Video Downloader
// @namespace    https://lawrenzo.com/p/reddit-video-downloader
// @version      0.3.1
// @description  Adds button to direct link or download the stupidly hard to save or share directly reddit videos. Designed to work on new Reddit only. Buttons appear when viewing the specific post -- does not work on preview/expand on post listing pages.
// @author       Lawrence Sim
// @license      WTFPL (http://www.wtfpl.net)
// @grant        none
// @match        *://*.reddit.com/*
// ==/UserScript==
'use strict';
(function() {
    var defaultStyles = {
        "margin":        "0.4em",
        "font-size":     "0.8em",
        "padding":       "0.4em 0.6em",
        "border-radius": "4px",
        "border":        "1px solid #d9d9d9",
        "background":    "#fff"
    };
    function createBtn(parent, opts) {
        let a = document.createElement("a"),
            btn = document.createElement("button");
        a.append(btn);
        a.href= opts.href;
        a.target = "_blank";
        btn.innerHTML = opts.html;
        for(let key in defaultStyles) {
            btn.style[key] = defaultStyles[key];
        }
        parent.append(a);
    }
    function addLinks(mutated, observer) {
        let videoElem = document.querySelector("[data-test-id='post-content'] video");
        if(!videoElem) return;
        if(videoElem.getAttribute("vlinked")) return observer && observer.disconnect();
        videoElem.setAttribute("vlinked", 1);
        fetch(window.location.href.split("?")[0].replace(/\/$/, "")+".json")
            .then(res => {
                if(!res && !res.ok) throw Error(res.statusText);
                return res.json();
            })
            .then(json => {
                let postData, vidData, contentDiv;
                try {
                    postData = json[0].data.children[0].data;
                    if(!postData.secure_media && postData.crosspost_parent_list && postData.crosspost_parent_list.length) {
                        postData = postData.crosspost_parent_list[0];
                    }
                    vidData = postData.secure_media.reddit_video;
                } catch(e) { }
                if(!vidData) return console.log(postData || json);
                console.log(vidData);
                contentDiv = videoElem.closest("[data-test-id='post-content']");
                createBtn(contentDiv, {
                    href: vidData.fallback_url,
                    html: "Direct Video Link (no sound)"
                });
                createBtn(contentDiv, {
                    href: window.location.href.replace(/reddit.com\//, "redditsave.com/info?url="),
                    html: "Download via RedditSave"
                });
                createBtn(contentDiv, {
                    href: window.location.href.replace(/reddit.com/, "reddit.tube"),
                    html: "Download via Reddit.Tube"
                });
            })
            .catch(err => console.log(err) && null);
        if(observer) observer.disconnect();
    }
    addLinks();
    (new MutationObserver(addLinks)).observe(document.body, {childList:true, subtree:true});
})();