Greasy Fork is available in English.
POE2 trade 繁体化
当前为
// ==UserScript==
// @name POE2 trade 繁体
// @namespace http://tampermonkey.net/
// @version 1.3
// @description POE2 trade 繁体化
// @author 放课后
// @match https://www.pathofexile.com/trade2/*
// @grant GM_xmlhttpRequest
// @license MIT
// ==/UserScript==
(async () => {
'use strict';
const urls = [
'https://pathofexile.tw/api/trade2/data/stats',
'https://pathofexile.tw/api/trade2/data/static',
// 'https://pathofexile.tw/api/trade2/data/items',
'https://pathofexile.tw/api/trade2/data/filters'
];
const getResult = (url) => {
return new Promise(resolve => {
GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function(response) {
if (response.status === 200) {
try {
const data = JSON.parse(response.responseText);
console.log(`Data from ${url} stored successfully.`);
resolve(data);
} catch (e) {
console.error(`Error parsing data from ${url}:`, e);
resolve(null);
}
} else {
console.error(`Failed to fetch data from ${url}:`, response.status);
resolve(null);
}
},
onerror: function(error) {
console.error(`Request to ${url} failed:`, error);
resolve(null);
}
});
});
};
for (const url of urls) {
const {result} = await getResult(url);
const key = url.split('/').pop();
if (result && result.length) {
if (key === 'static') {
localStorage.setItem('lscache-trade2data', JSON.stringify(result));
} else {
localStorage.setItem('lscache-trade2' + key, JSON.stringify(result));
}
}
}
const enTradeItems2Tw = await getResult('https://p2.710421059.xyz/enTradeItems2Tw.json');
const {result} = await getResult('https://www.pathofexile.com/api/trade2/data/items');
if (result) {
for (let i = 0; i < result.length; i++) {
try {
result[i].label = enTradeItems2Tw[i].label;
} catch (e) {
console.error(`Error processing item ${i}:`, e);
}
if (result[i].entries) {
for (let j = 0; j < result[i].entries.length; j++) {
const find = enTradeItems2Tw[i].entries.find(a => a.type === result[i].entries[j].type && (result[i].entries[j].name ? a.name === result[i].entries[j].name : true));
if (find) {
result[i].entries[j].text = find.text;
}
}
}
}
localStorage.setItem('lscache-trade2items', JSON.stringify(result));
}
})();