Pixiv Image Size Fitting

pixiv の原寸画像が表示領域に収まるように画像サイズを変更

  1. // ==UserScript==
  2. // @name Pixiv Image Size Fitting
  3. // @namespace http://userscripts.org/users/121129
  4. // @description pixiv の原寸画像が表示領域に収まるように画像サイズを変更
  5. // @include *://www.pixiv.net/*
  6. // @version 12
  7. // @grant none
  8. // @license MIT
  9. // @noframes
  10. // ==/UserScript==
  11.  
  12. ;(function() {
  13. 'use strict'
  14. function hasModifiersKey(event) {
  15. return event.altKey || event.ctrlKey || event.metaKey || event.shiftKey
  16. }
  17. function addStyle() {
  18. const style = document.createElement('style')
  19. style.id = 'PixivImageSizeFittingStyle'
  20. style.textContent = `
  21. body > [role="presentation"] > div > div {
  22. overflow: hidden;
  23. }
  24. body > [role="presentation"] img {
  25. max-height: 100vh;
  26. max-width: 100vw;
  27. }
  28. `
  29. document.head.appendChild(style)
  30. }
  31. function keydown(e) {
  32. if (hasModifiersKey(e)) return
  33. if (!['x', 'i'].includes(e.key)) return
  34. const style = document.getElementById('PixivImageSizeFittingStyle')
  35. if (style) {
  36. style.remove()
  37. } else {
  38. addStyle()
  39. }
  40. }
  41. function main() {
  42. addStyle()
  43. window.addEventListener('keydown', keydown)
  44. }
  45. main()
  46. })()