scrap.tf select all duplicate items

auto select duplicate items to sell

目前為 2024-01-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         scrap.tf select all duplicate items
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  auto select duplicate items to sell
// @author       calculatortamer
// @match        https://scrap.tf/sell/weapons
// @icon         https://www.google.com/s2/favicons?sz=64&domain=scrap.tf
// @grant        none
// @license MIT
// ==/UserScript==

var sell_achievement_obtainable_weapons=true
var sell_duplicate_weapons=true
var sell_gifted=false
var sell_crafted=false

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}


const tf2AchievementWeapons = [
    "Force-A-Nature", "Sandman", "Bonk! Atomic Punch",
    "Equalizer", "Direct Hit", "Buff Banner",
    "Flare Gun", "Backburner", "Axtinguisher",
    "Chargin' Targe", "Eyelander", "Scottish Resistance",
    "Sandvich", "Natascha", "Killing Gloves of Boxing",
    "Frontier Justice", "Gunslinger", "Wrangler",
    "Blutsauger", "Kritzkrieg", "Übersaw",
    "Huntsman", "Jarate", "Razorback",
    "Ambassador", "Cloak and Dagger", "Dead Ringer"
];

//checks if its ok to click
function select_item(item){
    console.log(item.classList)
    if(item.classList.contains("gifted") && !sell_gifted){
        return false
    }
	  if(item.dataset["content"].includes("Crafted by:") && !sell_crafted){
        return false
    }
    item.click()
    return true
}

(async function() {
    await sleep(3000)
    'use strict';

    var items_container=document.getElementsByClassName("user-bp-app")[0].children[0];

//check if achievement obtainable weapons are there
    if(sell_achievement_obtainable_weapons){
        for(let wep=0;wep<tf2AchievementWeapons.length;wep++){
            let items=items_container.querySelectorAll('[data-title="'+tf2AchievementWeapons[wep]+'"]');
            for(let item=0;item<items.length;item++){
                select_item(items[item])
            }
        }
    }
    //check if duplicate weapons are there
    if(sell_duplicate_weapons){
        //get all weapon names
        let weapon_names=[]
        for(let i=0;i<items_container.children.length;i++){
            let item=items_container.children[i]
            let title=item.dataset["title"]
            if(!weapon_names.includes(title) && !tf2AchievementWeapons.includes(title)){
                weapon_names.push(title)
            }
        }
        //find all duplicate weapons
        for(let i=0;i<weapon_names.length;i++){
            let items=items_container.querySelectorAll('[data-title="'+weapon_names[i]+'"]');
            let items_clicked=0
            for(let item=0;item<items.length && items_clicked<items.length-1 ;item++){
                if(select_item(items[item])){
                    items_clicked++
                }
            }
        }
    }
})();