this.$ = this.jQuery = jQuery.noConflict(true); // ==UserScript== // @name Bazar minimalne ceny // @namespace http://tampermonkey.net/ // @version 0.8.3 // @description Zapamiętuje w local storage najniższe ceny gier z listy życzeń i pokazuje je obok aktualnie najniższej ceny. Jeśli aktualna cena jest mniejsza od dotychczas zapisanej, wtedy tytuł oznaczany jest na zielono, jeśli cena jest równa naniższej - na niebiesko. // @author nochalon // @match https://bazar.lowcygier.pl/ // @match https://bazar.lowcygier.pl/?* // @icon https://bazar.lowcygier.pl/favicon.ico // @require https://greasyfork.org/scripts/34527-gmcommonapi-js/code/GMCommonAPIjs.js?version=751210 // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.5.4/jquery.timeago.min.js // @require https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.5.4/locales/jquery.timeago.pl.js // @grant GM_registerMenuCommand // @grant GM.registerMenuCommand // @downloadURL none // ==/UserScript== (function() { 'use strict'; GMC.registerMenuCommand('Usuń całą historię', () => { if (confirm( "Aktualnie zapisanych jest " + localStorage.length + " tytułów. Czy chcesz je wszystkie usunąć?")) { localStorage.clear(); } }); GMC.registerMenuCommand('Usuń historię tytułu', () => { var title = prompt( "Podaj tytuł gry której historię chcesz usunąć"); if (title != null) { if (!removeFromLocalStorage(title)) { alert("Nie znaleziono tytułu o nazwie: " + title); } } }); var ths = document.querySelectorAll(".row.game-list.wishlist-item"); console.log("Local storage contains " + localStorage.length + " items"); var lowerPriceItems = []; for (var i = 0; i < ths.length; i++) { var titleElem = ths[i].querySelector(".media-heading > a"); var title = titleElem.innerHTML; var priceElem = ths[i].querySelector(".pc > p.prc"); var price = priceElem.innerHTML; var priceFloat = parseFloat(price.replace(',', '.')); var inStorage = JSON.parse(localStorage.getItem(title)); if (inStorage === null) { console.log("Adding new entry for " + title + " with price " + priceFloat); saveToLocalStorage(title, priceFloat); continue; } else if (inStorage.price > priceFloat) { console.log("Replacing price for " + title + " " + inStorage.price + " with " + priceFloat); saveToLocalStorage(title, priceFloat); } var priceParent = priceElem.parentNode; appendIntegrations(title, priceParent); var diff = inStorage.price - priceFloat; if (diff > 0) { titleElem.style.color = '#00E000'; priceElem.style.color = '#00E000'; appendStoredPrice(inStorage.price, diff, priceParent); lowerPriceItems.push({'title': title, 'diff': diff}); } else if (diff < 0) { appendStoredPrice(inStorage.price, diff, priceParent); appendTime(inStorage.timestamp, priceParent); } else { titleElem.style.color = '#0000E0'; priceElem.style.color = '#0000E0'; appendTime(inStorage.timestamp, priceParent); } } if (lowerPriceItems.length > 0) { appendLowerPricesBanner(document.querySelector(".banner-top"), lowerPriceItems); } })(); function appendLowerPricesBanner(bannerTop, items) { var alert = document.createElement("p"); bannerTop.insertBefore(alert, bannerTop.firstChild); alert.classList = "lowerPrices"; alert.style = "font-weight: bold; font-size: 1.3em; background: -webkit-linear-gradient(135deg, rgb(192, 192, 192) 0%, rgb(214, 214, 214) 25%, rgb(230, 230, 230) 100%); background-color: rgb(230,230,230); background: linear-gradient(135deg, rgb(192, 192, 192) 0%, rgb(214, 214, 214) 25%, rgb(230, 230, 230) 100%); border: 2px solid lightgrey; padding: 6px;"; alert.innerHTML = "

Pojawiły się nowe najniższe ceny dla:

"; } function appendTime(timeVal, elem) { var time = document.createElement("time"); var timeString = new Date(timeVal); time.innerHTML = timeString.toLocaleString(); time.dateTime = timeString.toISOString(); time.classList = "timeago"; elem.appendChild(time); jQuery(time).timeago(); } function appendStoredPrice(price, diff, elem) { var priceElem = document.createElement("p"); var val = diff/price*100.0; priceElem.innerHTML = "" + parseFloat(price).toFixed(2) + "zł (" + (val > 0.0 ? "+" : "") + val.toFixed(2) + "%)"; elem.appendChild(priceElem); } function appendIntegrations(title, elem) { var newPriceElem = document.createElement("p"); elem.appendChild(newPriceElem); var ggDeals = createGGDealsButton(title); var allKeyStop = createAllKeyShopButton(title); newPriceElem.appendChild(ggDeals); newPriceElem.appendChild(allKeyStop); } function saveToLocalStorage(title, price) { var newItem = {'price': price, 'timestamp': Date.now()}; localStorage.setItem(title, JSON.stringify(newItem)); } function removeFromLocalStorage(key) { var keyLowerCase = key.toLowerCase(); for (var a in localStorage) { if (a.toLowerCase() === keyLowerCase) { localStorage.removeItem(a); return true; } } return false; } function createGGDealsButton(title) { return createLinkWithImageAndCaption("https://gg.deals/favicon.ico", "https://gg.deals/games/?title=" + title, "Porównaj ceny " + title + " na GG.deals"); } function createAllKeyShopButton(title) { return createLinkWithImageAndCaption("https://www.allkeyshop.com/favicon.ico", "https://www.allkeyshop.com/blog/catalogue/category-pc-games-all/search-" + title + "/sort-price-asc/", "Porównaj ceny " + title + " na AllKeyShop"); } function createLinkWithImageAndCaption(img, href, caption) { var elem = document.createElement("a"); var imgElem = document.createElement("img"); elem.appendChild(imgElem); elem.href = href; elem.target = "_blank"; elem.title = caption; imgElem.src= img; imgElem.style.width = "20%"; imgElem.style.height = "20%"; return elem; }