Add ImageEnlarger feature with modal viewer#924
Conversation
Introduce an ImageEnlarger utility: add a toggle option to the feature list and implement a modal image viewer with CSS, toolbar (zoom in/out, reset, save), keyboard shortcuts, and click-to-open behavior. Images are annotated with a preview class and the feature ignores gravatar/cravatar sources; it applies to existing and dynamically added images via a MutationObserver. Errors are logged and surface a DebugMode alert when enabled.
Reviewer's GuideImplements a new toggleable ImageEnlarger utility that injects modal-viewer CSS/DOM, wires zoom/reset/save controls and keyboard shortcuts, and automatically decorates non-avatar images (including dynamically added ones) with click-to-enlarge behavior, with errors funneled through existing debug handling. Sequence diagram for ImageEnlarger click-to-enlarge and controlssequenceDiagram
actor User
participant ImageElement
participant ImageEnlargerUtility
participant ImageModal
participant KeyboardHandler
User->>ImageElement: click
ImageElement->>ImageEnlargerUtility: click event handler
ImageEnlargerUtility->>ImageModal: OpenImageModal(imgSrc)
ImageModal-->>ImageModal: CurrentZoom = 1
ImageModal-->>ImageModal: UpdateImageSize()
ImageModal-->>User: modal displayed with image
User->>ImageModal: click ZoomInBtn
ImageModal->>ImageModal: CurrentZoom = min(CurrentZoom + ZoomStep, MaxZoom)
ImageModal-->>ImageModal: UpdateImageSize()
User->>ImageModal: click ZoomOutBtn
ImageModal->>ImageModal: CurrentZoom = max(CurrentZoom - ZoomStep, MinZoom)
ImageModal-->>ImageModal: UpdateImageSize()
User->>ImageModal: click ResetZoomBtn
ImageModal->>ImageModal: CurrentZoom = 1
ImageModal-->>ImageModal: UpdateImageSize()
User->>KeyboardHandler: press + or - or Escape
KeyboardHandler->>ImageModal: handle keydown when modal is show
alt + key
KeyboardHandler->>ImageModal: trigger ZoomInBtn.click
else - key
KeyboardHandler->>ImageModal: trigger ZoomOutBtn.click
else Escape key
KeyboardHandler->>ImageModal: CloseImageModal()
ImageModal-->>User: modal hidden
end
User->>ImageModal: click SaveBtn
ImageModal->>ImageEnlargerUtility: create temporary anchor with ModalImage.src
ImageEnlargerUtility-->>User: browser download dialog
Flow diagram for ImageEnlarger initialization and image handlingflowchart TD
A[Check UtilityEnabled ImageEnlarger] -->|enabled| B[Inject CSS styles for previews and modal]
A -->|not enabled| Z[Do nothing]
B --> C[Create modal container ImageModal]
C --> D[Add CloseButton to ImageModal]
D --> E[Create ModalContent with ModalImage]
E --> F[Create Toolbar with ZoomInBtn ZoomOutBtn ResetZoomBtn SaveBtn]
F --> G[Append ImageModal to document body]
G --> H[Initialize zoom state CurrentZoom ZoomStep MinZoom MaxZoom]
H --> I[Register event handlers]
I --> I1[CloseButton click -> CloseImageModal]
I --> I2[ImageModal click on background -> CloseImageModal]
I --> I3[ZoomInBtn click -> increase CurrentZoom and UpdateImageSize]
I --> I4[ZoomOutBtn click -> decrease CurrentZoom and UpdateImageSize]
I --> I5[ResetZoomBtn click -> reset CurrentZoom and UpdateImageSize]
I --> I6[SaveBtn click -> create download link from ModalImage.src]
I --> I7[document keydown when modal show -> handle Escape plus minus]
I --> J[ApplyEnlargerToImages on existing images]
J --> J1[Select all img elements]
J1 --> J2{Is candidate image?}
J2 -->|yes| J3[Add class xmoj-image-preview and click handler to open modal]
J2 -->|no| J4[Skip image]
J --> K[Create MutationObserver]
K --> L[Observer.observe document body childList subtree]
L --> M[On mutations -> ApplyEnlargerToImages again]
subgraph ErrorHandling
N[try block around ImageEnlarger setup]
N -->|throws| O[catch e]
O --> P[console.error e]
P --> Q{UtilityEnabled DebugMode?}
Q -->|yes| R[SmartAlert with error details]
Q -->|no| S[End]
end
File-Level ChangesTips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
3 issues found across 3 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="XMOJ.user.js">
<violation number="1" location="XMOJ.user.js:5811">
P2: The modal image is not actually excluded from enhancement because the parent-class check targets the wrong element.</violation>
<violation number="2" location="XMOJ.user.js:5819">
P2: Image clicks don’t prevent default link navigation, so linked images can navigate away instead of staying in the modal viewer.</violation>
<violation number="3" location="XMOJ.user.js:5827">
P2: The mutation observer triggers a full-image rescan on every DOM mutation, which can cause unnecessary performance overhead.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@PythonSmall-Q I've opened a new pull request, #925, to work on those changes. Once the pull request is ready, I'll request review from you. |
…rc, and MutationObserver performance Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
Fix ImageEnlarger: accessibility, modal re-entry, responsive images, MutationObserver perf
|
你测试一下短消息内嵌图片 |
都测试过了,没有问题 |
|
@copilot 放大图片后需要可以让用户左右滑动,同时下载图片应该直接调出下载而不是redir到地址 |
|
@PythonSmall-Q I've opened a new pull request, #926, to work on those changes. Once the pull request is ready, I'll request review from you. |
Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
Fix image viewer: broken pan, missing wheel zoom, download navigates instead of saving
This pull request adds a new optional "Image Enlargement" feature to the user script, allowing users to click on images to view them in an interactive modal with zoom, reset, and save options. The feature is integrated as a toggleable utility and includes both UI and keyboard controls for improved user experience.
New Feature: Image Enlargement
Summary by Sourcery
Add an optional image enlargement utility that provides a modal viewer with zoom and save controls for images across the site.
New Features: