Pixiv raw image 403 Forbidden Fix

Fix Pixiv raw image 403

ของเมื่อวันที่ 25-06-2018 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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
        })
    }
})()