PizzaPortal Enchancer

Skrypt dodaje brakujące opcje filtrowania do PizzaPortal

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         PizzaPortal Enchancer
// @namespace    uniquenamespace
// @version      1.0.0
// @description  Skrypt dodaje brakujące opcje filtrowania do PizzaPortal
// @author       zranoI
// @match        https://pizzaportal.pl/*/restauracje/*
// @grant        none
// ==/UserScript==

var inputValues = {
    maxPrice: Number.MAX_VALUE,
    maxDelivery: Number.MAX_VALUE
};

function apply() {
    var filterPanel = document.querySelector('.filter-and-sort-panel');
    var filterPanelContent = filterPanel.querySelector('.filter-and-sort-panel-content');
    var customFilters = createCustomFilters();
    filterPanel.insertBefore(customFilters,filterPanelContent);

    var openRestaurants = Array.from(document.querySelectorAll('.restaurant-list > ul > li'))
                           .filter(function(restaurant) {
                               var isClosed = !!restaurant.querySelector('.restaurant-closed');
                               if (isClosed) {
                                   restaurant.style.display = 'none';
                               }
                               return !isClosed;
                           });

    document.getElementById('maxPrice').addEventListener('input', function (e) {
        inputValues.maxPrice = this.value || Number.MAX_VALUE;
        updateRestaurants(openRestaurants);
    })
    document.getElementById('maxDelivery').addEventListener('input', function (e) {
        inputValues.maxDelivery = this.value || Number.MAX_VALUE;
        updateRestaurants(openRestaurants);
    });
}

function createCustomFilters() {
    var customFilters = document.createElement('div');
    customFilters.style.backgroundColor = 'white';
    customFilters.style.paddingLeft = '16px';
    customFilters.style.paddingTop = '16px';
    customFilters.style.paddingRight = '16px';
    customFilters.style.paddingBottom = '16px';
    customFilters.style.borderBottom = '1px black solid';
    customFilters.classList.add('sort-method-panel');
    customFilters.classList.add('restaurant-search-panel');
    customFilters.innerHTML =
        '<div class="sort-method-panel-title">Skryptowe opcje</div>' +
        '<input id="maxPrice" placeholder="Minimalna kwota nie większa niż" type="text" class="restaurant-search-panel-input" style="font-size: 1rem;"></input>' +
        '<input id="maxDelivery" placeholder="Dostawa nie droższa niż" type="text" class="restaurant-search-panel-input" style="font-size: 1rem; margin-top: 8px;"></input>';
    return customFilters;
}

function updateRestaurants(restaurants) {
    restaurants.forEach(function (restaurant) {
        var price = inputValues.maxPrice !== Number.MAX_VALUE ? parseFloat(restaurant.querySelector('.restaurant-payment-infos-minimum-order-value > .restaurant-payment-infos-image-container')
                                                                                     .innerText
                                                                                     .replace(',', '.'))
                                                              : 0;
        var delivery = inputValues.maxDelivery !== Number.MAX_VALUE ? parseFloat(restaurant.querySelector('.restaurant-payment-infos-delivery-fee > .restaurant-payment-infos-image-container')
                                                                                           .innerText
                                                                                           .replace(',', '.'))
                                                                    : 0;
        if (price > inputValues.maxPrice || delivery > inputValues.maxDelivery) {
            restaurant.style.display = 'none';
        } else {
            restaurant.style.display = 'block';
        }
    });
}

(function() {
    'use strict';
    setTimeout(apply, 100);
})();