EasyPrice

Hides items that are more expensive than a predecessor in the market when sorting by Quality, Accuracy, Damage or Armor in Desc order only

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         EasyPrice
// @namespace    gaskarth.torn
// @version      0.0.7
// @description  Hides items that are more expensive than a predecessor in the market when sorting by Quality, Accuracy, Damage or Armor in Desc order only
// @author       Gaskarth
// @match        https://www.torn.com/page.php?sid=ItemMarket*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @grant        none
// @license      MIT
// ==/UserScript==

/**
INSTRUCTIONS

When buying fungible items in Torn we all sort by price ascending and buy the cheapest because they are all the same.
But Weapons and Armor are not all the same and we want the best cheap ones :)

* Install this script then
* go to the Item Market page for weapons or armor and
* change Sort by from price to one of the other attributes in DESCENDING order - overpriced items will hide with embarrisment.

Sorting in Descending attribute order shows the best ones first and the script will then dim any item that is more expensive than a previous better example.

If you save a load of money and time please send me a xanax and words of encouragment every so often.

**/

'use strict';

const hiddenOpacity = 0.3,
      interval = 500;

function updateList() {
    let best = null, order = null, direction = null, failReason = '';

    //
    const dropdowns = [...document.querySelectorAll('input[type="hidden"][value*=":"]:not([value*="{"])')]
        .reduce((acc, el) => {
        const [order, direction] = el.value.split(':');
        if (["accuracy", "quality", "damage","armor"].includes(order)) {
            acc.push({ order, direction });
        }
        return acc;
    }, []);
    if (dropdowns && dropdowns.length) {
        order = dropdowns[0].order;
        direction = dropdowns[0].direction
    }
    if (order) {
        Array.from(document.querySelectorAll('.priceAndTotal___eEVS7'))
            .map(el => (
            {
                el: el,
                value: (+el.innerText.replace(/[^0-9]/g, ''))
            }))
            .forEach(m => {
            if (!best) { best = m.value; }
            if (direction === 'DESC') {
                m.el.closest('li').style.opacity = (m.value > best) ? hiddenOpacity : 1;
                if (m.value < best) best = m.value;
            } else { failReason = 'EasyPrice: choose descending' }
        });
    } else {
        failReason = 'EasyPrice: Choose QUAL, ACC or DMG'
    }
    document.querySelector('.title___rhtB4').innerText = (failReason)? failReason:'Item Market : EasyPrice ON';
    document.querySelector('.dropdowns___QIaHL').lastChild.style.backgroundColor=failReason? 'red':'green';

}

let inter = setInterval(updateList, interval);