Skip to content

Commit

Permalink
Fix code.user.js userscript
Browse files Browse the repository at this point in the history
  • Loading branch information
patschi authored Aug 23, 2024
1 parent 930adcf commit bb2dc09
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions FreePackagesImporter/code.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @namespace https://github.com/Citrinate
// @author Citrinate
// @description Transfer packages from SteamDB's free packages tool to the ASF Free Packages plugin
// @version 1.0.0
// @version 1.0.1
// @match *://steamdb.info/freepackages/*
// @connect localhost
// @connect 127.0.0.1
Expand Down Expand Up @@ -101,11 +101,15 @@
}

async function SendASF(operation, path, http_method, target_bot, data = {}) {
let payload = JSON.stringify(data);
if (http_method == "HEAD" || http_method == "GET") {
payload = null;
}
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
url: `${GetSetting(SETTING_ASF_SERVER)}:${GetSetting(SETTING_ASF_PORT)}/Api/${operation}/${target_bot}/${path}`,
method: http_method,
data: JSON.stringify(data),
data: payload,
responseType: "json",
headers: {
"Accept": "application/json",
Expand All @@ -126,7 +130,7 @@
}

resolve(result ?? response);
},
},
onerror: reject,
ontimeout: reject,
});
Expand Down Expand Up @@ -191,7 +195,7 @@
</div>
</div>
`);

// Add packages
document.getElementById("js-freepackages-add-button").addEventListener("click", function() {
AddPackages();
Expand All @@ -205,7 +209,7 @@
// Close settings
document.getElementById("js-freepackages-settings-cancel").addEventListener("click", function() {
document.getElementById("js-freepackages-settings").style.display = "none";

document.getElementById("js-freepackages-settings-asf-server").value = GetSetting(SETTING_ASF_SERVER);
document.getElementById("js-freepackages-settings-asf-port").value = GetSetting(SETTING_ASF_PORT);
document.getElementById("js-freepackages-settings-asf-password").value = GetSetting(SETTING_ASF_PASSWORD);
Expand Down Expand Up @@ -243,7 +247,7 @@
if (freePackages.length == 0) {
Finish();
ShowMessage("There are no packages to add.");

return;
}

Expand All @@ -254,7 +258,7 @@
select.innerHTML = `<option value="ASF">All bots</option>`;
for (const i in bots) {
let bot = bots[i];

let opt = document.createElement("option");
opt.value = bot.BotName;
opt.innerHTML = bot.BotName;
Expand All @@ -277,4 +281,4 @@
}
}
//#endregion
}) ();
}) ();

0 comments on commit bb2dc09

Please sign in to comment.