* Add background sort by date added feature
* reapply search after changing sort
* overengineer it
* use sortIgnoreCaseAndAccents
* make enum for sort options
* Startup and on-demand check
* Update comments, add color preload
* remove redundant metadata generation
* changed image-metadata/all from GET to POST
* move initializeAllUserMetadata to image-metadata.js, make blocking (?)
* Add type annotations
---------
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
* init
* cleanup
* logic changes and some styling
* set z index to a reasonable value
* remove pointless animation
* cleanup
* restore animation
* checkmark icon on selected background
* drop shadow
* tweak size slightly
* Apply suggestion from @Cohee1207
condense
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
* more of the above
* make lock indicator use a class like the selection indicator
* make backgroundHighlight run on page load
* cleanup
* html restructure and display: contents. only issue left is slightly wonky desktop buttons order
* yellow lock icon for consistancy
* Update layout
* Restore fitting logic
* Styles clean-up
* Remove duplicate class
* Restore button titles
* Fix return types of slash commands
* Update locked background on select if lock status is on
* Force header to 100% width
* Clean-up styles
* Fix locked highlight on custom backgrounds
* Revert global lock button
---------
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
* init
* mostly working messy version
* css layout, mobile is fixed
* revert changes
* more of the above
* cleanup
* revert breaking fixes, cleanup dead code
* dead code
* delete fallback
* spacing
* css tweaks and removed getChatBackgroundsList
* mobile sizing
* revert unrelated changes
* use name instead of context
* debounce from constants.js
* replace if/else
* pass images directly
* more of the above
* buttons
* buttons functionality
* add default column counts
* remove .mobile-only-menu-toggle when clicked (layering fix)
* lint
* universal column default of 3
* sacrifice firefox for chrome
* Restore media query
This reverts commit 295a5a8190.
* Add disabled attribute styles for menu_button
* use opacity 0, pointer events none instead of display:none
* Format styles
* Fix type errors
* Add blur event handler to close mobile menu when focus is lost
---------
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
* refactor: remove unused background styles
* feat: add support for nested @media, @supports, and @container rules in dynamic focus styles
* fix: add keyboard focus support for background menu buttons back
* fix: move "custom" background copy functionality to unified button UI and make it work again
* refactor: simplify CSSContainerRule instance check using window global
* fix: update hover and focus selector placeholder replacements to handle multiple occurrences in selector
* Fix focused outline offset of background samples
* Fix locked background outline color
* Add a11y roles to background menu items
* Add mobile-only button selector
* fix: update button and list item selectors
* Improve keyboard navigation in narrow layout
* Hide rename button for custom=true backgrounds
---------
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
* debug: Enhance logging for IntersectionObserver and root element
This commit adds more detailed console logging to `backgrounds.js`
to help you diagnose issues with the lazy loading mechanism.
Key changes:
- Added logs to trace calls to `activateLazyLoader` from
`getBackgrounds` and `getChatBackgroundsList`.
- Added a log at the start of `activateLazyLoader`.
- Added a check and log for the existence of the `#Backgrounds`
element, which is intended as the `root` for the
IntersectionObserver.
- Logged the options being passed to the IntersectionObserver.
- Ensured the IntersectionObserver can handle a null rootElement
(which would default to the viewport).
* feat: Implement lazy loading for background image thumbnails
This commit introduces lazy loading for background image thumbnails to improve initial load performance and reduce unnecessary data transfer.
Key changes:
- Modified `getBackgroundFromTemplate` to store image URLs in a `data-bg-src` attribute instead of directly setting the `background-image` style. A `lazy-load-background` class is added to these elements.
- Introduced a new `activateLazyLoader` function that uses the `IntersectionObserver` API. This function monitors elements with the `lazy-load-background` class and only loads their `background-image` (from `data-bg-src`) when they are about to become visible in the viewport.
- Integrated `activateLazyLoader` into `getBackgrounds` and `getChatBackgroundsList` so that it's activated after background placeholder elements are created.
- Added checks at the beginning of `getBackgrounds` and `getChatBackgroundsList` to prevent them from re-populating the thumbnail lists if they already contain elements, avoiding redundant processing.
This ensures that:
1. No background thumbnails are downloaded when the application first loads.
2. When the background selection menu is opened, the list of thumbnails is generated as placeholders, but the actual images are not downloaded.
3. Thumbnail images are only downloaded from the server as they scroll into view.
* I've made some updates to help diagnose why background images may not be loading.
Specifically, I've:
- Added logging to see when the lazy loader is activated and how many elements it's working with.
- Included logs to track when the IntersectionObserver is triggered for an element and its status.
- Added logging for the image URL being applied.
- Included a warning if an image URL isn't found for an element that should be loading.
Additionally, I've configured the IntersectionObserver to use the '#Backgrounds' element as the reference point for its calculations, with a 10% threshold.
* Optimize background menu loading and add toggleable logging
This PR addresses UI lag caused by the background selection menu.
Changes:
- Optimized Background Loading:
- The background selection menu (`#Backgrounds`) now unloads non-selected and non-locked background images when it's closed. This is achieved by setting `style.backgroundImage = 'none'` for the respective elements.
- When the menu is reopened, the background images are repopulated by calling the existing `getBackgrounds()` and `getChatBackgroundsList()` functions, which also re-initialize the lazy loader.
- A `MutationObserver` is used to detect when the `#Backgrounds` menu drawer is opened or closed by observing changes to its `classList` (specifically the `closedDrawer` class).
- Toggleable Debug Logging:
- Added a `DEBUG_BACKGROUND_LOADING` constant at the top of `public/scripts/backgrounds.js`.
- All `console.log`, `console.warn`, and `console.error` statements related to the background loading/unloading logic and the lazy loader are now conditional on this flag. Set `DEBUG_BACKGROUND_LOADING = true` to enable these logs for debugging purposes.
Benefits:
- Improves UI performance by reducing the number of images actively loaded in the DOM when the background menu is not in use.
- Reduces main background playback lag that was exacerbated by having many backgrounds loaded.
- Provides a way to enable detailed logging for troubleshooting background loading issues without cluttering the console during normal operation.
* I can optimize the background menu loading.
I'll detect when the background select menu is opened and closed.
When the menu is closed, I will remove non-selected and non-locked backgrounds from the DOM to improve performance.
When the menu is opened, I will repopulate the backgrounds.
This will prevent UI lag caused by too many background images being loaded simultaneously.
* lint syntax and spacing fix
* add url check back in
* Post-merge clean-up
* Disconnecting previous observer on lazy load init
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
* Feat: Add toggle for animated background thumbnails
This commit introduces a new toggle in the User Settings UI: "Load Animated Background Thumbnails".
- When checked (default), animated background thumbnails (.gif, .mp4, animated .webp) load and display as usual in the background selection menu.
- When unchecked, these animated thumbnails are replaced with a transparent PNG (`__transparent.png`) in the selection menu. This is intended to reduce UI and network lag for you if you have a large number of animated backgrounds.
The actual functionality of setting any background (animated or static) remains unchanged; clicking a thumbnail will always apply the original background file.
Changes include:
- Added `loadAnimatedBackgroundThumbnails` (boolean, defaults to true) to `settings.json` under the `power_user` object.
- Added the toggle HTML to `public/index.html`.
- Modified `public/scripts/backgrounds.js` to conditionally replace animated thumbnails based on the new setting.
- Modified `public/script.js` to handle the toggle's event listener and save its state.
- Modified `public/scripts/power-user.js` to initialize the toggle's state upon loading settings.
* Fix: Resolve issues with animated background thumbnail toggle
This commit addresses two issues with the "Load Animated Background Thumbnails" feature:
1. Toggle state was not persisting correctly across page loads.
2. Animated media files were still being loaded even when the toggle was set to hide their thumbnails.
Fixes:
- Corrected the variable scope in `applyPowerUserSettings` within `public/scripts/power-user.js` to ensure the toggle's checked state is properly initialized from the global `power_user.loadAnimatedBackgroundThumbnails` setting. This resolves the persistence issue.
- Refined the logic in `getBackgroundFromTemplate` within `public/scripts/backgrounds.js`. When the toggle is off and a background is an animated type (.gif, .mp4, .webp), the `background-image` CSS property for its thumbnail now directly uses the path to `__transparent.png`. This prevents the browser from potentially pre-fetching or the server from processing the original animated file via the `/thumbnail` endpoint for display purposes.
- Added console logging in `getBackgroundFromTemplate` to help debug the toggle state and file being processed.
The core functionality of applying backgrounds by clicking on thumbnails (whether transparent or regular) remains unchanged, as the `bgfile` attribute correctly stores the original media path.
* Fix: Resolve page load error and animated thumbnail toggle issues
This commit addresses a critical page loading error (`power_user is not defined`
in `backgrounds.js`) and ensures the "Load Animated Background Thumbnails"
toggle functions as intended.
The page load error was caused by `getBackgrounds()` (and subsequently
`getBackgroundFromTemplate()`) in `backgrounds.js` attempting to access
`power_user.loadAnimatedBackgroundThumbnails` before the `power_user` object
was fully initialized and its properties reliably accessible during the
application's `firstLoadInit` sequence.
Fixes:
1. **Explicit Setting Passing for Initial Load**:
* Modified `getBackgrounds()` in `public/scripts/backgrounds.js` to accept
`loadAnimatedThumbnailsSetting` as a parameter.
* Modified `getBackgroundFromTemplate()` in `public/scripts/backgrounds.js`
to accept and prioritize this passed parameter. It includes fallback
logic to use the global `power_user.loadAnimatedBackgroundThumbnails`
(primarily for event-driven updates like chat changes, which happen later)
and then to a default of `true` if the setting is somehow unavailable.
* Updated the call to `getBackgrounds()` in `public/script.js` during
`firstLoadInit` to pass `power_user.loadAnimatedBackgroundThumbnails`
explicitly after `power_user` settings are loaded.
* Updated the toggle's `change` event listener in `public/script.js` to also
pass the new setting state to `getBackgrounds()` for immediate refresh
of system backgrounds.
2. **Toggle Persistence**:
* Ensured the toggle's state in `public/scripts/power-user.js`
(within `applyPowerUserSettings`) is correctly initialized using the
global `power_user.loadAnimatedBackgroundThumbnails`.
3. **Media Loading for Thumbnails**:
* The logic in `getBackgroundFromTemplate` now ensures that if animated
thumbnails are toggled off, the `background-image` CSS directly uses
`url("backgrounds/__transparent.png")`, avoiding calls to `getThumbnailUrl()`
with original animated file paths, which might have caused unintended
pre-fetching or server-side processing.
This set of changes should resolve the page loading blockage and ensure the
animated background thumbnail toggle works correctly for both display and
network loading, while maintaining the functionality of applying original
backgrounds.
* Fix: Ensure correct initial state and first-toggle behavior for animated thumbnail toggle
This commit addresses issues where the "Load Animated Background Thumbnails"
toggle might not correctly display its default 'on' state (checked) on
a clean install, and ensures the first toggle action takes immediate effect.
Changes:
- In `public/scripts/power-user.js`:
- `loadPowerUserSettings`: Ensured that `power_user.loadAnimatedBackgroundThumbnails`
is robustly defaulted to `true` if the key is missing or not a boolean
(e.g., from an older settings file) *before* `applyPowerUserSettings` is called.
- `applyPowerUserSettings`: Added console logging to trace the value of
`power_user.loadAnimatedBackgroundThumbnails` just before setting the
checkbox state. Ensured the checkbox `checked` property is set using
`!!power_user.loadAnimatedBackgroundThumbnails` for explicit boolean conversion.
The function already correctly referenced the global `power_user` object.
- In `public/scripts/backgrounds.js`:
- `getBackgroundFromTemplate`: This function's logic for determining the
`loadSetting` (which decides if a transparent thumbnail is used) was
previously refined to prioritize a passed parameter, then fall back to the
global `power_user.loadAnimatedBackgroundThumbnails`, and then to `true`.
Console logs were added to trace the resolved setting and file details.
- In `public/script.js`:
- `firstLoadInit`: The call to `getBackgrounds` already correctly passes the
`power_user.loadAnimatedBackgroundThumbnails` after settings are loaded.
- Event listener for `#loadAnimatedBackgroundThumbnails`: The logic to update
the global `power_user` state and then call refresh functions
(`getBackgrounds` and emitting `CHAT_CHANGED` for `getChatBackgroundsList`)
appears to be in the correct synchronous order.
These changes should ensure the toggle initializes to its correct visual state (checked)
and that the first toggle from ON to OFF (and back) correctly and immediately
updates both the visual display of thumbnails and the network loading behavior.
* Fix: Address ESLint issues in background thumbnail toggle feature
This commit resolves ESLint errors that were present in
`public/scripts/backgrounds.js` and `public/scripts/power-user.js`
related to the "Load Animated Background Thumbnails" feature.
Changes:
- I corrected indentation errors in `public/scripts/backgrounds.js`
as reported by the linter.
- I replaced direct use of `object.hasOwnProperty()` with
`Object.prototype.hasOwnProperty.call(object, ...)` in both
`backgrounds.js` and `power-user.js` to resolve the
`no-prototype-builtins` ESLint error.
- I ensured `power_user` is correctly imported and/or checked for
definition (using `typeof power_user !== 'undefined'`) in
`backgrounds.js` before accessing its properties, to satisfy
linter concerns around `no-undef` for `power_user` in the
context of the `getBackgroundFromTemplate` fallback logic.
These changes primarily address code style and linting rules and
are not intended to alter the functional behavior of the animated
background thumbnail toggle, which was addressed in previous commits.
* fix weird spacing for lint
* Refactor animated background thumbnail settings and functionality
* Remove comments
* Add missing awaits
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
* set isForced to true on input
* make floating auto-complete follow horizontal scrolling
* add callable closure vars
* changes to /let and /var for callable closures
* fix error message
* fix scope for closure arguments
* if should return the pipe result from closures
* use /run to call closures and no arguments on immediate closures
* throw exception from QRs window-function if no match
* when to show autocomplete vs info only
* autocomplete positioning
* autocomplete styling
* add theming to autocomplete (theme, dark, light)
* improve autocomplete show/hide logic and editor selection
* use blur tint color instead of chat tint color and use blur setting
* cleanup and docs
* use scope macros for QR args
* add enter to select autocomplete
* fix no executor found
* cleanup and comment
* fix alias list in help string
* fallback to empty string piped value if null or undefined
* fix typo
* blur textarea on ctrl+enter execute (and refocus after)
* stop executeSlashCommand if parser throws
* move /let and /var callbacks into functions
* switch textarea to monospace when value starts with slash
* add double pipe a pipe breaker
* fix /? slash
* remove some logging
* add "/:name" as shorthand for "/run name" after all
* move shit around
* fix error message
* use testRunShorthandEnd
* use parseQuotedValue and parseValue to determine name for "/:"
QR labels and set names can include spaces
* add some adjustments to make autocomplete work properly
some hint in there about "/:" would still be nice
* add autocomplete style selector
* only strip quotes from subcommand if they are at both ends
* fix JSDoc
* escaping
* allow open quotes on dry run
* throwing shit at the wall for /: autocomplete
* escapes only for symbols
* clean up autocomplete
* improve performance
* fix scope macros
* remove unescaping of pipes
* fix macros in scope copy
* fix "/? slash"
* don't run parser for getNameAt if text has not changed
* fix options filter
* re-enable blur listener
* restore selection on non-replace select
* fix for escaping first character of value
* add support for {{pipe}} and {{var::}} closures
* add index support to var macro
* add scoped var macro to macro help
* more escape fixes
* reduce autocomplete render debounce
* cleanup
* restore old escape handling and parser flag for strict escaping
* fix "no match" autocomplete message
* add dummy commands for comments and parser flag
* fix type annotations
* somewhat safer macro replacements
* fix autocomplete select on blank / "no match"
* fix cutting off handled part in substitution
* add parser flag REPLACE_GETVAR
Replaces all {{getvar::}} and {{getglobalvar::}} macros with {{var::}}.
Inserts a series of command executors before the command with the macros that:
- save {{pipe}} to a var
- call /getvar or /getglobalvar to get the variable used in the macro
- call /let to save the retrieved variable
- return the saved {{pipe}} value
This helps to avoid double-substitutions when the var values contain text that could be interpreted as macros.
* remove old parser
* fix send on enter when no match
* deal with pipes in quoted values (loose escaping)
* add default parser flags to user settings
* allow quoted values in unnamed argument
* set parser flag without explicit state to "on"
* add click hint on parser error toast
* dirty more detailed cmd defs
* remove name from unnamed arg
* move autocomplete into class and floating with details
* replace jQuery's trigger('input') on #send_textarea with native events because jQuery does not dispatch the native event
* fix ctrl+space
* fix arrow navigation
* add comments
* fix pointer block
* add static fromProps
* fix up dummy commands
* migrate all commands to addCommandObject
* remove commented comment command
* fix alias in details
* add range as argument type
* switch to addCommandObject
* switch to addCommandObject
* fix height
* fix floating details position on left
* re-enable blur event
* use auto width for full details on floating autocomplete
* auto-size floating full details
* fix typo
* re-enable blur listener
* don't prevent enter when selected item is fully typed out
* add autocomplete details tooltips
* add language to slash command examples
* move makeItem into option and command and fix click select
* use autocomplete parts in /? slash
* fix alias formatting
* add language to slash command examples
* fix details position on initial input history
* small screen styles
* replace registerSlashCommand with detailed declarations
* put name on first line
* add missing returns
* fix missing comma
* fix alias display in autocomplete list
* remove args from help string
* move parser settings to its own section
* jsdoc
* hljs stscript lang
* add hljs to autocomplete help examples
* add missing import
* apply autocomplete colors to stscript codeblocks (hljs)
* add fromProps
* cache autocomplete elements
* towards generic autocomplete
* remove unused imports
* fix blanks
* add return types
* re-enable blur
* fix blank check
* Caption messages by id
* add aborting command execution
* fix return type
* fix chat input font reset
* add slash command progress indicator
* add missing return
* mark registerSlashCommand deprecated
* why??
* separate abort logic for commands
* remove parsing of quoted values from unnamed arg
* add adjustable autocomplete width
* revert stop button pulse
* add progress and pause/abort to QR editor
* add resize event on autocomplete width change
* add key= argument to all get vars
* refactoring
* introduce NamedArgumentAsignment
* add TODOs
* refactoring
* record start and end of named arg assignment
* refactoring
* prevent duplicate calls to show
* refactoring
* remove macro ac
* add secondary autocomplete and enum descriptions
* add syntax highlighting to QR editor
* add enum descriptions to /while
* add /let key=... to scope variable names
* add unnamed argument assignment class and unnamed argument splitting
* fix QR editor style
* remove dash before autocomplete help text
* add autocomplete for unnamed enums
* fix remaining dom after holding backslash
* fix for unnamed enums
* fix autocomplete for /parser-flag
* add parser-flag enum help
* fix type annotations
* fix autocomplete result for /:
* add colored autocomplete type icons
* collapse second line autocomplete help if empty
* mark optional named args in autocomplete
* fix when what
* remove duplicate debug buttons
* dispatch input on autocomplete select
* prevent grow from editor syntax layer
* add auto-adjust qr editor caret color
* remove text-shadow from autocomplete
* join value strings in /let and /var
* add /abort syntax highlight
* fix attempting secondary result when there is none
* rename settings headers and split autocomplete / stscript
* add parser flag tooltips
* add tooltips to chat width stops
* fix typo
* return clone of help item
* fix enum string
* don't make optional notice for autocomplete arguments smaller
* avoid scrollbar in chat input
* add rudimentary macro autocomplete
* strip macro from helptext
* finally remove closure delimiters around root
* cleanup
* fix index stuff for removed closure delimiters
* fix type hint
* add child commands to progress indicator
* include sub-separator in macro autocomplete
* remove all mentions of interruptsGeneration and purge
* remove unused imports
* fix syntax highlight with newline at end of input
* cleanup select pointer events
* coalesce onProgress call
* add regex to STscript syntax highlighting
* fix closure end
* fix autocomplete type icon alignment
* adjustments for small screens
* fix removing wrong element
* add missing "at=" arg to /sys, /comment, /sendas
* add font scale setting for autocomplete
* add target=_blank for parser flag links
* fix for searching enums
* remove REGEXP_MODE from hljs
just causes trouble
* fix autocomplete in closures
* fix typo
* fix type hint
* Get rid of scroll bar on load
* Add type hint for /send name argument. Fix 'at' types
* Add 'negative' arg hint to /sd command
* reenable blur event
* Allow /summarize to process any text
* Compact layout of script toggles
* Expand CSS by default
* fix double ranger indicator and adjust to narrow container
* make custom css input fill available vertical space
* reduce scroll lag
* use default cursor on scrollbar
* Clean-up module loading in index.html
* fix tab indent with hljs
---------
Co-authored-by: Cohee <18619528+Cohee1207@users.noreply.github.com>
- Toggle to auto-sort tags alphabetically
- Init auto-sort based on current sorted state, if not chosen before
- Tag management redraw list if changes happen
- Tag management highlight renamed rows on auto-sort if they get automatically reordered
- Manual drag&drop of tags disables auto-sort option
- Small fixes to popup tag management pop drawing
- Utility function to flash highlight via CSS