Only work for new design of reddit (beta reddit). Get a reddit video link from gif or video that hosted from reddit.
当前为
// ==UserScript==
// @name Reddit video link
// @namespace http://github.com/nakorndev
// @version 0.1
// @description Only work for new design of reddit (beta reddit). Get a reddit video link from gif or video that hosted from reddit.
// @author nakorndev
// @match https://www.reddit.com/*
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
$.ajax(window.location.href + '/.json')
.done(res => {
let output = res[0].data.children[0].data.secure_media;
if (output) {
let video = output.reddit_video.fallback_url;
let selector = document.querySelector('.icon.icon-upvote').parentNode.parentNode.parentNode;
let button = document.createElement('button');
let text = document.createTextNode('?');
button.style.cursor = 'pointer';
button.appendChild(text);
selector.prepend(button);
button.addEventListener('click', event => {
navigator.clipboard.writeText(video);
});
}
});
})();