sync: dev to extern-contrib#987
Merged
Merged
Conversation
Update to release 3.5.0
Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
…-in-xmoj-script Fix Violentmonkey SyntaxError: wrap async init block in IIFE
Contributor
Reviewer's GuideSynchronizes extern-contrib with dev by wrapping the main userscript initialization in an async IIFE for Violentmonkey compatibility, fixing global variable scoping for username/theme/search params, hardening login/profile handling, adjusting main() invocation and error logging, and bumping the script/package versions to 3.5.1. Sequence diagram for async IIFE initialization, login handling, and main invocationsequenceDiagram
actor User
participant Browser
participant Userscript
participant XMOJServer
User->>Browser: Open xmoj.tech page
Browser->>Userscript: Execute XMOJ.user.js
Userscript->>Userscript: (async IIFE) start
Userscript->>XMOJServer: fetch(loginpage.php)
XMOJServer-->>Userscript: loginStatus
alt UtilityEnabled AutoLogin and login prompt
Userscript->>Browser: location.href = loginpage.php
Userscript-->>Userscript: return
end
Userscript->>Userscript: SearchParams = new URLSearchParams(location.search)
Userscript->>Browser: profileElement = document.querySelector(#profile)
alt profileElement is null and not logined
Userscript->>Browser: location.href = loginpage.php
Userscript-->>Userscript: return
else profileElement exists
Userscript->>Userscript: CurrentUsername = profileElement.innerText
end
Userscript->>Userscript: await main()
alt main succeeds
Userscript->>Browser: console.log(XMOJ-Script loaded successfully!)
else main throws
Userscript->>Browser: console.error([XMOJ-Script] Initialization error:, e)
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Deploying xmoj-script-dev-channel with
|
| Latest commit: |
2993f85
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://a1cb1e1b.xmoj-script-dev-channel.pages.dev |
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The new async initialization block assumes the
fetchforloginStatusalways succeeds; consider wrapping it (and theawait main()call) in a more granular try/catch so that network or runtime failures don’t silently prevent the rest of the script from running. - The early
returnwhenprofileElementisnullwill permanently skip script initialization on pages where#profileis not yet in the DOM (e.g., if the script runs before it’s rendered); consider delaying this check until DOMContentLoaded or otherwise ensuring the element is expected to exist before returning.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new async initialization block assumes the `fetch` for `loginStatus` always succeeds; consider wrapping it (and the `await main()` call) in a more granular try/catch so that network or runtime failures don’t silently prevent the rest of the script from running.
- The early `return` when `profileElement` is `null` will permanently skip script initialization on pages where `#profile` is not yet in the DOM (e.g., if the script runs before it’s rendered); consider delaying this check until DOMContentLoaded or otherwise ensuring the element is expected to exist before returning.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
sync-branches: New code has just landed in dev, so let's bring extern-contrib up to speed!
Summary by Sourcery
Sync extern-contrib userscript with latest dev changes and improve initialization flow.
New Features:
Bug Fixes:
CurrentUsername,SearchParams, andinitThemefrom being undefined by declaring them before asynchronous initialization.#profilewhen it is absent by checking and returning early, preventing errors on pages without a profile element.Enhancements:
mainand capturing initialization errors in a catch block.Summary by cubic
Sync extern-contrib with dev to release 3.5.1. Fix Violentmonkey top-level await error, harden init/login flow, and update version and release metadata (3.5.0/3.5.1).
CurrentUsername,initTheme, andSearchParams; added early returns for login/profile checks to avoid undefined access and redirect loops.main()and added init error logging.Update.json.Written for commit 2993f85. Summary will update on new commits.