Greasy Fork is available in English.

CherryPicker Slayer! - Stow

Find those cherrypickers!

// ==UserScript==
// @name         CherryPicker Slayer! - Stow
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Find those cherrypickers!
// @author       milcz
// @match        https://fclm-portal.amazon.com/reports/*&processId=01002976*
// @match        https://fclm-portal.amazon.com/reports/*&processId=1002976*
// @match        https://fclm-portal.amazon.com/reports/*&processId=01003016*
// @match        https://fclm-portal.amazon.com/reports/*&processId=1003016*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAABnlBMVEX///+MoAFhbgLDAAitAAaBAAWlAAafAAW+AAazAAbXAAe5AAawAAWXAAecAAjJAAiRAAWisAHdAAfTAAmMAAVpeAOIAAbIAQjrAAepAAXlAAfgAAjnAAj1AAiClACdrAB5AABaaACFmgD7AAl8jgBndQNVZAD/l5ZtfgP8/PJ1hgPRAADR15Tt7tm0v0TM4EuLniD19uecrTeir2H/kZb27Ozotba5w1LCzHDd4K+1v3fJ0n2/x5CwwCGeq0u8zDSqtSaJljHu8Nfc4r+lrnSxvGzJzq3m59OstYN7hynb4Me5vJeRnVXP1qzi5byOm0WjrXbGzpWJlEmmt1OTnWTL05rV3bLP0bavtIuttHqPniabqlGfrWD64eKVozvzzs3pk5XjYWHfS07amp7aKSrNXV69LjCoKCrDbW/durn10NCqmwD139bWrq3OTEvCenyzgQPBZQSCTwfNmZr6enp/aAStUVCFhATGJSfqKCuKFhiHXAauQULbbW2ugD/HZVrbPUDuPDr4pqmiYGLwIiWOJyraxcaWP0K7hIa0XF+C9/+xAAAQPklEQVR4nO2ci1sTVxrGyUASIAkJlySQ4CRMJ5CEi6ZrEG+LhbWtvbBt3V53U0ClC7TW3WptdWUrpbr6X++532YCSZjxTHjyPrZignB+vt/5vu9chr6+nnrqqaeeeuqpp5566ukMq7JwaWnlckX3MPzT5UJhdBT8d6WmeyR+6Wrh+iiUaV/TPRSftFI4jxBN0/6z7rH4o5XR86uY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JpkU8yhhv1woxBiVFk4oSPXWe6j9OBilEqgipais4GAsJlhI04yjVGivhlDwZiGJU8FHJ2NW9I8TYkClVHBCvUsnrF3iIZuLQsJpZqBooZRmpCANQq2A2oyLiAKjU/39Qo6RQ5THqJRnghCkfX1xGZEwOiAZnkI4JZdCKUY172BQPRAQBRtFSv4Kw1NC1FHsg5JJoRoDCNHNR0Wyf6hOqJNQtlB/ucd6FseIAqGTkr7KAXGpH5AtlEuF3g0MruWpARHR1UeJjwAODDRLM5RQd0/KFAGDjSuQgpkiG8WjBsqAEl8QOjaqu1OMcKgJYUwhxL2aGKJOwmK7d4T9Ux0QMkTRRqeGhsQcwxx0JQzr5hK0OwUZT4QU8WiViHA+1cJglAqsxtQUsfFYRBcDhRBVHQyShchE6iJhlED5K/ATRAubh2igLAQmRqamCCSiFDElOvQZkoGKg4xQ76GaU7sRxhhvgkjtg3iuISpbGJxEilWPRjAjt9EpxUAlRGXCoFnY1/cqigbNg9VN6F0Rr5mDAWpnuEYiHBGUcicdAXQxkDnIAMMBeQxB0l40QuVqpEjHc4x7iAZmUSFrN8oZuZtU0ltShDpDNGiVggkMOhJtgujKxwFJiFLC4LTcshpROPjI8YpGnYATtBAGOkah7o/Q8R9P5/QP8wU4j1I9HIkSSBiu+FeEfkDpOB+fghJgQCch1oMEs5G6qfx5ZMQNUAjRwGxdNNGrBCKIumqkCZ6QRQMPCAI1QUEQEvnfiGKeYwp2DyCo/AzRTRKfYwoGYxf/RNWfJSBIMzYZT3KwqP0RoFb1MHGcUqp/NMUUjwJbBx2qv55IHUcnGUh2ZYpHAXmsuUU1XqdSbmQCHZ2BGYQXtAVvC2o8AFyJlIrHAYl9xcyLV3vdE56y9o5SE+509LLM0wcPX3YrHVHj4dELxCW3L5mnj48evgzE8acXqjf27r86ev0Y6vWDV/fvv6x3uW899dRTTz311FNPPfXUUxv6P2j+MLE4KNfSAAAAAElFTkSuQmCC
// @grant        none
// @run-at       document-idle
// ==/UserScript==


