Pixiv Replace With Original

Replace Pixiv image with original image

目前為 2018-06-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pixiv Replace With Original
// @namespace    https://blog.maple3142.net/
// @version      0.2
// @description  Replace Pixiv image with original image
// @author       maple3142
// @match        https://www.pixiv.net/member_illust.php?mode=medium&illust_id=*
// @match        https://www.pixiv.net/member_illust.php?mode=manga&illust_id=*
// @run-at       document-start
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict'
    const $=s=>document.querySelector(s)
    const $$=s=>[...document.querySelectorAll(s)]
    const params=new URLSearchParams(location.search)
    const mode=params.get('mode')
    function createSafeReadonlyProperty(obj,prop,value){
        let x={value}
        Object.defineProperty(obj,prop,{
            get: ()=>x.value,
            set: ()=>{}
        })
        return {value,update:nval=>x.value=nval}
    }
    if(mode==='medium'){
        const PREFIX=Math.random().toString(36)
        Object.defineProperty(Object.prototype,'props',{
            set(v){
                this[PREFIX+'_props']=v
                if(v.urls)onTarget(this)
            },
            get(v){
                return this[PREFIX+'_props']
            }
        })
        function onTarget(target){
            const url=target.props.urls.original
            target.props.urls=new Proxy({},{
                get: ()=>url
            })
        }
    }
    else if(mode==='manga'){
        const id=params.get('illust_id')
        const p=fetch(`/ajax/illust/${id}`,{ credentials: 'same-origin' }).then(r=>r.json()).then(r=>r.body).then(data=>{
            const url=data.urls.original
            const ar=[]
            for(let i=0;i<data.pageCount;i++){
                ar.push(url.replace('p0',`p${i}`))
            }
            return ar
        })
        addEventListener('load',()=>{
            p.then(ar=>{
                const imgs=$$('img.image')
                console.log(imgs,ar)
                for(let i=0;i<ar.length;i++){
                    imgs[i].src=imgs[i].dataset.src=ar[i]
                }
            })
        })
    }
})()