DeGiro improved filters

Adds missing sort options

נכון ליום 30-12-2020. ראה הגרסה האחרונה.

// ==UserScript==
// @name         DeGiro improved filters
// @namespace    https://yelidmod.com/degiro
// @version      0.1
// @description  Adds missing sort options
// @author       DonNadie
// @match        https://trader.degiro.nl/*
// @grant        none
// ==/UserScript==

// jshint esversion: 6

(function() {
    'use strict';

    let filterIndex;
    const sortButton = '<i role="img" data-name="icon" data-type="sort" aria-hidden="true" class="ife-sort-icon"><svg viewBox="0 0 24 24"><path d="M16.8 13.2L12 18l-4.8-4.8h9.6zM12 6l4.8 4.8H7.2L12 6z"></path></svg></i>';

    const addStyle = (styleString) => {
        const style = document.createElement('style');
        style.textContent = styleString;
        document.head.append(style);
    };

    const sort = () => {
        const trList = document.querySelectorAll('[data-name="productTypeSearch"] tr');

        new Promise((resolve, reject) => {
            let list = [];
            let val;
            trList.forEach((tr, e) => {
                tr.querySelectorAll('td').forEach((td, i) => {
                    if (i === filterIndex) {
                        val = parseInt(td.innerText.replace(".", ""));
                        list.push({
                            tr: tr,
                            value : isNaN(val) ? 0 : val
                        });
                    }
                });
                if (e == (trList.length - 1)) {
                    resolve(list);
                }
            });
        }).then(list => {
            list.sort((a, b) => (a.value < b.value) ? 1 : -1);
            list.forEach(entry => {
                document.querySelector('[data-name="productTypeSearch"] tbody').appendChild(entry.tr);
            });
        });

    };

    const onLoaded = () => {
        document.querySelectorAll('[data-name="productTypeSearch"] th').forEach((el, i) => {
            if (el.innerText != "Volumen") {
                return;
            }
            filterIndex = i;
            el.classList.add('ife-container');
            el.innerHTML += sortButton;
            el.addEventListener("click", sort);
        });
    };

    addStyle(`
     .ife-container {
        align-items: center;
        display: flex;
        flex-direction: row;
        padding-right: 12px;
        position: relative;
     }
     .ife-sort-icon {
        contain: strict;
        display: inline-block;
        flex-shrink: 0;
        font-style: normal;
        font-weight: 400;
        line-height: 1;
        opacity: 1;
        overflow: hidden;
        width: 20px;
        height: 20px;
        text-align: center;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        vertical-align: middle;
        position: absolute;
        right: -8px;
        top: 50%;
        transform: translateY(-50%);
        cursor: pointer;
   }
   `);

    let appLoadedInterval = setInterval(() => {
        if (document.querySelectorAll('[data-name="productTypeSearch"] th').length > 0) {
            clearInterval(appLoadedInterval);
            onLoaded();
        }
    }, 1000);
})();
长期地址
遇到问题?请前往 GitHub 提 Issues。