Skip to content

sync: dev to extern-contrib#962

Merged
PythonSmall-Q merged 13 commits intoextern-contribfrom
dev
Mar 28, 2026
Merged

sync: dev to extern-contrib#962
PythonSmall-Q merged 13 commits intoextern-contribfrom
dev

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions bot commented Mar 28, 2026

sync-branches: New code has just landed in dev, so let's bring extern-contrib up to speed!

Summary by Sourcery

Add cloud-based settings synchronization support and expose it in the user script UI while bumping the script/package version to 3.4.1.

New Features:

  • Introduce an optional CloudSync utility that synchronizes user script settings to a server across devices.
  • Add a settings sync card with controls to upload local settings to the cloud and download/apply cloud settings.
  • Automatically apply cloud settings on load or upload local settings if none exist when CloudSync is enabled.

Enhancements:

  • Trigger automatic cloud sync when theme or other settings are changed, avoiding sync when CloudSync is turned off itself.

Build:

  • Bump script and package versions from 3.4.0 to 3.4.1 in metadata and package.json.

Summary by cubic

Adds cross‑device settings sync via a cloud backend, plus a simple UI to upload/download and auto-sync settings. Bumps version to 3.4.1 and updates release metadata.

  • New Features

    • Added CloudSync toggle to sync script settings to your account.
    • New “设置云同步” card with status text and Upload/Download buttons; applies theme and toggles on download.
    • Auto‑uploads on setting changes (e.g., theme or utility toggles); fetches cloud settings on load when enabled.
    • Uses RequestAPI actions GetUserSettings and SetUserSettings.
  • Bug Fixes

    • Guard when not logged in with clear messages.
    • Skip syncing when turning CloudSync off; normalize checkbox booleans; handle empty/null cloud settings safely.

Written for commit 86b25a5. Summary will update on new commits.

Copilot AI and others added 13 commits March 28, 2026 01:33
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Signed-off-by: Shan Wenxiao <seanoj_noreply@yeah.net>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@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>
…fault on)

Agent-Logs-Url: https://github.com/XMOJ-Script-dev/XMOJ-Script/sessions/91cd1e68-c0d5-495a-bbed-36e3cd49d955

Co-authored-by: PythonSmall-Q <106425289+PythonSmall-Q@users.noreply.github.com>
…r-settings

feat: Cross-device settings sync via cloud backend
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 28, 2026

Reviewer's Guide

Adds a cloud-based settings synchronization feature to the XMOJ userscript, wiring it into the existing settings UI and auto-sync behavior, and bumps the script/package version to 3.4.1.

Sequence diagram for uploading settings to cloud

sequenceDiagram
    actor User
    participant SettingsUI
    participant SyncSettingsToCloud
    participant localStorage
    participant RequestAPI
    participant BackendAPI

    User->>SettingsUI: Change theme or toggle setting
    SettingsUI->>localStorage: setItem UserScript-Setting-*
    SettingsUI->>SyncSettingsToCloud: SyncSettingsToCloud(CallBack)

    SyncSettingsToCloud->>SyncSettingsToCloud: Check CurrentUsername
    alt user not logged in
        SyncSettingsToCloud-->>SettingsUI: CallBack{Success:false,Message:用户未登录}
    else user logged in
        SyncSettingsToCloud->>SyncSettingsToCloud: Check UtilityEnabled(CloudSync)
        alt CloudSync disabled
            SyncSettingsToCloud-->>SettingsUI: CallBack{Success:false,Message:云同步已禁用}
        else CloudSync enabled
            SyncSettingsToCloud->>localStorage: Iterate keys with prefix UserScript-Setting-
            SyncSettingsToCloud->>RequestAPI: Action SetUserSettings, Data Settings JSON
            RequestAPI->>BackendAPI: SetUserSettings(Settings)
            BackendAPI-->>RequestAPI: Response{Success,Message}
            RequestAPI-->>SyncSettingsToCloud: Response
            SyncSettingsToCloud->>SyncSettingsToCloud: Optional debug console log
            SyncSettingsToCloud-->>SettingsUI: CallBack(Response)
        end
    end
Loading

Sequence diagram for downloading and applying cloud settings

