返回首頁 

Greasy Fork is available in English.

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.

ของเมื่อวันที่ 08-03-2022 ดู เวอร์ชันล่าสุด

// ==UserScript==// @name         Reddit Video Downloader// @namespace    https://lawrenzo.com/p/reddit-video-downloader// @version      0.5.0// @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","cursor":        "pointer"};function createBtn(parent, opts) {let btn = document.createElement("button");btn.innerHTML = opts.html;for(let key in defaultStyles) {btn.style[key] = defaultStyles[key];}if(opts.disabled) {btn.disabled = true;btn.style.background = "#bbb";btn.style.cursor = "wait";}if(opts.href) btn.addEventListener('click', () => window.open(opts.href));parent.append(btn);return btn;}function addLinks() {let contentDiv = document.querySelector("[data-test-id='post-content']"),videoElem = contentDiv && contentDiv.querySelector("video");if(!videoElem || videoElem.getAttribute("vlinked")) return;let directBtn = createBtn(contentDiv, {html: "Direct Video Link (no sound)",disabled: true});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"});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;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);directBtn.addEventListener('click', () => window.open(vidData.fallback_url));directBtn.disabled = false;directBtn.style.background = defaultStyles.background;directBtn.style.cursor = defaultStyles.cursor;}).catch(err => console.log(err) && null);}addLinks();if(!window.redditWatcher) {(new MutationObserver(addLinks)).observe(document.body, {childList:true, subtree:true});} else {window.redditWatcher.body.onUpdate(addLinks);}})();