Greasy Fork

Greasy Fork is available in English.

Bazar minimalne ceny

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.

当前为 2021-08-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

this.$ = this.jQuery = jQuery.noConflict(true);
// ==UserScript==
// @name         Bazar minimalne ceny
// @namespace    http://tampermonkey.net/
// @version      0.7.0
// @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      http://greasyfork.icu/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

// ==/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");
    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 || inStorage.price > priceFloat) {
            console.log("Replacing " + title + " " + inStorage + " with " + priceFloat);
            saveToLocalStorage(title, priceFloat);
            if (inStorage === null) continue;
        }

        var diff = inStorage.price - priceFloat;
        if (diff > 0) {
            titleElem.style.color = '#00E000';
            priceElem.style.color = '#00E000';
            appendStoredPrice(inStorage.price, diff, priceElem.parentNode);
        } else if (diff < 0) {
            appendStoredPrice(inStorage.price, diff, priceElem.parentNode);
            appendTime(inStorage.timestamp, priceElem.parentNode);
        } else {
            titleElem.style.color = '#0000E0';
            priceElem.style.color = '#0000E0';
            appendTime(inStorage.timestamp, priceElem.parentNode);
        }
    }
})();

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 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;
}