Pixiv raw image 403 Forbidden Fix

Fix Pixiv raw image 403

Από την 25/06/2018. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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