function go() {
    'use strict';

    if (document.querySelectorAll('.tablesorter-headerRow').length > 3) {
    const eachStowHeader = document.querySelectorAll('.tablesorter-headerRow')[1]
    const header = document.createElement('th')
    header.innerHTML = 'Product Mix'
    header.setAttribute('colspan', '3')
    eachStowHeader.appendChild(header)
    const eachStowHeaderS = document.createElement('th')
    const eachStowHeaderM = document.createElement('th')
    const eachStowHeaderL = document.createElement('th')
    eachStowHeaderS.innerHTML = 'Small'
    eachStowHeaderM.innerHTML = 'Medium'
    eachStowHeaderL.innerHTML = 'Large'
    eachStowHeaderS.style.cursor = 'pointer'
    eachStowHeaderM.style.cursor = 'pointer'
    eachStowHeaderL.style.cursor = 'pointer'
    document.querySelectorAll('.tablesorter-headerRow')[2].appendChild(eachStowHeaderS)
    document.querySelectorAll('.tablesorter-headerRow')[2].appendChild(eachStowHeaderM)
    document.querySelectorAll('.tablesorter-headerRow')[2].appendChild(eachStowHeaderL)
    eachStowHeaderS.setAttribute('id', 'each-stow-header-S')
    eachStowHeaderM.setAttribute('id', 'each-stow-header-M')
    eachStowHeaderL.setAttribute('id', 'each-stow-header-L')
    eachStowHeaderS.addEventListener('click', sortBySmalls)
    eachStowHeaderM.addEventListener('click', sortByMediums)
    eachStowHeaderL.addEventListener('click', sortByLarges)
    }

    const eachStowHeaderNike = document.querySelectorAll('.tablesorter-headerRow')[document.querySelectorAll('.tablesorter-headerRow').length - 2]
    const headerNike = document.createElement('th')
    headerNike.innerHTML = 'Product Mix'
    headerNike.setAttribute('colspan', '3')
    eachStowHeaderNike.appendChild(headerNike)
    const eachStowHeaderNikeS = document.createElement('th')
    const eachStowHeaderNikeM = document.createElement('th')
    const eachStowHeaderNikeL = document.createElement('th')
    eachStowHeaderNikeS.innerHTML = 'Small'
    eachStowHeaderNikeM.innerHTML = 'Medium'
    eachStowHeaderNikeL.innerHTML = 'Large'
    eachStowHeaderNikeS.style.cursor = 'pointer'
    eachStowHeaderNikeM.style.cursor = 'pointer'
    eachStowHeaderNikeL.style.cursor = 'pointer'
    document.querySelectorAll('.tablesorter-headerRow')[document.querySelectorAll('.tablesorter-headerRow').length - 1].appendChild(eachStowHeaderNikeS)
    document.querySelectorAll('.tablesorter-headerRow')[document.querySelectorAll('.tablesorter-headerRow').length - 1].appendChild(eachStowHeaderNikeM)
    document.querySelectorAll('.tablesorter-headerRow')[document.querySelectorAll('.tablesorter-headerRow').length - 1].appendChild(eachStowHeaderNikeL)
    eachStowHeaderNikeS.setAttribute('id', 'each-stow-header-nike-S')
    eachStowHeaderNikeM.setAttribute('id', 'each-stow-header-nike-M')
    eachStowHeaderNikeL.setAttribute('id', 'each-stow-header-nike-L')
    eachStowHeaderNikeS.addEventListener('click', sortBySmallsNike)
    eachStowHeaderNikeM.addEventListener('click', sortByMediumsNike)
    eachStowHeaderNikeL.addEventListener('click', sortByLargesNike)

    const rows = document.querySelectorAll('.empl-all[role="row"]:not(.total)')

    for (let row of rows) {
    const smallCell = document.createElement('td')
    const mediumCell = document.createElement('td')
    const largeCell = document.createElement('td')

    smallCell.innerHTML = Math.round(Number(row.cells[11].innerHTML) * 100 / Number(row.cells[19].innerHTML)) + '%'
    mediumCell.innerHTML = Math.round(Number(row.cells[13].innerHTML) * 100 / Number(row.cells[19].innerHTML)) + '%'
    largeCell.innerHTML = Math.round(Number(row.cells[15].innerHTML) * 100 / Number(row.cells[19].innerHTML)) + '%'
    row.appendChild(smallCell)
    row.appendChild(mediumCell)
    row.appendChild(largeCell)
    }


};

