Pixiv raw image 403 Forbidden Fix

Fix Pixiv raw image 403

目前为 2018-06-25 提交的版本。查看 最新版本

// ==UserScript==
// @name         Pixiv raw image 403 Forbidden Fix
// @namespace    https://blog.maple3142.net/
// @version      0.1
// @description  Fix Pixiv raw image 403
// @author       maple3142
// @match        https://i.pximg.net/*
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict'
    const params=new URLSearchParams(location.search)
    const removeAllChild=el=>{
        while(el.firstChild)el.removeChild(el.firstChild)
    }
    function download(url,name=true){
        const a=document.createElement('a')
        a.href=url
        a.download=name
        document.body.appendChild(a)
        a.click()
        a.remove()
    }
    if(document.title==='403 Forbidden'){
        const fname=location.pathname.split('/').slice(-1)[0]
        GM_xmlhttpRequest({
            method: 'GET',
            url: location.href,
            headers: {
                Referer: `https://www.pixiv.net/`
            },
            responseType: 'blob',
            onload: xhr=>{
                const blob=xhr.response
                const url=URL.createObjectURL(blob)
                const img=new Image()
                img.src=url
                removeAllChild(document.body)
                document.body.appendChild(img)
                img.oncontextmenu=e=>{
                    e.preventDefault()
                    if(confirm('Download Image?')){
                        download(url,fname)
                    }
                }
            },
            onerror: console.error
        })
    }
})()

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址