Last active
November 14, 2023 20:19
-
-
Save NZDev0/b5ad52cb35435625dd814cd18de9c0f7 to your computer and use it in GitHub Desktop.
Adds slight tweaks to GoG.com for better UI
This file contains 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
// ==UserScript== | |
// @name Add GOG Site Adjustments | |
// @namespace https://gist.github.com/NZDev0/ | |
// @author Dev0 NZ | |
// @description Items currently added: Button for sorting wishlists by price | |
// @updateURL https://gist.github.com/NZDev0/b5ad52cb35435625dd814cd18de9c0f7/raw/ | |
// @downloadURL https://gist.github.com/NZDev0/b5ad52cb35435625dd814cd18de9c0f7/raw/ | |
// @match https://www.gog.com/* | |
// @run-at document-end | |
// @version 1.3 | |
// ==/UserScript== | |
(function() { | |
//let ascendingOrder = true; | |
let sort_btn = document.createElement("button"); | |
sort_btn.innerHTML = "Sort By Price"; | |
sort_btn.addEventListener("click", () => { | |
let elems = document.querySelectorAll('.list-inner'); | |
elems = elems[elems.length-1]; | |
let prices = Array.prototype.slice.call(document.querySelectorAll('.product-row-wrapper'),0); | |
prices.sort(function(a,b){ | |
if(elems.classList.contains('sorted')){ | |
return parseFloat(b.querySelector('._price.product-state__price').textContent) - parseFloat(a.querySelector('._price.product-state__price').textContent); | |
} | |
return parseFloat(a.querySelector('._price.product-state__price').textContent) - parseFloat(b.querySelector('._price.product-state__price').textContent); | |
}); | |
elems.innerHTML = ''; | |
elems.classList.contains('sorted') ? elems.classList.remove('sorted') : elems.classList.add('sorted'); | |
for(let i = 0; i<prices.length; i++){ | |
elems.appendChild(prices[i]); | |
} | |
/*let listInner = document.querySelectorAll('.list-inner')[1]; | |
let productRows = Array.from(listInner.querySelectorAll('.product-row-wrapper')); | |
productRows.sort((a, b) => { | |
const priceA = parseFloat(a.querySelector('._price.product-state__price').textContent); | |
const priceB = parseFloat(b.querySelector('._price.product-state__price').textContent); | |
return ascendingOrder ? priceA - priceB : priceB - priceA; | |
}); | |
ascendingOrder = !ascendingOrder; | |
productRows.forEach(productRow => listInner.appendChild(productRow));*/ | |
}); | |
// Add wishlist sort button | |
if(/wishlist/.test(document.location.href)){ | |
// Timeout added for it to be able to work in conjuction with Barefoot Essentials/Adalia Fundamentals scripts | |
/* | |
* https://greasyfork.org/de/scripts/1758-barefoot-essentials | |
* https://gist.github.com/adaliabooks/bf3cbdbb56db6c107dd8 | |
* | |
*/ | |
setTimeout(()=>{ | |
let el; | |
if(/Wishlisted by/.test(document.querySelector(".header__main").innerHTML)){ | |
el = document.querySelector(".collection-header"); | |
}else{ | |
el = document.querySelectorAll(".header__main"); | |
el = el[el.length-1]; | |
} | |
el.appendChild(sort_btn); | |
}, 900); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment