🏠 Home 

S1长图缩小

2020/2/22 下午4:38:25


Install this script?
  1. // ==UserScript==
  2. // @name S1长图缩小
  3. // @namespace Violentmonkey Scripts
  4. // @match *://*.saraba1st.com/2b/*
  5. // @grant none
  6. // @version 2.3
  7. // @author -
  8. // @run-at document-idle
  9. // @description 2020/2/22 下午4:38:25
  10. // ==/UserScript==
  11. function scale() {
  12. Array.from(document.querySelectorAll('.pct')).map(el => {
  13. Array.from(el.querySelectorAll('img')).map(pic => {
  14. if (pic.naturalHeight > 300 && pic.flag != 1) {
  15. pic.height = 300
  16. pic.removeAttribute('width')
  17. }
  18. else if(pic.naturalWidth > 300 && pic.naturalHeight > 300 && pic.flag != 1){
  19. pic.height = 300
  20. pic.removeAttribute('width')
  21. }
  22. pic.onclick = function () {
  23. large(this)
  24. }
  25. if (pic.parentElement.tagName == 'A') {
  26. pic.parentElement.removeAttribute('href')
  27. }
  28. })
  29. })
  30. }
  31. function large(pic) {
  32. if (pic.flag != 1 && pic.naturalWidth <= 800) {
  33. pic.viewWidth = pic.width
  34. pic.viewHeight = pic.height
  35. pic.width = pic.naturalWidth
  36. pic.height = pic.naturalHeight
  37. pic.flag = 1
  38. }
  39. else if (pic.flag != 1 && pic.naturalWidth > 800) {
  40. pic.viewWidth = pic.width
  41. pic.viewHeight = pic.height
  42. pic.width = 800
  43. pic.height = pic.naturalHeight / pic.naturalWidth * 800
  44. pic.flag = 1
  45. }
  46. else {
  47. pic.width = pic.viewWidth
  48. pic.height = pic.viewHeight
  49. pic.flag = 0
  50. // window.scrollBy(0, (pic.height - pic.naturalHeight)/3)
  51. }
  52. }
  53. scale()
  54. window.addEventListener('scroll', scale)