setTimeout(go,5000);

function sortBySmallsNike(){
    const eachStowHeaderNikeS = document.getElementById('each-stow-header-nike-S')
    const rowsArray = []
    for (let row of [...document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].children]) {
        if (row.cells[21].innerHTML != 'NaN%') {
         rowsArray.push(row)
        }
    }
    let sortedRows = ''
    if (document.getElementById('each-stow-header-nike-S').getAttribute('data-sort') != 'asc'){
    sortedRows = rowsArray.sort((a ,b) => Number(b.cells[21].innerHTML.slice(0,-1)) - Number(a.cells[21].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-nike-S').setAttribute('data-sort', 'asc')
    } else {
    sortedRows = rowsArray.sort((a ,b) => Number(a.cells[21].innerHTML.slice(0,-1)) - Number(b.cells[21].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-nike-S').setAttribute('data-sort', 'dsc')
    }

    while (document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].firstChild) {
    document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].removeChild(document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].lastChild);
  }
    for (let row of sortedRows){
        document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].appendChild(row)
    }
}
function sortByMediumsNike(){
    const eachStowHeaderNikeS = document.getElementById('each-stow-header-nike-M')
    const rowsArray = []
    for (let row of [...document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].children]) {
        if (row.cells[21].innerHTML != 'NaN%') {
         rowsArray.push(row)
        }
    }
    let sortedRows = ''
    if (document.getElementById('each-stow-header-nike-M').getAttribute('data-sort') != 'asc'){
    sortedRows = rowsArray.sort((a ,b) => Number(b.cells[22].innerHTML.slice(0,-1)) - Number(a.cells[22].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-nike-M').setAttribute('data-sort', 'asc')
    } else {
    sortedRows = rowsArray.sort((a ,b) => Number(a.cells[22].innerHTML.slice(0,-1)) - Number(b.cells[22].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-nike-M').setAttribute('data-sort', 'dsc')
    }

    while (document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].firstChild) {
    document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].removeChild(document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].lastChild);
  }
    for (let row of sortedRows){
        document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].appendChild(row)
    }
}
function sortByLargesNike(){
    const eachStowHeaderNikeL = document.getElementById('each-stow-header-nike-L')
    const rowsArray = []
    for (let row of [...document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].children]) {
        if (row.cells[21].innerHTML != 'NaN%') {
         rowsArray.push(row)
        }
    }
    let sortedRows = ''
    if (document.getElementById('each-stow-header-nike-L').getAttribute('data-sort') != 'asc'){
    sortedRows = rowsArray.sort((a ,b) => Number(b.cells[23].innerHTML.slice(0,-1)) - Number(a.cells[23].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-nike-L').setAttribute('data-sort', 'asc')
    } else {
    sortedRows = rowsArray.sort((a ,b) => Number(a.cells[23].innerHTML.slice(0,-1)) - Number(b.cells[23].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-nike-L').setAttribute('data-sort', 'dsc')
    }

    while (document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].firstChild) {
    document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].removeChild(document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].lastChild);
  }
    for (let row of sortedRows){
        document.querySelectorAll('table')[document.querySelectorAll('table').length - 1].children[2].appendChild(row)
    }
}
function sortBySmalls(){
    const eachStowHeaderNikeS = document.getElementById('each-stow-header-S')
    const rowsArray = []
    for (let row of [...document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].children]) {
        if (row.cells[21].innerHTML != 'NaN%') {
         rowsArray.push(row)
        }
    }
    let sortedRows = ''
    if (document.getElementById('each-stow-header-S').getAttribute('data-sort') != 'asc'){
    sortedRows = rowsArray.sort((a ,b) => Number(b.cells[21].innerHTML.slice(0,-1)) - Number(a.cells[21].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-S').setAttribute('data-sort', 'asc')
    } else {
    sortedRows = rowsArray.sort((a ,b) => Number(a.cells[21].innerHTML.slice(0,-1)) - Number(b.cells[21].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-S').setAttribute('data-sort', 'dsc')
    }

    while (document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].firstChild) {
    document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].removeChild(document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].lastChild);
  }
    for (let row of sortedRows){
        document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].appendChild(row)
    }
}
function sortByMediums(){
    const eachStowHeaderS = document.getElementById('each-stow-header-nike-M')
    const rowsArray = []
    for (let row of [...document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].children]) {
        if (row.cells[21].innerHTML != 'NaN%') {
         rowsArray.push(row)
        }
    }
    let sortedRows = ''
    if (document.getElementById('each-stow-header-M').getAttribute('data-sort') != 'asc'){
    sortedRows = rowsArray.sort((a ,b) => Number(b.cells[22].innerHTML.slice(0,-1)) - Number(a.cells[22].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-M').setAttribute('data-sort', 'asc')
    } else {
    sortedRows = rowsArray.sort((a ,b) => Number(a.cells[22].innerHTML.slice(0,-1)) - Number(b.cells[22].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-M').setAttribute('data-sort', 'dsc')
    }

    while (document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].firstChild) {
    document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].removeChild(document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].lastChild);
  }
    for (let row of sortedRows){
        document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].appendChild(row)
    }
}
function sortByLarges(){
    const eachStowHeaderNikeL = document.getElementById('each-stow-header-L')
    const rowsArray = []
    for (let row of [...document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].children]) {
        if (row.cells[21].innerHTML != 'NaN%') {
         rowsArray.push(row)
        }
    }
    let sortedRows = ''
    if (document.getElementById('each-stow-header-L').getAttribute('data-sort') != 'asc'){
    sortedRows = rowsArray.sort((a ,b) => Number(b.cells[23].innerHTML.slice(0,-1)) - Number(a.cells[23].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-L').setAttribute('data-sort', 'asc')
    } else {
    sortedRows = rowsArray.sort((a ,b) => Number(a.cells[23].innerHTML.slice(0,-1)) - Number(b.cells[23].innerHTML.slice(0,-1)))
    document.getElementById('each-stow-header-L').setAttribute('data-sort', 'dsc')
    }

    while (document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].firstChild) {
    document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].removeChild(document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].lastChild);
  }
    for (let row of sortedRows){
        document.querySelectorAll('table')[document.querySelectorAll('table').length - 2].children[2].appendChild(row)
    }
}