Ahab / market fix

// ==UserScript==
// @name         market fix
// @namespace    torn
// @version      0.3
// @description  try to take over the world!
// @author       Ahab
// @match        https://www.torn.com/page.php?sid=ItemMarket*
// @require      https://gist.githubusercontent.com/BrockA/2625891/raw/9c97aa67ff9c5d56be34a55ad6c18a314e5eb548/waitForKeyElements.js
// @grant        GM_addStyle
// @license      MIT
// ==/UserScript==

GM_addStyle(`
#posOption:hover{
    background: var(--default-bg-panel-active-color)!important;
}

div[class*="categoryGroup___"] div[class*="title___"]{
    background: var(--title-black-gradient);
    color: var(--tutorial-title-color);
}
div[class*="itemsHeader___"]{
    background: var(--title-black-gradient);
    color: var(--tutorial-title-color);
    border-top: 1px solid var(--title-black-gradient);
}
#posOption{
    background-color: var(--default-bg-panel-color);
    color: var(--item-market-color);
    border-radius: var(--item-market-border-radius);
    box-shadow: var(--item-market-shadow);
    cursor: pointer;
}
div[class*="price___"]{
    font-weight: 100 !important;
    justify-content: center;
}
`)

if(localStorage.catPos === undefined){
    localStorage.catPos = 'Left'
}

function bleh(){
    $('div[class*="categoriesWrapper___"]').append('<button id="posOption" type="button">Move '+localStorage.catPos+'</button>')

    $('button[id*="posOption"]').on('click', function(event) {
        console.log($('button[id*="posOption"]').text())
        if($('button[id*="posOption"]').text().split(' ')[1] == 'Left'){
            localStorage.catPos = 'Right'
            $('div[class*="marketWrapper___"]').css('cssText', 'grid-template-columns: 160px 1fr')
            $('div[class*="categoriesWrapper___"]').css('cssText', 'order: -1')
            $('button[id*="posOption"]').text('Move Right')
        }else{
            localStorage.catPos = 'Left'
            $('div[class*="marketWrapper___"]').css('cssText', 'grid-template-columns: 1fr 160px')
            $('div[class*="categoriesWrapper___"]').css('cssText', 'order: 1')
            $('button[id*="posOption"]').text('Move Left')
        }
    })

    if(localStorage.catPos == 'Right'){
        $('div[class*="marketWrapper___"]').css('cssText', 'grid-template-columns: 160px 1fr')
        $('div[class*="categoriesWrapper___"]').css('cssText', 'order: -1')
    }

    var observerTarget = $('div[class*="itemListWrapper___"]')[0];
    var observerConfig = { attributes: false, childList: true, characterData: false, subtree: true };
    var observer = new MutationObserver(function(mutations) {
        $('div[class*="thumbnail___"]').remove()
    })
    observer.observe(observerTarget, observerConfig);
}

waitForKeyElements("div[class^='marketWrapper___']", bleh);