CryonicWraith / Hentai Foundry Download

// ==UserScript==
// @name         Hentai Foundry Download
// @namespace    cryonicwraith.hfoundrydownloader
// @author       CryonicWraith
// @copyright    2017, CryonicWraith
// @version      1.5
// @description  A new script to add Ctrl + S support to Hentai Foundry, as well as a convenient download button.
// @match        *://*.hentai-foundry.com/pictures/user/*
// @updateURL    https://openuserjs.org/meta/CryonicWraith/Hentai_Foundry_Download.meta.js
// @downloadURL  https://openuserjs.org/src/scripts/CryonicWraith/Hentai_Foundry_Download.user.js
// @require      https://code.jquery.com/jquery-3.2.1.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    if (!$("#picBox")[0]) {
        return 0;
    }

    const regex = /\/user\/(.*)\/(\d*)\/(.*)/g;
    let m;

    m = regex.exec(window.location.href);

    var imageUrl = "//pictures.hentai-foundry.com/" + m[1].substring(0, 1).toLowerCase() + "/" + m[1] + "/" + m[2] + "/" + m[1] + "-" + m[2] + "-" + m[3] + ".jpg";

    $("#picBox>div.boxfooter").append($("<a/>")
                                      .attr("id", "downloadBtn")
                                      .attr("class", "linkButton picButton")
                                      .attr("title", "Download Image")
                                      .attr("download", "")
                                      .attr("href", imageUrl)
                                      .text("⇩ DOWNLOAD IMAGE"));

    $(window).bind('keydown', function (event) {
        if (event.ctrlKey || event.metaKey) {
            switch (String.fromCharCode(event.which).toLowerCase()) {
                case 's':
                    event.preventDefault();
                    $("#downloadBtn")[0].click();
                    break;
            }
        }
    });
})();