Last active
November 30, 2019 08:05
-
-
Save burdiuz/7b340196d153a5fb7a5f7bb52279fc5d to your computer and use it in GitHub Desktop.
GOG.com display discount in games selection list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| document | |
| .querySelectorAll('.product-row__price.product-row__alignment') | |
| .forEach((row) => { | |
| const node = row.querySelector('.product-row-price--old ._price'); | |
| const oldPrice = parseFloat(node.innerText); | |
| const newPrice = parseFloat( | |
| row.querySelector('.product-row-price--new ._price').innerText, | |
| ); | |
| node.innerText = ` ${((1 - newPrice / oldPrice) * 100) >> 0}%`; | |
| node.parentElement.style.textDecoration = 'none'; | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (() => { | |
| const list = Array.from(document.querySelectorAll('.product-row')); | |
| list.forEach((row) => { | |
| const prices = row.querySelector('.product-row__price.product-row__alignment'); | |
| const discountNode = prices.querySelector('.product-row-price--old ._price'); | |
| const oldPrice = parseFloat(discountNode.innerText); | |
| const newPrice = parseFloat( | |
| prices.querySelector('.product-row-price--new ._price').innerText, | |
| ); | |
| const discount = ((1 - newPrice / oldPrice) * 100) >> 0; | |
| discountNode.innerText = ` ${discount}%`; | |
| discountNode.parentElement.style.textDecoration = 'none'; | |
| row.perc = discount; | |
| }); | |
| list.sort((r1, r2) => parseFloat(r1.perc) > parseFloat(r2.perc) ? -1 : 1) | |
| .reverse() | |
| .forEach((row) => document.querySelector('.list__products').prepend(row)); | |
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (() => { | |
| const minDiscount = 80; // minimum discount to look for | |
| const lastPage = 51; // last page on stre page | |
| const list = []; | |
| const findDiscounts = () => | |
| Array.from(document.querySelectorAll('.list-view__item')).forEach((node) => { | |
| const discountNode = node.querySelector('.product-tile__discount'); | |
| if (node.querySelector('.product-tile__labels--in-library') || !discountNode) { | |
| return; | |
| } | |
| discount = parseInt((discountNode.innerText.match(/^\s*-(\d+)%\s*$/) || ['0', '0'])[1], 10); | |
| if (discount >= minDiscount) { | |
| list.push({ discount, node }); | |
| } | |
| }); | |
| const goNextPage = async () => { | |
| document.querySelector('.arrow-wrapper.arrow-wrapper--right').click(); | |
| await new Promise((res) => setTimeout(res, 3000)); | |
| }; | |
| const showResult = () => { | |
| document.querySelectorAll('.list-view__item').forEach((node) => node.remove()); | |
| const parent = document.querySelector('.list-inner'); | |
| list.sort(({ discount: a }, { discount: b }) => (a < b ? 1 : -1)).forEach(({ node }) => parent.appendChild(node)); | |
| }; | |
| const read = async () => { | |
| for (let page = 1; page <= lastPage; page++) { | |
| findDiscounts(); | |
| await goNextPage(); | |
| } | |
| showResult(); | |
| }; | |
| read(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment