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. function createSafeReadonlyProperty(obj,prop,value){
  20. let x={value}
  21. Object.defineProperty(obj,prop,{
  22. get: ()=>x.value,
  23. set: ()=>{}
  24. })
  25. return {value,update:nval=>x.value=nval}
  26. }
  27. if(mode==='medium'){
  28. const PREFIX=Math.random().toString(36)
  29. Object.defineProperty(Object.prototype,'props',{
  30. set(v){
  31. this[PREFIX+'_props']=v
  32. if(v.urls)onTarget(this)
  33. },
  34. get(v){
  35. return this[PREFIX+'_props']
  36. }
  37. })
  38. function onTarget(target){
  39. const url=target.props.urls.original
  40. target.props.urls=new Proxy({},{
  41. get: ()=>url
  42. })
  43. }
  44. }
  45. else if(mode==='manga'){
  46. const id=params.get('illust_id')
  47. const p=fetch(`/ajax/illust/${id}`,{ credentials: 'same-origin' }).then(r=>r.json()).then(r=>r.body).then(data=>{
  48. const url=data.urls.original
  49. const ar=[]
  50. for(let i=0;i<data.pageCount;i++){
  51. ar.push(url.replace('p0',`p${i}`))
  52. }
  53. return ar
  54. })
  55. addEventListener('load',()=>{
  56. p.then(ar=>{
  57. const imgs=$$('img.image')
  58. console.log(imgs,ar)
  59. for(let i=0;i<ar.length;i++){
  60. imgs[i].src=imgs[i].dataset.src=ar[i]
  61. }
  62. })
  63. })
  64. }
  65. })()