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.

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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);
}