Last active
November 26, 2022 22:27
-
-
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
This file contains 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== | |
// @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