{"record":{"id":"0460a41885b84aa3","repo":"maboloshi/github-chinese","slug":"github-locals-js","errorCode":null,"errorMessage":"[GitHub 中文化插件] 词库文件 locals.js 未加载","messagePattern":"\\[GitHub 中文化插件\\] 词库文件 locals\\.js 未加载","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"main(nju.edu).user.js","lineNumber":143,"sourceCode":"        // 当前运行时状态\n        pageConfig: null,        // 当前页面配置（null 表示无有效页面）\n        currentURL: window.location.href, // 当前页面URL\n        transEngine: 'iflyrec',  // 当前翻译引擎\n        mutationObserver: null,  // DOM变化观察器\n        urlChangeHandler: null,  // 存储URL变化处理器\n        dynamicMenus: {},        // 动态菜单ID记录\n        initDone: false,\n    };\n\n    /* =========================== 安全检查 =========================== */\n\n    /**\n     * 检查词库文件是否加载 — 未加载则抛出错误阻止继续执行\n     */\n    function checkI18NLoaded() {\n        if (typeof I18N === 'undefined') {\n            alert('GitHub 汉化插件：词库文件 locals.js 未加载，脚本无法运行！');\n            throw new Error('[GitHub 中文化插件] 词库文件 locals.js 未加载');\n        }\n    }\n\n    /**\n     * 错误边界 — 包装函数，捕获异常避免阻断页面正常使用\n     * @param {Function} fn - 要执行的函数\n     * @param {string} label - 错误标签\n     * @returns {Function} 包装后的函数\n     */\n    function safe(fn, label) {\n        return function (...args) {\n            try {\n                return fn.apply(this, args);\n            } catch (e) {\n                console.error(`[GitHub 中文化插件] ${label} 出错:`, e);\n            }\n        };\n    }","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/maboloshi/github-chinese/blob/1db777260aeaeba52b39ebc37e1097e0c7053198/main(nju.edu).user.js#L125-L161","documentation":"checkI18NLoaded() is a fail-fast startup guard in the userscript. The script body relies on an externally @require'd locals.js that defines the global I18N translation dictionary (see // @require at the top of the .user.js). If that required file did not load before the script body executes, typeof I18N === 'undefined', the script alerts the user and throws, refusing to run with a missing vocabulary rather than partially translating the page.","triggerScenarios":"The @require https://mirror.nju.edu.cn/github-chinese/locals.js (line 15) fails to load — the NJU mirror is unreachable, blocked, returns a non-JS error page, or the userscript manager disabled remote @require fetches — so when the IIFE reaches checkI18NLoaded() at line 165 the global I18N is still undefined. Also fires when a user copies only the script body without the metadata header, so the manager never processes the @require directive.","commonSituations":"Users on networks where mirror.nju.edu.cn is firewalled or rate-limited; the NJU mirror being temporarily down; Tampermonkey/Violentmonkey with 'download @require resources' or network access disabled; installing the script by pasting the body instead of the full metadata block; a manager update that cleared cached @require resources.","solutions":["Open https://mirror.nju.edu.cn/github-chinese/locals.js in a browser; if it does not return JavaScript, the mirror is down/blocked — switch to the raw.githubusercontent variant (main.user.js) or wait for recovery.","In your userscript manager settings enable 'Download @require resources' / remote network access, then force the script to re-fetch resources (edit+save the metadata or reinstall) so locals.js is pulled again.","If the mirror is persistently unreachable, download locals.js locally and change the @require to a file:/// path, first enabling the manager's 'allow access to local files' option (see README §local-file require).","Reinstall the full script including the // ==UserScript== metadata block so the @require directive is honored."],"exampleFix":"// before\n// @require      https://mirror.nju.edu.cn/github-chinese/locals.js\n// after — mirror unreachable, point @require at the gh-pages source instead\n// @require      https://raw.githubusercontent.com/mabolashi/github-chinese/gh-pages/locals.js?v1.9.4.4","handlingStrategy":"validation","validationCode":"// Run in the same page context, before calling init():\nif (typeof I18N === 'undefined' || !I18N || typeof I18N !== 'object') {\n    console.error('[github-chinese] locals.js not loaded — aborting init');\n    return; // leave the page untranslated instead of throwing\n}","typeGuard":"function isI18NPresent(v: unknown): v is Record<string, unknown> {\n    return typeof v === 'object' && v !== null;\n}","tryCatchPattern":"try {\n    checkI18NLoaded();\n    init();\n} catch (e) {\n    // Fatal guard: log and degrade gracefully rather than crash the page.\n    console.warn('[github-chinese] skipped:', e instanceof Error ? e.message : e);\n}","preventionTips":["Confirm the @require URL returns 200 + JS by visiting it directly before relying on it.","Keep 'download @require resources' enabled in your userscript manager.","Pin a known-good mirror/tag in the @require URL instead of an unstable host.","Re-fetch resources after upgrading or reinstalling the manager."],"tags":["userscript","i18n","runtime-guard","require","dependency-loading"],"backgroundTag":null,"analyzedSha":"1db777260aeaeba52b39ebc37e1097e0c7053198","analyzedAt":"2026-08-13T05:58:27.900Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}