TipidPC User Items To Sortable Table

Transforms the User's Items for Sale list to sortable and searchable table

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         TipidPC User Items To Sortable Table
// @description  Transforms the User's Items for Sale list to sortable and searchable table
// @namespace    https://github.com/rainniel/tampermonkey-scripts
// @supportURL   https://github.com/rainniel/tampermonkey-scripts/issues
// @version      1.0
// @author       Rainniel
// @license      MIT
// @match        https://tipidpc.com/useritems.php*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=tipidpc.com
// @require      https://unpkg.com/[email protected]/js/dataTables.min.js
// @run-at       document-start
// @grant        GM_addStyle
// ==/UserScript==

(function () {
    'use strict';

    GM_addStyle(`
        .item-manager {
            display: none !important;
        }
    `);

    var $ = unsafeWindow.jQuery;

    $(document).ready(function () {
        var dataTablesCss = document.createElement('link');
        dataTablesCss.rel = 'stylesheet';
        dataTablesCss.href = 'https://cdn.datatables.net/2.2.2/css/dataTables.dataTables.min.css';
        document.head.appendChild(dataTablesCss);

        var pad10Div = $('.pad10');

        if (pad10Div.length > 0) {
            var window2div = pad10Div.find('.window').eq(1);
            var userIfs = window2div.find('#user-ifs');

            if (userIfs.length > 0) {
                var data = [];

                userIfs.find('li').each(function () {
                    var $li = $(this);
                    var nameLink = $li.find('h4 a');
                    var name = nameLink.text();
                    var nameUrl = nameLink.attr('href');
                    var priceText = $li.find('.meta strong').text();
                    var price = parseFloat(priceText.replace(/[^0-9.-]+/g, ""));
                    var catalogLink = $li.find('.meta a');
                    var catalog = catalogLink.text();
                    var catalogUrl = catalogLink.attr('href');

                    data.push([
                        `<a href="${nameUrl}" target="_blank">${name}</a>`,
                        new Intl.NumberFormat('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(price),
                        `<a href="${catalogUrl}" target="_blank">${catalog}</a>`
                    ]);
                });

                window2div.find('.winbody').prepend('<div style="padding: 0 12px;"><table id="userItems" class="display"></table></div>');

                $('#userItems').DataTable({
                    columns: [
                        { title: "Name" },
                        { title: "Price" },
                        { title: "Catalog" }
                    ],
                    data: data,
                    pageLength: 20,
                    lengthMenu: [10, 20, 30, 40, 50]
                });

                $('.dt-container').css('clear', 'none');
            }
        }
    });
})();