Skip to content

Instantly share code, notes, and snippets.

@vaaas
Last active March 8, 2024 02:54
Show Gist options
  • Save vaaas/08b7c2d5a6b0ecb1e37ef0a1e3bc17c4 to your computer and use it in GitHub Desktop.
Save vaaas/08b7c2d5a6b0ecb1e37ef0a1e3bc17c4 to your computer and use it in GitHub Desktop.
rg download button
// ==UserScript==
// @name RG Download Button
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add download button
// @author Vasileios Pasialiokis
// @match https://www.redgifs.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
const empty = x => x.innerHTML = ''
const throttled = (f, t) => {
let id = null
function run() {
id = null
f()
}
return () => {
if (id) return
f()
id = setTimeout(run, t)
}
}
function E(tagname, props, children) {
const e = document.createElement(tagname)
if (props)
for (const k in props)
e[k] = props[k]
if (children)
for (const x of children)
if (typeof x === 'string')
e.appendChild(document.createTextNode(x))
else
e.appendChild(x)
return e
}
const anchors = x => x.children[0].tagName === 'A'
function on_mutation() {
const last_items = document.querySelectorAll('.SideBarWrap > ul > li:last-child')
for (const x of last_items) {
if (anchors(x)) continue
empty(x)
x.appendChild(make_anchor(x))
x.style.paddingTop = '2rem'
}
}
function make_anchor(elem) {
return E('a', {
href: elem.parentElement.parentElement.parentElement.querySelector('video').src,
style: 'font-size: 2rem;',
target: '_blank',
}, [ '⬇️' ])
}
new MutationObserver(throttled(on_mutation, 500))
.observe(document.body, { subtree: true, childList: true })
})()
@TheDegenerateDev5150
Copy link

👌🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment