Wish.com - Price filter & more

Filtering by min/max price & allow hidding free products

目前為 2018-03-29 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Wish.com - Price filter & more
// @namespace    http://tampermonkey.net/
// @version      2.2
// @description  Filtering by min/max price & allow hidding free products
// @author       Shuunen, [email protected]
// @match        https://*.wish.com/*
// @grant        none
// ==/UserScript==

$(document).ready(function() {

    console.log('wish price filter : init');

    // Returns a function, that, as long as it continues to be invoked, will not
    // be triggered. The function will be called after it stops being called for
    // N milliseconds. If `immediate` is passed, trigger the function on the
    // leading edge, instead of the trailing.
    function debounce(func, wait, immediate) {
        var timeout;
        return function() {
            var context = this, args = arguments;
            var later = function() {
                timeout = null;
                if (!immediate) func.apply(context, args);
            };
            var callNow = immediate && !timeout;
            clearTimeout(timeout);
            timeout = setTimeout(later, wait);
            if (callNow) func.apply(context, args);
        };
    }

    function showHideProducts() {
        // hide already rated products in order hsitory
        $('.edit-rating-button').parents('.transaction-expanded-row-item').hide();
        // hide products that can't be rated
        $('.late-box').parents('.transaction-expanded-row-item');
        console.log('wish price filter : showHideProducts');
        var minPrice = parseInt($("#wtc_min_price").val()) || 0;
        var maxPrice = parseInt($("#wtc_max_price").val()) || 1000;
        var hideFree = $("#wtc_hide_free").is(':checked');
        sessionStorage.wishHidefree = hideFree;
        // console.log('wish price filter : hide free items ?', hideFree);
        var items = $(".feed-actual-price");
        $.each( items, function() {
            var price = $(this).text().replace(/\D/g,'');
            var priceOk = (price <= maxPrice);
            if(minPrice && minPrice > 0){
                priceOk = priceOk && (price >= minPrice);
            }
            if(priceOk && hideFree && this.textContent.includes('Free')){
                priceOk = false;
            }
            $(this).parent().parent().parent().parent().toggle(priceOk);
        });
    }

    if ($("#nav-search").length > 0){
        $('#mobile-app-buttons').hide();
        $('#nav-search-input-wrapper').width(320);
        var html = '<div id="wish_tweaks_config" style="float:left;margin-top:10px;display:flex;justify-content:space-between;width:280px;align-items:center;font-weight: bold;font-size: 13px;font-family: sans-serif;color: white;background-color: steelblue;padding:6px 12px;border-radius: 5px;">';
        html += 'Min / Max Price : <input id="wtc_min_price" type="text" style="width: 30px; margin-left: 5px;">&nbsp;/<input id="wtc_max_price" type="text" style="width: 30px; margin-left: 5px;">';
        html += '<div style="margin-left: auto"></div>';
        html += 'Hide free : <input id="wtc_hide_free" type="checkbox" checked style="margin: 0; height: 16px; width: 16px; margin-left: 5px;">';
        html += '</div>';
        $("#header-left").after(html);
    }

    // restore previous choices
    var hideFreeCheckbox = $("#wtc_hide_free");
    hideFreeCheckbox.attr('checked', (sessionStorage.wishHidefree === 'true'));

    // prepare a debounced function
    var showHideProductsDebounced = debounce(showHideProducts, 500);

    // trigger twice by default
    showHideProductsDebounced();
    setTimeout(showHideProductsDebounced, 1000);

    // when window is scrolled
    window.onscroll = showHideProductsDebounced;

    // when input value change
    $("#wtc_hide_free").change(showHideProductsDebounced);
    $("#wtc_min_price").keydown(showHideProductsDebounced);
    $("#wtc_max_price").keydown(showHideProductsDebounced);

});