Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix code.user.js userscript #49

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}) ();
}) ();