Prevent Image Scaling

Force full-size gallery viewer to display images at their native resolution, with scaling options.

  1. // ==UserScript==
  2. // @name Prevent Image Scaling
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Force full-size gallery viewer to display images at their native resolution, with scaling options.
  6. // @author Taka_Sakagami
  7. // @match https://bsky.app/*
  8. // @grant GM_addStyle
  9. // ==/UserScript==
  10.  
  11. GM_addStyle(`
  12. div[style*="background-image"] {
  13. background-size: auto !important;
  14. background-repeat: no-repeat !important;
  15. transform: scale(var(--zoom-scale, 1)) translate(var(--translate-x, 0px), var(--translate-y, 0px)) !important;
  16. cursor: grab;
  17. image-rendering: var(--image-scaling, auto) !important;
  18. height: 1000%;
  19. width: 1000%;
  20. left: -450%;
  21. top: -450%;
  22. }
  23.  
  24. .css-9pa8cd {
  25. object-fit: none !important;
  26. transform: scale(var(--zoom-scale, 1)) translate(var(--translate-x, 0px), var(--translate-y, 0px)) !important;
  27. cursor: grab;
  28. image-rendering: var(--image-scaling, auto) !important;
  29. }
  30.  
  31. .zoom-controls {
  32. position: fixed;
  33. bottom: 20px;
  34. right: 20px;
  35. display: flex;
  36. align-items: center;
  37. gap: 10px;
  38. user-select: none;
  39. }
  40.  
  41. .zoom-button {
  42. width: 32px;
  43. height: 32px;
  44. background-color: #007bff;
  45. color: white;
  46. border: none;
  47. cursor: pointer;
  48. font-size: 16px;
  49. border-radius: 5px;
  50. user-select: none;
  51. }
  52.  
  53. .zoom-button:hover {
  54. background-color: #0056b3;
  55. }
  56.  
  57. .zoom-label {
  58. width: 50px;
  59. text-align: center;
  60. font-size: 16px;
  61. font-weight: bold;
  62. color: #333;
  63. user-select: none;
  64. display: inline-block;
  65. }
  66. `);
  67.  
  68.  
  69. (function() {
  70. let zoomLevel = 1;
  71. let zooming = 0;
  72. let translateX = 0;
  73. let translateY = 0;
  74. let isDragging = false;
  75. let startX, startY;
  76. let isNearestNeighbor = false;
  77.  
  78. function updateZoom(scale) {
  79. if (zooming !== 0) {
  80. zoomLevel = scale;
  81. document.documentElement.style.setProperty("--zoom-scale", zoomLevel);
  82. document.getElementById("zoom-label").textContent = `${Math.round(zoomLevel * 100)}%`;
  83. }
  84. }
  85. function updatePosition(x, y) {
  86. if (zooming !== 0) {
  87. translateX = x;
  88. translateY = y;
  89. document.documentElement.style.setProperty("--translate-x", `${translateX}px`);
  90. document.documentElement.style.setProperty("--translate-y", `${translateY}px`);
  91. }
  92. }
  93.  
  94. function startDrag(event) {
  95. if (event.button !== 0) {
  96. isDragging = true;
  97. startX = event.clientX - translateX;
  98. startY = event.clientY - translateY;
  99. }
  100. else {
  101. if (zooming === 0) {
  102. translateX = 0;
  103. translateY = 0;
  104. startX = 0;
  105. startY = 0;
  106. document.documentElement.style.setProperty("--translate-x", `${translateX}px`);
  107. document.documentElement.style.setProperty("--translate-y", `${translateY}px`);
  108. zoomLevel = 1;
  109. document.documentElement.style.setProperty("--zoom-scale", zoomLevel);
  110. document.getElementById("zoom-label").textContent = `${Math.round(zoomLevel * 100)}%`;
  111. }
  112. zooming = 0;
  113. }
  114. }
  115.  
  116. function dragImage(event) {
  117. if (isDragging) {
  118. updatePosition(event.clientX - startX, event.clientY - startY);
  119. }
  120. }
  121.  
  122. function stopDrag() {
  123. isDragging = false;
  124. }
  125.  
  126. document.addEventListener("mousedown", startDrag);
  127. document.addEventListener("mousemove", dragImage);
  128. document.addEventListener("mouseup", stopDrag);
  129.  
  130. function toggleScaling() {
  131. zooming = 1;
  132. isNearestNeighbor = !isNearestNeighbor;
  133. document.documentElement.style.setProperty("--image-scaling", isNearestNeighbor ? "pixelated" : "auto");
  134. document.getElementById("scaling-toggle").textContent = isNearestNeighbor ? "O" : "ロ";
  135. }
  136.  
  137. const container = document.createElement("div");
  138. container.className = "zoom-controls";
  139.  
  140. const zoomOutButton = document.createElement("button");
  141. zoomOutButton.className = "zoom-button";
  142. zoomOutButton.textContent = "-";
  143. zoomOutButton.addEventListener("click", function() {
  144. zooming = 1; updateZoom(zoomLevel - 0.25);
  145. });
  146.  
  147. const zoomLabel = document.createElement("span");
  148. zoomLabel.className = "zoom-label";
  149. zoomLabel.id = "zoom-label";
  150. zoomLabel.textContent = `100%`;
  151.  
  152. const zoomInButton = document.createElement("button");
  153. zoomInButton.className = "zoom-button";
  154. zoomInButton.textContent = "+";
  155. zoomInButton.addEventListener("click", function() {
  156. zooming = 1; updateZoom(zoomLevel + 0.25);
  157. });
  158.  
  159. const scalingToggle = document.createElement("button");
  160. scalingToggle.className = "zoom-button";
  161. scalingToggle.id = "scaling-toggle";
  162. scalingToggle.textContent = "ロ";
  163. scalingToggle.addEventListener("click", toggleScaling);
  164.  
  165. container.appendChild(zoomOutButton);
  166. container.appendChild(zoomLabel);
  167. container.appendChild(zoomInButton);
  168. container.appendChild(scalingToggle);
  169. document.body.appendChild(container);
  170. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址