Skip to content

Instantly share code, notes, and snippets.

@BytewaveMLP
Last active February 28, 2022 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BytewaveMLP/6de9eaf98d88aecd71b3dcefcd1db28c to your computer and use it in GitHub Desktop.
Save BytewaveMLP/6de9eaf98d88aecd71b3dcefcd1db28c to your computer and use it in GitHub Desktop.
Derpibooru "Share" button userscript
// ==UserScript==
// @name Derpibooru "Share" button
// @namespace https://code.horse
// @version 0.1
// @description Add a "share" button to Derpibooru to copy the current link to clipboard
// @author Bytewave
// @match https://derpibooru.org/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=derpibooru.org
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
const IMAGE_ID_PATTERN = /\/(\d+)/;
const metabar = document.querySelector('.image-metabar');
if (!metabar || !metabar.hasChildNodes()) return;
const links = metabar.childNodes[3];
if (!links) return;
const shareLinks = document.createElement('a');
shareLinks.href = '#';
shareLinks.title = 'Copy link to clipboard';
const shareIcon = document.createElement('i');
shareIcon.className = 'fa fa-share-alt';
shareLinks.appendChild(shareIcon);
shareLinks.appendChild(document.createTextNode(' Share'));
shareLinks.addEventListener('click', function(e) {
e.preventDefault();
const imageId = IMAGE_ID_PATTERN.exec(window.location.pathname)[1];
if (!imageId) return;
const url = `https://derpibooru.org/images/${imageId}`;
GM_setClipboard(url);
});
links.appendChild(shareLinks);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment