|
6 | 6 | // @supportURL https://github.com/0xdevalias/userscripts/issues
|
7 | 7 | // @downloadURL https://github.com/0xdevalias/userscripts/raw/main/userscripts/amazon-prime-gaming-highlighter/amazon-prime-gaming-highlighter.user.js
|
8 | 8 | // @namespace https://www.devalias.net/
|
9 |
| -// @version 1.0.2 |
| 9 | +// @version 1.0.3 |
10 | 10 | // @match https://gaming.amazon.com/home
|
11 | 11 | // @grant none
|
12 | 12 | // ==/UserScript==
|
|
117 | 117 | "offer-section-FGWP_FULL",
|
118 | 118 | ];
|
119 | 119 |
|
| 120 | + const sectionsWithTitleInHeading = [ |
| 121 | + "offer-section-WEB_GAMES", |
| 122 | + ]; |
| 123 | + |
| 124 | + const sectionsToIgnore = [ |
| 125 | + "offer-section-WEB_GAMES", |
| 126 | + ]; |
| 127 | + |
120 | 128 | function styleAsHighlighted(element) {
|
121 | 129 | element.style.backgroundColor = "green";
|
122 | 130 | }
|
|
128 | 136 | function styleAsIgnored(element) {
|
129 | 137 | element.style.backgroundColor = "red";
|
130 | 138 | 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 | + } |
131 | 145 | }
|
132 | 146 |
|
133 | 147 | function getCardsInSection(section) {
|
|
136 | 150 | return Array.from(document.querySelectorAll(sectionCardsSelector));
|
137 | 151 | }
|
138 | 152 |
|
| 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 | + |
139 | 161 | function isItemCollected(item) {
|
140 | 162 | const collectedSelector =
|
141 | 163 | '[data-a-target="notification-success"], [data-a-target="ItemCardDetailSuccessStatus"]';
|
|
147 | 169 | function highlightGames() {
|
148 | 170 | sectionsToMatch.forEach((section) => {
|
149 | 171 | getCardsInSection(section).forEach((card) => {
|
150 |
| - const title = card.querySelector(".item-card-details__body p")?.title; |
| 172 | + const title = getTitleForCard({ card, section }); |
151 | 173 |
|
152 | 174 | if (title) {
|
153 | 175 | if (gamesToHighlight.includes(title)) {
|
|
157 | 179 | console.log(
|
158 | 180 | `[APGH] Highlighting section=${section} title=${title}`
|
159 | 181 | );
|
160 |
| - } else if (gamesToIgnore.includes(title)) { |
| 182 | + } else if (gamesToIgnore.includes(title) || sectionsToIgnore.includes(section)) { |
161 | 183 | styleAsIgnored(card);
|
162 | 184 |
|
163 | 185 | DEBUG &&
|
164 | 186 | console.log(`[APGH] Ignoring section=${section} title=${title}`);
|
| 187 | + } else { |
| 188 | + DEBUG && |
| 189 | + console.log(`[APGH] Unhandled section=${section} title=${title}`); |
165 | 190 | }
|
166 | 191 | }
|
167 | 192 |
|
|
0 commit comments