Skip to content

Instantly share code, notes, and snippets.

@ivanmem
Last active November 26, 2022 22:27
Show Gist options
  • Save ivanmem/812b182d4f2543bff9a26b2fb512cba8 to your computer and use it in GitHub Desktop.
Save ivanmem/812b182d4f2543bff9a26b2fb512cba8 to your computer and use it in GitHub Desktop.
tampermonkey script for safebooru.org to open the original image by right-clicking
// ==UserScript==
// @name safebooru-open-image-right-click
// @version 0.1
// @description script for safebooru.org to open the original image by right-clicking
// @author github.com/xeleoss
// @match *://safebooru.org/index.php*
// @icon https://www.google.com/s2/favicons?sz=64&domain=safebooru.org
// @run-at document-end
// @updateUrl https://gist.github.com/xeleoss/812b182d4f2543bff9a26b2fb512cba8
// ==/UserScript==
(function () {
'use strict';
console.log('safebooru original image by right-clicking working!');
document.querySelectorAll('a').forEach(a => {
const imgs = a.querySelectorAll('img');
if (imgs.length !== 1 || !a.href) {
return;
}
a.addEventListener('contextmenu', e => {
e.preventDefault();
const iframe = document.createElement('iframe');
iframe.setAttribute('src', a.href);
document.body.appendChild(iframe);
iframe.addEventListener('load', () => {
const image = iframe.contentDocument.getElementById('image');
if (image) {
window.open(image.src, '_blank');
}
document.body.removeChild(iframe);
});
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment