Skip to content

Commit

Permalink
Add highlight and tag support for ignored as owned elsewhere
Browse files Browse the repository at this point in the history
  • Loading branch information
candela97 committed Mar 28, 2024
1 parent 9e1a86f commit 1f2421d
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ <h2 data-locale-text="highlight" class="js-section-head">Highlight</h2>
<div data-dynamic="highlight_inv_gift" data-dynamic-color="1"></div>
<div data-dynamic="highlight_inv_guestpass" data-dynamic-color="1"></div>
<div data-dynamic="highlight_notinterested" data-dynamic-color="1"></div>
<div data-dynamic="highlight_notinterested_owned" data-dynamic-color="1"></div>
<div data-dynamic="highlight_collection" data-dynamic-color="1"></div>
<div data-dynamic="highlight_waitlist" data-dynamic-color="1"></div>
</div>
Expand All @@ -135,6 +136,7 @@ <h2 data-locale-text="options.tag" class="js-section-head">Tag</h2>
<div data-dynamic="tag_inv_gift" data-dynamic-color="1"></div>
<div data-dynamic="tag_inv_guestpass" data-dynamic-color="1"></div>
<div data-dynamic="tag_notinterested" data-dynamic-color="1"></div>
<div data-dynamic="tag_notinterested_owned" data-dynamic-color="1"></div>
<div data-dynamic="tag_collection" data-dynamic-color="1"></div>
<div data-dynamic="tag_waitlist" data-dynamic-color="1"></div>
</div>
Expand Down
13 changes: 12 additions & 1 deletion src/js/Background/Modules/SteamStoreApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,19 @@ class SteamStoreApi extends Api {
const store = await SteamStoreApi.getEndpoint("dynamicstore/userdata", {}, null, {"cache": "no-cache"});
const {rgOwnedApps, rgOwnedPackages, rgIgnoredApps, rgWishlist} = store;

const ignored = [];
const ignoredOwnedElsewhere = [];
Object.entries(rgIgnoredApps).forEach(([appid, value]) => {
if (value === 0) {
ignored.push(Number(appid));
} else if (value === 2) {
ignoredOwnedElsewhere.push(Number(appid));
}
});

const dynamicStore = {
"ignored": Object.keys(rgIgnoredApps).map(key => Number(key)),
ignored,
ignoredOwnedElsewhere,
"ownedApps": rgOwnedApps,
"ownedPackages": rgOwnedPackages,
"wishlisted": rgWishlist,
Expand Down
32 changes: 12 additions & 20 deletions src/js/Content/Features/Common/FHighlightsTags.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class FHighlightsTags extends Feature {

title.dataset.dsAppid = appid;

return FHighlightsTags.highlightAndTag([title], false);
return FHighlightsTags.highlightAndTag([title]);
}

/**
Expand All @@ -29,17 +29,17 @@ export default class FHighlightsTags extends Feature {
*
* @param {NodeList|Array} nodes - The nodes that should get highlighted
* (defaults to all known nodes that are highlightable and taggable)
* @param {boolean} hasDsInfo - Whether or not the supplied nodes contain dynamic store info (defaults to true)
* @param {Object} options - Option overrides that should be applied
* @returns {Promise} - Resolved once the highlighting and tagging completed for the nodes
*/
static async highlightAndTag(nodes, hasDsInfo = true, options = {}) {
static async highlightAndTag(nodes, options = {}) {

Check warning on line 35 in src/js/Content/Features/Common/FHighlightsTags.js

View workflow job for this annotation

GitHub Actions / run-eslint

Static async method 'highlightAndTag' has a complexity of 50. Maximum allowed is 20

if (typeof FHighlightsTags._options === "undefined") {
FHighlightsTags._options = {
"owned": SyncedStorage.get("highlight_owned") || SyncedStorage.get("tag_owned"),
"wishlisted": SyncedStorage.get("highlight_wishlist") || SyncedStorage.get("tag_wishlist"),
"ignored": SyncedStorage.get("highlight_notinterested") || SyncedStorage.get("tag_notinterested"),
"ignoredOwned": SyncedStorage.get("highlight_notinterested_owned") || SyncedStorage.get("tag_notinterested_owned"),
"collected": SyncedStorage.get("highlight_collection") || SyncedStorage.get("tag_collection"),
"waitlisted": SyncedStorage.get("highlight_waitlist") || SyncedStorage.get("tag_waitlist"),
"gift": SyncedStorage.get("highlight_inv_gift") || SyncedStorage.get("tag_inv_gift"),
Expand Down Expand Up @@ -85,30 +85,14 @@ export default class FHighlightsTags extends Feature {
} else {
console.warn("FHighlightsTags: Couldn't find storeId for node %o", node);
}

if (hasDsInfo) {
try {
if (opts.owned && node.querySelector(".ds_owned_flag") !== null) {
this.highlightOwned(node);
}
if (opts.wishlisted && node.querySelector(".ds_wishlist_flag") !== null) {
this.highlightWishlist(node);
}
if (opts.ignored && node.querySelector(".ds_ignored_flag") !== null) {
this.highlightIgnored(node);
}
} catch (err) {
console.error("Failed to highlight / tag node", err);
}
}
}

const storeIds = Array.from(storeIdsMap.keys());
if (storeIds.length === 0) { return; }

const trimmedStoreIds = storeIds.map(id => GameId.trimStoreId(id));

const includeDsInfo = !hasDsInfo && (opts.owned || opts.wishlisted || opts.ignored);
const includeDsInfo = opts.owned || opts.wishlisted || opts.ignored || opts.ignoredOwned;

const [dsStatus, itadStatus, invStatus] = await Promise.all([
includeDsInfo ? DynamicStore.getAppStatus(storeIds) : Promise.resolve(),
Expand Down Expand Up @@ -137,6 +121,9 @@ export default class FHighlightsTags extends Feature {
if (opts.ignored && dsStatus[storeId].ignored) {
operations.push(this.highlightIgnored);
}
if (opts.ignoredOwned && dsStatus[storeId].ignoredOwned) {
operations.push(this.highlightIgnoredOwnedElsewhere);
}
}

/*
Expand Down Expand Up @@ -345,6 +332,10 @@ export default class FHighlightsTags extends Feature {
this._highlightItem(node, "notinterested");
}

static highlightIgnoredOwnedElsewhere(node) {
this._highlightItem(node, "notinterested_owned");
}

static highlightCollection(node) {
this._highlightItem(node, "collection");
}
Expand All @@ -362,6 +353,7 @@ FHighlightsTags._tagCssLoaded = false;
* The later it appears in the array, the higher its precedence
*/
FHighlightsTags._types = [
"notinterested_owned",
"notinterested",
"waitlist",
"wishlist",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export default class FHighlightFriendsActivity extends CallbackFeature {
// https://github.com/IsThereAnyDeal/AugmentedSteam/pull/470#pullrequestreview-284928257
&& (link.childElementCount !== 1 || !link.closest(".vote_header")));

FHighlightsTags.highlightAndTag(nodes, false);
FHighlightsTags.highlightAndTag(nodes);
}
}
2 changes: 1 addition & 1 deletion src/js/Content/Features/Store/App/FSteamPeek.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class FSteamPeek extends Feature {
window.SteamFacade.dynamicStoreDecorateItems("#recommended_block_content > a.es_sp_similar");
});

this.context.decorateStoreCapsules(content.querySelectorAll("a.es_sp_similar"), true);
this.context.decorateStoreCapsules(content.querySelectorAll("a.es_sp_similar"));

HTML.beforeBegin(lastChild,
`<a class="small_cap es_sp_similar" href="http://steampeek.hu/?appid=${this.context.appid}" target="_blank">
Expand Down
4 changes: 2 additions & 2 deletions src/js/Content/Features/Store/Common/CStoreBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export class CStoreBase extends CBase {
}
}

decorateStoreCapsules(nodes, hasDsInfo) {
FHighlightsTags.highlightAndTag(nodes, hasDsInfo);
decorateStoreCapsules(nodes) {
FHighlightsTags.highlightAndTag(nodes);
FEarlyAccess.show(nodes);
}
}
2 changes: 1 addition & 1 deletion src/js/Content/Features/Store/Storefront/CStoreFront.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class CStoreFront extends CStoreBase {

// This section goes through multiple rendering steps before apps show up, so don't disconnect immediately
if (nodes.length !== 0) {
this.decorateStoreCapsules(nodes, false); // This section doesn't have dsinfo for some reason
this.decorateStoreCapsules(nodes);
observer.disconnect();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ export default class FWishlistHighlights extends CallbackFeature {
options.waitlisted = false;
}

return FHighlightsTags.highlightAndTag(nodes, false, options);
return FHighlightsTags.highlightAndTag(nodes, options);
}
}
1 change: 1 addition & 0 deletions src/js/Content/Modules/Data/DynamicStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DynamicStore {
const trimmedId = trimmedIds[i];
acc[id] = {
"ignored": dsStatus[trimmedId].includes("ignored"),
"ignoredOwned": dsStatus[trimmedId].includes("ignoredOwnedElsewhere"),
"wishlisted": dsStatus[trimmedId].includes("wishlisted"),
};
if (id.startsWith("app/")) {
Expand Down
4 changes: 4 additions & 0 deletions src/js/Core/Storage/SyncedStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const DEFAULTS = {
"highlight_inv_gift_color": "#800040",
"highlight_inv_guestpass_color": "#513c73",
"highlight_notinterested_color": "#4f4f4f",
"highlight_notinterested_owned_color": "#4f4f4f",
"highlight_collection_color": "#856d0e",
"highlight_waitlist_color": "#4c7521",

Expand All @@ -65,6 +66,7 @@ const DEFAULTS = {
"tag_inv_gift_color": "#b10059",
"tag_inv_guestpass_color": "#65449a",
"tag_notinterested_color": "#4f4f4f",
"tag_notinterested_owned_color": "#4f4f4f",
"tag_collection_color": "#856d0e",
"tag_waitlist_color": "#4c7521",

Expand All @@ -74,6 +76,7 @@ const DEFAULTS = {
"highlight_inv_gift": false,
"highlight_inv_guestpass": false,
"highlight_notinterested": false,
"highlight_notinterested_owned": false,
"highlight_excludef2p": false,
"highlight_collection": true,
"highlight_waitlist": true,
Expand All @@ -84,6 +87,7 @@ const DEFAULTS = {
"tag_inv_gift": false,
"tag_inv_guestpass": false,
"tag_notinterested": true,
"tag_notinterested_owned": true,
"tag_collection": false,
"tag_waitlist": false,
"tag_short": false,
Expand Down
2 changes: 2 additions & 0 deletions src/js/Options/Modules/Data/OptionsSetup.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default {
"highlight_inv_gift": "options.gift",
"highlight_inv_guestpass": "options.guest",
"highlight_notinterested": "notinterested",
"highlight_notinterested_owned": "notinterested_owned",
"highlight_collection": "options.collection",
"highlight_waitlist": "options.waitlist",
"highlight_excludef2p": "options.excludef2p",
Expand All @@ -63,6 +64,7 @@ export default {
"tag_inv_gift": "options.gift",
"tag_inv_guestpass": "options.guest",
"tag_notinterested": "notinterested",
"tag_notinterested_owned": "notinterested_owned",
"tag_collection": "options.collection",
"tag_waitlist": "options.waitlist",
"tag_short": "tag_short",
Expand Down
2 changes: 2 additions & 0 deletions src/js/Options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ const Options = (() => {
"highlight_inv_gift",
"highlight_inv_guestpass",
"highlight_notinterested",
"highlight_notinterested_owned",
"highlight_waitlist",
"highlight_collection",
"tag_owned",
Expand All @@ -335,6 +336,7 @@ const Options = (() => {
"tag_inv_gift",
"tag_inv_guestpass",
"tag_notinterested",
"tag_notinterested_owned",
"tag_collection",
"tag_waitlist",
"spamcommentregex",
Expand Down
2 changes: 2 additions & 0 deletions src/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"view": "View",
"game_name": "Game Name",
"notinterested": "Items you ignored",
"notinterested_owned": "Items you ignored as owned elsewhere",
"search_filters": {
"reviews_score": {
"between": "Between __lower__% and __upper__% review score",
Expand Down Expand Up @@ -534,6 +535,7 @@
"inv_guestpass": "Guestpass",
"owned": "Owned",
"notinterested": "Ignored",
"notinterested_owned": "Ignored (owned elsewhere)",
"collection": "Collected",
"waitlist": "Waitlisted"
},
Expand Down

0 comments on commit 1f2421d

Please sign in to comment.