Skip to content

Commit 1891d53

Browse files
committed
[userscript] amazon-prime-gaming-highlighter: refactor to better handle offer-section-WEB_GAMES nuances + fix title extraction
1 parent 1519bea commit 1891d53

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

userscripts/amazon-prime-gaming-highlighter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// @supportURL https://github.com/0xdevalias/userscripts/issues
1010
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js
1111
// @namespace https://www.devalias.net/
12-
// @version 1.0.2
12+
// @version 1.0.3
1313
// @match https://gaming.amazon.com/home
1414
// @grant none
1515
// ==/UserScript==

userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// @supportURL https://github.com/0xdevalias/userscripts/issues
77
// @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js
88
// @namespace https://www.devalias.net/
9-
// @version 1.0.2
9+
// @version 1.0.3
1010
// @match https://gaming.amazon.com/home
1111
// @grant none
1212
// ==/UserScript==
@@ -117,6 +117,14 @@
117117
"offer-section-FGWP_FULL",
118118
];
119119

120+
const sectionsWithTitleInHeading = [
121+
"offer-section-WEB_GAMES",
122+
];
123+
124+
const sectionsToIgnore = [
125+
"offer-section-WEB_GAMES",
126+
];
127+
120128
function styleAsHighlighted(element) {
121129
element.style.backgroundColor = "green";
122130
}
@@ -128,6 +136,12 @@
128136
function styleAsIgnored(element) {
129137
element.style.backgroundColor = "red";
130138
element.style.opacity = 0.25;
139+
140+
// This extra background class seems to conflict/override the colour we set above.. so we remove it
141+
const cardDetails = element.querySelector('.item-card-details');
142+
if (cardDetails && cardDetails.classList.contains('tw-c-background-free-game')) {
143+
cardDetails.classList.remove('tw-c-background-free-game');
144+
}
131145
}
132146

133147
function getCardsInSection(section) {
@@ -136,6 +150,14 @@
136150
return Array.from(document.querySelectorAll(sectionCardsSelector));
137151
}
138152

153+
function getTitleForCard({ card, section }) {
154+
if (sectionsWithTitleInHeading.includes(section)) {
155+
return card.querySelector(".item-card-details .item-card-details__body .item-card-details__body__primary > [title]")?.title;
156+
} else {
157+
return card.querySelector(".item-card-details .item-card-details__body p > a[aria-label]")?.ariaLabel;
158+
}
159+
}
160+
139161
function isItemCollected(item) {
140162
const collectedSelector =
141163
'[data-a-target="notification-success"], [data-a-target="ItemCardDetailSuccessStatus"]';
@@ -147,7 +169,7 @@
147169
function highlightGames() {
148170
sectionsToMatch.forEach((section) => {
149171
getCardsInSection(section).forEach((card) => {
150-
const title = card.querySelector(".item-card-details__body p")?.title;
172+
const title = getTitleForCard({ card, section });
151173

152174
if (title) {
153175
if (gamesToHighlight.includes(title)) {
@@ -157,11 +179,14 @@
157179
console.log(
158180
`[APGH] Highlighting section=${section} title=${title}`
159181
);
160-
} else if (gamesToIgnore.includes(title)) {
182+
} else if (gamesToIgnore.includes(title) || sectionsToIgnore.includes(section)) {
161183
styleAsIgnored(card);
162184

163185
DEBUG &&
164186
console.log(`[APGH] Ignoring section=${section} title=${title}`);
187+
} else {
188+
DEBUG &&
189+
console.log(`[APGH] Unhandled section=${section} title=${title}`);
165190
}
166191
}
167192

0 commit comments

Comments
 (0)