Refactor logging in agent.user.js to improve readability and add error indicators. Introduce a welcome message function to display server status upon initialization.
This commit is contained in:
@@ -41,8 +41,8 @@
|
||||
|
||||
// ====== Utility ======
|
||||
const TL = {
|
||||
log: (msg, ...args) => GM_log(`[TL] ${msg}`, ...args),
|
||||
error: (msg, ...args) => GM_log(`[TL] [ERROR] ${msg}`, ...args),
|
||||
log: (msg, ...args) => GM_log(`[TL]\n${msg}`, ...args),
|
||||
error: (msg, ...args) => GM_log(`[TL] [ERROR] ❌\n${msg}`, ...args),
|
||||
noti: (title, text, timeout = 2500) => {
|
||||
if (typeof GM_notification === 'function') {
|
||||
GM_notification({ title, text, timeout });
|
||||
@@ -75,7 +75,7 @@
|
||||
let data = text;
|
||||
const isJSON = /content-type:\s*application\/json/i.test(resp.responseHeaders || '');
|
||||
if (isJSON) { try { data = JSON.parse(text); } catch { } }
|
||||
TL.log(`[GM] ${resp.status} ${url}`, data);
|
||||
TL.log(`${init.method} ${resp.status} ${url}`, data);
|
||||
resolve({
|
||||
status: resp.status,
|
||||
ok: resp.status >= 200 && resp.status < 300,
|
||||
@@ -175,6 +175,21 @@
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ====== Main ======
|
||||
async function welcome_message() {
|
||||
|
||||
const s = await BAF.getServer();
|
||||
const res = await BAF.ping();
|
||||
const resStr =
|
||||
`Server: ${s.label} (${s.url})\n` +
|
||||
`Status: ${res.ok ? 'Connected ✅' : 'Failed ❌'} (${res.status})`;
|
||||
|
||||
TL.log(resStr);
|
||||
}
|
||||
|
||||
|
||||
// ====== Khởi tạo ======
|
||||
await welcome_message();
|
||||
await createGM_Menu();
|
||||
})();
|
||||
Reference in New Issue
Block a user