GOG.com Wishlist Discounted Items Toggle

When items in your GOG.com wishlist are discounted, only the discounted items will be shown. Provides a toggle to display all items and remembers your last setting.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GOG.com Wishlist Discounted Items Toggle
// @version      1.0
// @namespace    https://greasyfork.org/users/219548
// @description  When items in your GOG.com wishlist are discounted, only the discounted items will be shown. Provides a toggle to display all items and remembers your last setting.
// @author       mnnks
// @grant        GM_setValue
// @grant        GM_getValue
// @include      https://www.gog.com/account/wishlist
// ==/UserScript==

function conjureUpStylesheet() {
    var stylesheet = document.createElement("style");
    stylesheet.type = "text/css";
    stylesheet.textContent = ".account__products .product-row {\ndisplay: none;\n}\n\n.account__products .is-discounted";
    stylesheet.textContent += "{\ndisplay: block;\n}\n\n.discount-toggle .menu-link {\ncolor: white;\n}";
    document.body.appendChild(stylesheet);
    // check the last stored setting to determine if we need to deactivate the stylesheet
    stylesheet.disabled = displayAllItems;
    return stylesheet;
}

var numberOfDiscountedItems = document.getElementsByClassName("is-discounted").length;

if (numberOfDiscountedItems) {
    //displayDiscountedCount(numberOfDiscountedItems); // probleem met 'clear filters'
    //var displayAllItems = confirm('Show only discounted items?');
    var displayAllItems = GM_getValue("displayAllItems", false);

    // create stylesheet to hide nondiscounted items
    var cssDiscountedOnly = conjureUpStylesheet();

    // create toggle switch...
    var discountedToggleDiv = document.createElement("div");
    discountedToggleDiv.className = "menu-tray";
    discountedToggleDiv.innerHTML = '<div class="menu-item discount-toggle"><a class="menu-link menu-link" id="toggleDiscounted">-%</a></div>';
    // ...and inject it into the menu bar
    var menu = document.getElementsByClassName("menu__container");
    menu[0].appendChild(discountedToggleDiv);

    function toggleDiscountedOnly() {
        displayAllItems = !displayAllItems;
        cssDiscountedOnly.disabled = displayAllItems;
        GM_setValue("displayAllItems", displayAllItems);
    }
    document.getElementById("toggleDiscounted").addEventListener("click", toggleDiscountedOnly);
}