sequenceDiagram
    actor User
    participant SettingsUI
    participant ApplyCloudSettings
    participant localStorage
    participant RequestAPI
    participant BackendAPI

    User->>SettingsUI: Click 从云端下载设置
    SettingsUI->>SettingsUI: Update SyncStatusText 正在下载…
    SettingsUI->>RequestAPI: Action GetUserSettings, Data {}
    RequestAPI->>BackendAPI: GetUserSettings()
    BackendAPI-->>RequestAPI: Response{Success,Data.Settings}
    RequestAPI-->>SettingsUI: Response

    alt Response.Success
        SettingsUI->>ApplyCloudSettings: ApplyCloudSettings(Response.Data.Settings)
        loop for each key in cloudSettings
            ApplyCloudSettings->>localStorage: setItem UserScript-Setting-key
            alt key is Theme
                ApplyCloudSettings->>SettingsUI: Update theme select value
                ApplyCloudSettings->>SettingsUI: initTheme()
            else other setting
                ApplyCloudSettings->>SettingsUI: Update checkbox checked
            end
        end
        SettingsUI->>SettingsUI: SyncStatusText 下载成功,设置已应用
    else Response not Success
        SettingsUI->>SettingsUI: SyncStatusText 下载失败: Response.Message
    end
Loading

File-Level Changes

Change Details Files
Introduce client-side helper to upload all UserScript settings from localStorage to a cloud API and integrate it into settings changes.
  • Add SyncSettingsToCloud helper that validates login and CloudSync utility flag, collects UserScript-Setting-* keys from localStorage, and sends them via SetUserSettings API
  • Log detailed success/failure messages in debug mode
  • Invoke SyncSettingsToCloud after theme changes and on most checkbox setting toggles, skipping sync when CloudSync is being turned off
XMOJ.user.js
Add a UI section for managing cloud sync, including initial auto-load behavior and manual upload/download controls.
  • Register a new CloudSync utility toggle in the utilities list with descriptive label
  • Create a new card UI "设置云同步" containing status text and buttons to upload settings to, or download settings from, the cloud via GetUserSettings/SetUserSettings APIs
  • Implement ApplyCloudSettings to mirror cloud settings into localStorage, update theme select, and check/uncheck feature toggles appropriately
  • On page load, if CloudSync is enabled, auto-fetch cloud settings and either upload local settings if cloud is empty or apply cloud settings; otherwise show that cloud sync is disabled
XMOJ.user.js
Bump script and package versions for the new cloud sync feature.
  • Update @Version metadata in XMOJ.user.js from 3.4.0 to 3.4.1
  • Update package.json version field from 3.4.0 to 3.4.1
  • Presumably update Update.json to reflect the new version (content not shown in diff)
XMOJ.user.js
package.json
Update.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying xmoj-script-dev-channel with  Cloudflare Pages  Cloudflare Pages

Latest commit: 86b25a5
Status: ✅  Deploy successful!
Preview URL: https://f058e36a.xmoj-script-dev-channel.pages.dev

View logs

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue 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:2322">
P2: Guard `Response.Data.Settings` before applying cloud settings to avoid runtime errors on successful-but-empty responses.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

SyncStatusText.innerText = "正在下载…";
RequestAPI("GetUserSettings", {}, (Response) => {
if (Response.Success) {
ApplyCloudSettings(Response.Data.Settings);
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Guard Response.Data.Settings before applying cloud settings to avoid runtime errors on successful-but-empty responses.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At XMOJ.user.js, line 2322:

<comment>Guard `Response.Data.Settings` before applying cloud settings to avoid runtime errors on successful-but-empty responses.</comment>

<file context>
@@ -2236,6 +2270,88 @@ async function main() {
+                            SyncStatusText.innerText = "正在下载…";
+                            RequestAPI("GetUserSettings", {}, (Response) => {
+                                if (Response.Success) {
+                                    ApplyCloudSettings(Response.Data.Settings);
+                                    SyncStatusText.innerText = "下载成功,设置已应用(部分设置需刷新页面后生效)";
+                                } else {
</file context>
Suggested change
ApplyCloudSettings(Response.Data.Settings);
ApplyCloudSettings((Response.Data && Response.Data.Settings) || {});
Fix with Cubic

@PythonSmall-Q PythonSmall-Q merged commit fcf5307 into extern-contrib Mar 28, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants