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

Add checkboxes for guild market #442 #505

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion source/core/locale/cs.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ gca_languages['cs'] = {
are_you_sure_you_want_to_buy : "Vážně chceš koupit tento předmět?",
click_enter_to_sell : "Stisknutím enter ⏎ prodejte",
// Tooltips
add_fees_in_price : "Přičíst poplatek do ceny"
add_fees_in_price : "Přičíst poplatek do ceny",
// Item checkboxes button
checkboxes_button : "Zrušit vybrané"
},

// Forge
Expand Down Expand Up @@ -506,6 +508,7 @@ gca_languages['cs'] = {
category_market$double_click_select : "Vybrat předmět dvojitým klikem",
category_market$sell_warning_icons : "Ikona varování při prodávání předmětů",
category_market$sell_with_enter : "Prodávat předměty stisknutím klávesy ENTER ⏎",
category_market$item_checkboxes : "Přidat zaškrtávací políčka pro předměty",
// Settings - Expedition
category_expedition$show_enemy_drops : "Zobrazit materiály padající z nepřátel",
category_expedition$underworld_layout : "Zobrazit nepřátele v podzemí stejně jako u výprav",
Expand Down
3 changes: 3 additions & 0 deletions source/core/locale/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ gca_languages["en"] = {
click_enter_to_sell : "press enter ⏎ to sell",
// Tooltips
add_fees_in_price : "Add fees in price",
// Item checkboxes button
checkboxes_button : "Cancel selected",
},

// Forge
Expand Down Expand Up @@ -519,6 +521,7 @@ gca_languages["en"] = {
category_market$double_click_select : "Select item with double click",
category_market$sell_warning_icons : "Warning icon when selling items",
category_market$sell_with_enter : "Sell items by pressing ENTER ⏎",
category_market$item_checkboxes : "Add checkboxes for each item",
// Settings - Expedition
category_expedition$show_enemy_drops : "Show crafting materials each enemy drops",
category_expedition$underworld_layout : "Show underworld's enemies layout like expedition's",
Expand Down
4 changes: 3 additions & 1 deletion source/core/source/gca.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,9 @@ gca_options.data = {
// Item sell warning icons
"sell_warning_icons" : true,
// Sell with enter
"sell_with_enter" : true
"sell_with_enter" : true,
// Add checkboxes
"item_checkboxes" : true
},

// Expedition Options
Expand Down
89 changes: 89 additions & 0 deletions source/core/source/markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ var gca_markets = {
// 1 gold mode
(gca_options.bool("market", "one_gold_mode") &&
this.oneGoldMode());

// Add item checkboxes
if (gca_section.mod == 'guildMarket' && gca_options.bool("market", "item_checkboxes")) {
this.addItemCheckboxes();
}

// If insert "with fees" button
if (gca_options.bool("market","add_fees_button")){
Expand Down Expand Up @@ -585,6 +590,90 @@ var gca_markets = {
});
}
},

// Add item checkboxes and button
addItemCheckboxes: function() {
// Get table
let marketTable = document.getElementById("market_item_table");
if (!marketTable) return;

let rows = marketTable.querySelectorAll("tbody > tr:not(:first-child)");
if (rows.length === 0) return;

rows.forEach(row => {
// Create checkboxes
let checkboxCell = document.createElement("td");
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.className = "cancel-checkbox";
checkboxCell.appendChild(checkbox);

row.appendChild(checkboxCell);
});

// Create button
let cancelSelectedButton = document.createElement("input");
cancelSelectedButton.type = "button";
cancelSelectedButton.className = "awesome-button";
cancelSelectedButton.id = "cancelSelectedButton";
cancelSelectedButton.style = "margin-top: 2px; float: right;";
cancelSelectedButton.value = gca_locale.get("markets", "checkboxes_button");

// Append
marketTable.parentElement.appendChild(cancelSelectedButton);

// Event listener
cancelSelectedButton.addEventListener("click", function() {
let checkboxes = document.querySelectorAll(".cancel-checkbox:checked");
if (checkboxes.length === 0) return;

let atomic = false;
let minDelayRequests = 100; // Delay

// Cancel items
function cancelNext(index) {
if (index >= checkboxes.length) {
// Refresh
document.location.href = document.location.href.replace(/&p=\d+/i, "");
return;
}

// Find every cancel button
let row = checkboxes[index].closest("tr");
let cancelBtn = row.querySelector("input[name='cancel']");
let buyid = cancelBtn.form.buyid.value;

// AJAX request
let requestStart = new Date().getTime();
jQuery.ajax({
type: "POST",
url: document.location.href,
data: `buyid=${encodeURIComponent(buyid)}&cancel=${encodeURIComponent(cancelBtn.value)}`,
success: function() {
let requestDuration = new Date().getTime() - requestStart;
cancelSelectedButton.value = `(${index + 1}/${checkboxes.length})`;

setTimeout(() => {
cancelNext(index + 1);
}, Math.max(requestDuration, minDelayRequests));
},
error: function() {
let requestDuration = new Date().getTime() - requestStart;
gca_notifications.error(gca_locale.get("general", "error"));

setTimeout(() => {
cancelNext(index + 1);
}, Math.max(requestDuration * 2, minDelayRequests));
}
});
}

// Start it
cancelSelectedButton.disabled = true;
cancelSelectedButton.value = "⏳";
cancelNext(0);
});
},

// Layout
layout : {
Expand Down
4 changes: 3 additions & 1 deletion source/core/source/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,9 @@ var gca_settings = {
// Item sell warning icons
"sell_warning_icons" : true,
// Sell with enter
"sell_with_enter" : true
"sell_with_enter" : true,
// Add checkboxes
"item_checkboxes" : true
},

// Expedition Options
Expand Down