// ==UserScript== // @name Figma CN // @namespace https://figma.cool // @match *://*.figma.com/* // @icon https://cdn.jim-nielsen.com/macos/1024/figma-2021-05-05.png // @license GPL-3.0 license // @version 1.7.1 // @description 中文 Figma 插件,设计师人工翻译校验。 // @author Figma-Cool // @homepageURL https://figma.cool // @supportURL https://github.com/Figma-Cool/figmaCN/issues // @run-at document-end // @grant none // @connect raw.githubusercontent.com // ==/UserScript== (function () { 'use strict'; const rawBase = 'https://raw.githubusercontent.com/Figma-Cool/figmaCN/refs/heads/master'; const contentScriptUrl = `${rawBase}/src/js/content.js`; const translationsUrl = `${rawBase}/src/js/translations.json`; function fetchChecked(url, asJson) { return fetch(url).then((response) => { if (!response.ok) { throw new Error(`HTTP ${response.status}: ${url}`); } return asJson ? response.json() : response.text(); }); } console.log('FigmaCN: 开始加载...'); Promise.all([ fetchChecked(contentScriptUrl, false), fetchChecked(translationsUrl, true) ]) .then(([contentScriptText, translationData]) => { if (!Array.isArray(translationData) || translationData.length === 0) { throw new Error('翻译数据为空或格式不正确。'); } // 禁止扩展环境专用的自动加载,改为使用上面已经取得的 JSON。 const modifiedContentScript = contentScriptText.replace( /loadTranslationData\s*\(\s*\)\s*;/g, '//$&' ); const runContentScript = new Function('allData', ` ${modifiedContentScript} if (typeof initializeTranslation !== 'function') { throw new Error('未找到 initializeTranslation。'); } initializeTranslation(allData); `); runContentScript(translationData); console.log(`FigmaCN: 已激活,加载 ${translationData.length} 条翻译。`); }) .catch((error) => { console.error('FigmaCN: 加载或执行失败:', error); }); })();