Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3861,6 +3861,17 @@
}
],
"Notes": "<p>修复浏览器过滤规则隐藏导航栏占位元素、导致页面顶部内容被遮挡的问题。</p>"
},
"3.8.5": {
"UpdateDate": 1791200581643,
"Prerelease": true,
"UpdateContents": [
{
"PR": 1045,
"Description": "fix: restore admin add-tag button for users without tags"
}
],
"Notes": "No release notes were provided for this release."
Comment thread
boomzero marked this conversation as resolved.
Resolved
}
}
}
8 changes: 5 additions & 3 deletions XMOJ.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name XMOJ
// @version 3.8.4
// @version 3.8.5
// @description XMOJ增强脚本
// @author @XMOJ-Script-dev, @langningchen and the community
// @namespace https://github/langningchen
Expand Down Expand Up @@ -2341,8 +2341,10 @@ function InitializeProfileBadge(container, userID, isAdmin) {
retry.disabled = true;
controls.replaceChildren();
RequestAPI("GetBadge", {UserID: userID}, response => {
if (!response?.Success) { Fail(response?.Message || "服务器响应异常,请重试"); return; }
let data = response.Data ?? {};
// GetBadge reports an absent database row as a failure; most users have no badge.
let missing = response?.Success === false && response.Message === "获取标签失败,该标签在数据库中不存在";
Comment thread
boomzero marked this conversation as resolved.
Resolved
Comment thread
boomzero marked this conversation as resolved.
Resolved
if (!response?.Success && !missing) { Fail(response?.Message || "服务器响应异常,请重试"); return; }
let data = missing ? {} : response.Data ?? {};
let content = String(data.Content ?? "");
badge.textContent = content;
badge.hidden = content === "";
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xmoj-script",
"version": "3.8.4",
"version": "3.8.5",
"description": "an improvement script for xmoj.tech",
"main": "AddonScript.js",
"scripts": {
Expand Down
44 changes: 41 additions & 3 deletions tests/profile-page.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ test('profile page browser regressions', {timeout: 60000}, async t => {
request.onload({status: mode === 'http' ? 503 : 200, responseText: '<html>Error</html>'});
return;
}
if (!mode && action === 'NewBadge') window.badgeData = {Content: 'New badge'};
if (!mode && action === 'DeleteBadge') window.badgeData = null;
if (mode === 'missing') {
request.onload({status: 200, responseText: JSON.stringify({Success: false, Message: '获取标签失败,该标签在数据库中不存在', Data: {}})});
return;
}
if (!mode && action === 'NewBadge') {
window.badgeData = {Content: 'New badge'};
window.badgeMode = null;
}
if (!mode && action === 'DeleteBadge') {
window.badgeData = null;
window.badgeMode = 'missing';
}
request.onload({status: 200, responseText: JSON.stringify({Success: mode !== 'denied', Message: 'Denied',
Data: action === 'GetBadge' ? badgeData : action === 'LastOnline' ? {logintime: onlineTimestamp} : {}})});
};
Expand Down Expand Up @@ -132,17 +142,45 @@ test('profile page browser regressions', {timeout: 60000}, async t => {
});
for (const mode of ['network', 'timeout', 'abort', 'throw', 'invalid-json', 'http', 'denied']) {
await t.test('preserves the profile and retries a ' + mode + ' badge failure', async () => {
const page = await Page({badgeMode: mode, onlineMode: mode});
const page = await Page({badgeMode: mode, onlineMode: mode, admin: true});
await AssertCore(page);
assert.match(await page.getByRole('status').innerText(), /标签暂不可用/);
assert.equal(await page.getByRole('button', {name: '重试加载标签'}).isVisible(), true);
assert.equal(await page.getByRole('button', {name: '添加标签'}).count(), 0);
await page.evaluate(() => { window.badgeMode = null; });
await page.getByRole('button', {name: '重试加载标签'}).click();
assert.equal(await page.locator('#UserScriptProfileBadge').innerText(), '省一');
assert.equal(await page.getByRole('button', {name: '重试加载标签'}).isHidden(), true);
await page.close();
});
}
for (const admin of [false, true]) {
await t.test('an absent database badge is an empty profile state with admin=' + admin, async () => {
const page = await Page({badgeMode: 'missing', admin});
await AssertCore(page);
assert.equal(await page.locator('#UserScriptProfileBadge').isHidden(), true);
assert.equal(await page.getByRole('status').innerText(), '');
assert.equal(await page.getByRole('button', {name: '重试加载标签'}).isHidden(), true);
assert.equal(await page.getByRole('button', {name: '添加标签'}).count(), admin ? 1 : 0);
assert.equal(await page.getByRole('button', {name: '删除标签'}).count(), 0);
if (admin) {
const add = page.getByRole('button', {name: '添加标签'});
assert.equal(await add.isVisible(), true);
await page.evaluate(() => { window.actionMode = 'denied'; });
await add.click();
assert.equal(await add.isEnabled(), true);
assert.equal(await page.getByRole('status').innerText(), 'Denied');
await page.evaluate(() => { window.actionMode = null; });
await add.click();
assert.equal(await page.locator('#UserScriptProfileBadge').innerText(), 'New badge');
assert.equal(await page.getByRole('button', {name: '删除标签'}).isVisible(), true);
assert.equal(await page.getByRole('status').innerText(), '');
assert.deepEqual(await page.evaluate(() => apiCalls.filter(call => call.action === 'NewBadge').map(call => call.data)),
[{UserID: 'ProfileTarget'}, {UserID: 'ProfileTarget'}]);
}
await page.close();
});
}
for (const badgeData of [null, {}, {Content: null, BackgroundColor: '', Color: 'invalid'}]) {
await t.test('handles missing badge data: ' + JSON.stringify(badgeData), async () => {
const page = await Page({badgeData, admin: true});
Expand Down