For those having issues with the torn API, getting CORS policy errors (503)
If you have a chrome/firefox extension add https://api.torn.com to the manifest in permissions array
For tampermonkey use GM_xmlhttpRequest instead of a regular xmlhttpRequest
These 2 lines are very important:
// @connect api.torn.com
// @grant GM_xmlhttpRequest
function getItems(api_key) {
return new Promise((resolve, reject) => {
let ret = GM_xmlhttpRequest({
method: "GET",
url: `https://api.torn.com/torn/?selections=items&key=${api_key}`,
onreadystatechange: function (res) {
if (res.readyState === 4 && res.status === 200) {
const parsedRes = JSON.parse(res.responseText)
Items = parsedRes.items
resolve()
}
},
onerror: function (err) {
console.log(err)
}
})
}).catch(e => {
console.log(e)
});
}
More info here https://github.com/scriptish/scriptish/wiki/GM_xmlhttpRequest