Pixiv Replace With Original

Replace Pixiv image with original image

当前为 2018-06-25 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pixiv Replace With Original
  3. // @namespace https://blog.maple3142.net/
  4. // @version 0.2
  5. // @description Replace Pixiv image with original image
  6. // @author maple3142
  7. // @match https://www.pixiv.net/member_illust.php?mode=medium&illust_id=*
  8. // @match https://www.pixiv.net/member_illust.php?mode=manga&illust_id=*
  9. // @run-at document-start
  10. // @grant unsafeWindow
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict'
  15. const $=s=>document.querySelector(s)
  16. const $$=s=>[...document.querySelectorAll(s)]
  17. const params=new URLSearchParams(location.search)
  18. const mode=params.get('mode')
  19. if(mode==='medium'){
  20. const PREFIX=Math.random().toString(36)
  21. Object.defineProperty(Object.prototype,'props',{
  22. set(v){
  23. this[PREFIX+'_props']=v
  24. if(v.urls)onTarget(this)
  25. },
  26. get(v){
  27. return this[PREFIX+'_props']
  28. }
  29. })
  30. function onTarget(target){
  31. const url=target.props.urls.original
  32. target.props.urls=new Proxy({},{
  33. get: ()=>url
  34. })
  35. }
  36. }
  37. else if(mode==='manga'){
  38. const id=params.get('illust_id')
  39. const p=fetch(`/ajax/illust/${id}`,{ credentials: 'same-origin' }).then(r=>r.json()).then(r=>r.body).then(data=>{
  40. const url=data.urls.original
  41. const ar=[]
  42. for(let i=0;i<data.pageCount;i++){
  43. ar.push(url.replace('p0',`p${i}`))
  44. }
  45. return ar
  46. })
  47. addEventListener('load',()=>{
  48. p.then(ar=>{
  49. const imgs=$$('img.image')
  50. console.log(imgs,ar)
  51. for(let i=0;i<ar.length;i++){
  52. imgs[i].src=imgs[i].dataset.src=ar[i]
  53. }
  54. })
  55. })
  56. }
  57. })()