Add hentai_foundry_downloader.user.js

This commit is contained in:
2025-01-13 09:36:13 -07:00
parent a929a1b042
commit 60247d44d1
+46
View File
@@ -0,0 +1,46 @@
// ==UserScript==
// @name Hentai Foundry Downloader
// @namespace BigDuckie.HentaiFoundryDownloader
// @version 2025.1.13
// @description A script to add Ctrl + S support to Hentai Foundry, as well as a convenient download button.
// @icon https://www.google.com/s2/favicons?sz=64&domain=hentai-foundry.com
// @author Big Duckie
// @copyright 2025, Big Duckie (https://bigduckie.dev)
// @license MIT
// @match *://*.hentai-foundry.com/pictures/user/*
// @grant GM_download
// ==/UserScript==
(function () {
'use strict';
const regex = /\/user\/(.*)\/(\d*)\/(.*)/g;
let m = regex.exec(window.location.href);
var imageFilename = `${m[1]}-${m[2]}-${m[3].replace("-", "_")}`;
var imageUrl = `https://pictures.hentai-foundry.com/${m[1].substring(0, 1).toLowerCase()}/${m[1]}/${m[2]}/${imageFilename}`
var button = document.createElement("a");
button.setAttribute("class", "linkButton picButton");
button.setAttribute("id", "downloadBtn");
button.setAttribute("title", "Download Image");
button.appendChild(document.createTextNode("⇩ DOWNLOAD IMAGE"));
button.addEventListener("click", event => {
GM_download(`${imageUrl}.jpg`, `${imageFilename}.jpg`)
GM_download(`${imageUrl}.png`, `${imageFilename}.png`)
});
document.querySelector("#picBox>div.boxfooter").append(button)
document.addEventListener("keydown", event => {
if (event.ctrlKey || event.metaKey) {
switch (String.fromCharCode(event.which).toLowerCase()) {
case 's':
event.preventDefault();
button.click();
break;
}
}
});
})();