Last active
December 23, 2020 00:00
-
-
Save Halkcyon/1474687f8447495b3ea724c9ea97bebb to your computer and use it in GitHub Desktop.
Creates a button to copy Reddit markdown to clipboard from Giphy for embedding gifs in Reddit comments.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @noframes | |
// @name giphy-reddit | |
// @namespace mburszley | |
// @description Creates a button to copy Reddit markdown to clipboard from Giphy for embedding gifs in Reddit comments. | |
// @grant clipboardWrite | |
// @match https://giphy.com/* | |
// @version 6 | |
// @downloadURL https://gist.github.com/mburszley/1474687f8447495b3ea724c9ea97bebb/raw/giphy-reddit.user.js | |
// @updateURL https://gist.github.com/mburszley/1474687f8447495b3ea724c9ea97bebb/raw/giphy-reddit.user.js | |
// ==/UserScript== | |
/// [`src`](https://gist.github.com/mburszley/1474687f8447495b3ea724c9ea97bebb) | |
/// footnote: if you install the script through the gist's raw link, | |
/// auto-update will not work as it pins to the latest revision at that point | |
/// in time | |
let node = document.createElement('textarea'); | |
node.id = 'clipboard-write'; | |
node.hidden = true; | |
document.body.appendChild(node); | |
node = document.getElementById('clipboard-write'); | |
let btn = document.createElement('button'); | |
btn.innerText = 'REDDIT'; | |
btn.style.position = 'fixed'; | |
btn.style.top = 0; | |
btn.style.left = 0; | |
document.body.appendChild(btn); | |
btn.addEventListener('click', () => { | |
let hash = location.href.split('-').pop(); | |
let markdown = ``; | |
console.info(`giphy hash: ${hash}`); | |
console.info(`reddit markdown: ${markdown}`); | |
node.value = markdown; | |
node.select(); | |
document.execCommand('copy'); | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment