adetailer-hires-sync
Mirror of KazeKaze93/adetailer-hires-sync at branch
master. Install, updates and issues: GitHub.
A lightweight extension for SD WebUI Forge / reForge that automatically enables ADetailer when you trigger a post-process hires fix on an already-generated image, then disables it once generation completes.
Problem
Running ADetailer on every generation is expensive β it adds a full inpaint pass even when you don't need it. But clicking β¨ (hires fix post-process) without ADetailer means faces won't be corrected at the final resolution. Manually toggling the checkbox each time is friction.
Solution
This extension hooks into the β¨ hires fix button and manages the ADetailer checkbox automatically:
- You click β¨ on a finished image.
- If ADetailer is off β the extension enables it and remembers it did so.
- Generation runs (hires pass + ADetailer inpaint).
- When generation completes β ADetailer is automatically turned back off (only if the extension enabled it for this run).
- If ADetailer was already on when you clicked β¨ β it is left on and not touched on completion.
Batch gallery: pick images for hires + ADetailer
After each batch, the script injects small circular checkboxes (class adhc-sel) on txt2img thumbnail buttons inside the gallery strip (not the main preview viewer):
- Thumbnails are resolved under
#txt2img_gallery: container.thumbnailsor[class*='thumbnails'], thenbuttonelements that contain an<img>. - Buttons whose
idor any ancestoridup to#txt2img_gallerycontainsselectedorpreview(case-insensitive) are skipped β avoids the large viewer slot.
β¨ behavior:
- No checkboxes ticked, or only one thumbnail in the strip β same as above (single hires pass on whatever is currently selected).
- One or more checkboxes ticked and two or more thumbnails β builds a sorted queue of indices, then runs hires sequentially: select thumbnail β enable ADetailer if needed β β¨ β wait for completion β next item. Queue mode uses programmatic β¨ clicks guarded so the handler does not re-enter. After the queue finishes, injected checkboxes are removed and the selection list resets.
During active generation (#txt2img_interrupt visible), gallery MutationObserver updates do not touch the DOM (debounced reinjection otherwise).
Installation
Via URL:
- Open Extensions -> Install from URL
- Paste:
https://github.com/KazeKaze93/adetailer-hires-sync.git - Click Install, then Apply and restart UI
Manual:
Clone or download this repo into your extensions/ folder, then restart the WebUI.
Requirements
- SD WebUI Forge or reForge (tested on reForge by Panchovix)
- ADetailer extension installed and configured
How it works
Frontend (javascript/adetailer_hires_sync.js, ES5): manages the ADetailer checkbox around #txt2img_upscale (β¨), gallery multi-select queue, and completion via #txt2img_interrupt.
Backend (scripts/adetailer_hires_sync.py + prompt_resolve.py): patches modules.txt2img.txt2img_upscale_function so the second pass uses the selected image's expanded all_prompts[k] / all_negative_prompts[k] (and seeds) from generation_info, instead of re-reading the wildcard template from the prompt field. Empty ADetailer ad_prompt then inherits the same expanded p.prompt. If generation_info is missing/empty or the gallery index is out of range, stock behaviour is kept and a warning is logged.
#txt2img_upscale(β¨): click handler enables ADetailer when unchecked (tracksautoEnabledByScript), arms completion observer, or starts multi-thumb queue processing when applicable.[id*="adetailer"] input[type="checkbox"]: ADetailer enable toggle (clicked only when the script decides to turn it on for hires).#txt2img_interrupt:MutationObserveron thestyleattribute β whendisplaygoes from visible generation state tononewhileautoEnabledByScriptis true, completion runs (toggle ADetailer off, disconnect observer; if a queue is active, schedule the next item after a short delay).#txt2img_gallery:MutationObserver(debounced) reinjects thumbnail checkboxes after gallery DOM updates; injects one-off#adhc-sel-stylesintodocument.headfor checkbox appearance.
Troubleshooting
If the extension does not trigger, verify selectors in DevTools (F12 -> Console):
// ADetailer checkbox
gradioApp().querySelector('[id*="adetailer"] input[type="checkbox"]')
// Hires fix button
gradioApp().querySelector('#txt2img_upscale')
// Interrupt button (used for completion detection)
gradioApp().querySelector('#txt2img_interrupt')
// Gallery root (thumbnails + preview live here)
gradioApp().querySelector('#txt2img_gallery')
All must return an element where relevant, not null. If any returns null, update the selectors in javascript/adetailer_hires_sync.js to match your build.
License
MIT