🎨 style: format

This commit is contained in:
2025-02-17 22:30:28 +07:00
parent e64376ea76
commit 830274e23b

View File

@@ -181,7 +181,7 @@ function TranslatorTool() {
"Instance Type": "#d4edbc", "Instance Type": "#d4edbc",
"Avatar Performance Rank": "#ffc8aa", "Avatar Performance Rank": "#ffc8aa",
"VRChat Specific": "#bfe1f6", "VRChat Specific": "#bfe1f6",
"Common": "#e6e6e6", Common: "#e6e6e6",
}; };
if (predefinedColors[category]) { if (predefinedColors[category]) {
@@ -203,12 +203,12 @@ function TranslatorTool() {
function isColorBright(color) { function isColorBright(color) {
// Convert hex to RGB // Convert hex to RGB
let r, g, b; let r, g, b;
if (color.startsWith('#')) { if (color.startsWith("#")) {
const hex = color.replace('#', ''); const hex = color.replace("#", "");
r = parseInt(hex.substr(0, 2), 16); r = parseInt(hex.substr(0, 2), 16);
g = parseInt(hex.substr(2, 2), 16); g = parseInt(hex.substr(2, 2), 16);
b = parseInt(hex.substr(4, 2), 16); b = parseInt(hex.substr(4, 2), 16);
} else if (color.startsWith('hsl')) { } else if (color.startsWith("hsl")) {
// Convert HSL to RGB // Convert HSL to RGB
const matches = color.match(/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)/); const matches = color.match(/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)/);
if (matches) { if (matches) {
@@ -222,17 +222,17 @@ function TranslatorTool() {
const hue2rgb = (p, q, t) => { const hue2rgb = (p, q, t) => {
if (t < 0) t += 1; if (t < 0) t += 1;
if (t > 1) t -= 1; if (t > 1) t -= 1;
if (t < 1/6) return p + (q - p) * 6 * t; if (t < 1 / 6) return p + (q - p) * 6 * t;
if (t < 1/2) return q; if (t < 1 / 2) return q;
if (t < 2/3) return p + (q - p) * (2/3 - t) * 6; if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
return p; return p;
}; };
const q = l < 0.5 ? l * (1 + s) : l + s - l * s; const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
const p = 2 * l - q; const p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3) * 255; r = hue2rgb(p, q, h + 1 / 3) * 255;
g = hue2rgb(p, q, h) * 255; g = hue2rgb(p, q, h) * 255;
b = hue2rgb(p, q, h - 1/3) * 255; b = hue2rgb(p, q, h - 1 / 3) * 255;
} }
} else { } else {
r = g = b = 128; // Fallback to gray if parsing fails r = g = b = 128; // Fallback to gray if parsing fails
@@ -247,12 +247,16 @@ function TranslatorTool() {
const bb = b / 255; const bb = b / 255;
// Calculate relative luminance (WCAG 2.0) // Calculate relative luminance (WCAG 2.0)
const luminance = 0.2126 * (rr <= 0.03928 ? rr / 12.92 : Math.pow((rr + 0.055) / 1.055, 2.4)) const luminance =
+ 0.7152 * (gg <= 0.03928 ? gg / 12.92 : Math.pow((gg + 0.055) / 1.055, 2.4)) 0.2126 *
+ 0.0722 * (bb <= 0.03928 ? bb / 12.92 : Math.pow((bb + 0.055) / 1.055, 2.4)); (rr <= 0.03928 ? rr / 12.92 : Math.pow((rr + 0.055) / 1.055, 2.4)) +
0.7152 *
(gg <= 0.03928 ? gg / 12.92 : Math.pow((gg + 0.055) / 1.055, 2.4)) +
0.0722 *
(bb <= 0.03928 ? bb / 12.92 : Math.pow((bb + 0.055) / 1.055, 2.4));
// Calculate YIQ // Calculate YIQ
const yiq = ((r * 299) + (g * 587) + (b * 114)) / 1000; const yiq = (r * 299 + g * 587 + b * 114) / 1000;
// Combine both methods // Combine both methods
// For pastel colors (high luminance but moderate YIQ) // For pastel colors (high luminance but moderate YIQ)
@@ -1058,7 +1062,7 @@ function TranslatorTool() {
function fetchRemoteCSV(url) { function fetchRemoteCSV(url) {
log("info", "Fetching remote CSV from", { url: url }); log("info", "Fetching remote CSV from", { url: url });
GM_xmlhttpRequest({ GM_xmlhttpRequest({
method: "GET", method: "GET",
url: url, url: url,
onload: function (response) { onload: function (response) {
if (response.status === 200) { if (response.status === 200) {
@@ -1066,23 +1070,24 @@ function TranslatorTool() {
const newData = parseCSVToArray(response.responseText); const newData = parseCSVToArray(response.responseText);
translationData = newData; translationData = newData;
currentCSVSource = url; currentCSVSource = url;
log("debug", "Translation data", { log("debug", "Translation data", {
translationData: JSON.stringify(translationData), translationData: JSON.stringify(translationData),
newData: JSON.stringify(newData) newData: JSON.stringify(newData),
}); });
log("success", "Successfully loaded remote CSV", { log("success", "Successfully loaded remote CSV", {
entries: translationData.length entries: translationData.length,
}); });
} catch (csvError) { } catch (csvError) {
log("error", "Error parsing CSV data", csvError); log("error", "Error parsing CSV data", csvError);
updateResults("Error parsing CSV data. Please check the file format and try again."); updateResults(
"Error parsing CSV data. Please check the file format and try again."
);
} }
} else { } else {
log("error", "Failed to fetch remote CSV", { log("error", "Failed to fetch remote CSV", {
status: response.status status: response.status,
}); });
updateResults( updateResults(
"Failed to fetch remote CSV. Please check the URL and try again." "Failed to fetch remote CSV. Please check the URL and try again."
@@ -1094,7 +1099,7 @@ function TranslatorTool() {
updateResults( updateResults(
"Error fetching remote CSV. Please check your connection and try again." "Error fetching remote CSV. Please check your connection and try again."
); );
} },
}); });
} }
@@ -1236,10 +1241,15 @@ function TranslatorTool() {
// First try exact match with punctuation // First try exact match with punctuation
translationData.forEach(function (entry) { translationData.forEach(function (entry) {
const uniqueKey = `${entry.source.toLowerCase()}_${entry.category || 'default'}`; const uniqueKey = `${entry.source.toLowerCase()}_${
entry.category || "default"
}`;
// Exact match (case-insensitive) // Exact match (case-insensitive)
if (entry.source.toLowerCase() === word.toLowerCase() && !seenCombinations.has(uniqueKey)) { if (
entry.source.toLowerCase() === word.toLowerCase() &&
!seenCombinations.has(uniqueKey)
) {
seenCombinations.add(uniqueKey); seenCombinations.add(uniqueKey);
matches.push({ matches.push({
entry: entry, entry: entry,
@@ -1257,10 +1267,7 @@ function TranslatorTool() {
if (cleanWord.length <= 3) { if (cleanWord.length <= 3) {
// Only match if it's a complete word match or surrounded by word boundaries // Only match if it's a complete word match or surrounded by word boundaries
const regex = new RegExp(`\\b${cleanWord}\\b`, "i"); const regex = new RegExp(`\\b${cleanWord}\\b`, "i");
if ( if (regex.test(entry.source) && !seenCombinations.has(uniqueKey)) {
regex.test(entry.source) &&
!seenCombinations.has(uniqueKey)
) {
seenCombinations.add(uniqueKey); seenCombinations.add(uniqueKey);
matches.push({ matches.push({
entry: entry, entry: entry,
@@ -1598,7 +1605,10 @@ function TranslatorTool() {
return JSON.stringify(obj1) === JSON.stringify(obj2); return JSON.stringify(obj1) === JSON.stringify(obj2);
} }
const needsDataUpdate = !isEqual(translationData, newData); const needsDataUpdate = !isEqual(
translationData,
newData
);
log("debug", "Translation data", { log("debug", "Translation data", {
translationData: JSON.stringify(translationData), translationData: JSON.stringify(translationData),