Skip to content

Instantly share code, notes, and snippets.

@Halkcyon
Last active December 23, 2020 00:00
Show Gist options
  • Save Halkcyon/1474687f8447495b3ea724c9ea97bebb to your computer and use it in GitHub Desktop.
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.
// ==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 = `![gif](giphy|${hash}|downsized)`;
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