Sleazy Fork is available in English.

xfolio解除保存限制

在图片浏览界面生成保存按钮,点按即可保存到浏览器默认下载目录

// ==UserScript==
// @name         xfolio解除保存限制
// @namespace    http://tampermonkey.net/
// @version      1.0.0
// @description  在图片浏览界面生成保存按钮,点按即可保存到浏览器默认下载目录
// @author       monat151
// @match        http*://xfolio.jp/fullscale_image?*
// @grant        none
// ==/UserScript==

(function() {
    const _CONFIG_MAX_RETRY_TIMES = 50 // 最大重试次数
    'use strict';
    let retry_count = 0

    const getImageId = () => {
        const regex = /(?<=image_id=)\d+/g;
        const matches = document.location.href.match(regex)
        return matches.length ? matches[0] : 'unknownImage'
    }
    const downloadImage = (imageSrc) => {
        const link = document.createElement('a')
        link.href = imageSrc
        link.download = getImageId() + '.png'
        link.click()
    }
    const tryGenerateDownloadButton = () => {
        try {
            const imageSrc = document.body.children[0].src
            const downloadBtn = document.createElement('button');
            downloadBtn.innerHTML = `下载图片`
            downloadBtn.style = 'margin: 1%;'
            downloadBtn.addEventListener('click', function() {
                downloadImage(imageSrc)
            })
            document.body.before(downloadBtn)
        } catch {
            retry_count++
            if (retry_count > _CONFIG_MAX_RETRY_TIMES) {
                console.error('[用户脚本.xfolio解除保存限制] 生成按钮失败并且已达到最大重试次数。')
            } else {
                console.warn('[用户脚本.xfolio解除保存限制] 生成按钮失败,图片可能未加载完成。即将重试..')
                tryGenerateDownloadButton()
            }
        }
    }
    setTimeout(() => {
        tryGenerateDownloadButton()
    },500);
})();