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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);