From 60247d44d1704cf7856d65c9da1f44bbddcd680e Mon Sep 17 00:00:00 2001 From: Big Duckie Date: Mon, 13 Jan 2025 09:36:13 -0700 Subject: [PATCH] Add hentai_foundry_downloader.user.js --- hentai_foundry_downloader.user.js | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 hentai_foundry_downloader.user.js diff --git a/hentai_foundry_downloader.user.js b/hentai_foundry_downloader.user.js new file mode 100644 index 0000000..50d4555 --- /dev/null +++ b/hentai_foundry_downloader.user.js @@ -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; + } + } + }); +})(); \ No newline at end of file