Last active
January 30, 2024 07:38
-
-
Save hashdashme/18718e0a68692d70cec7d0cd2d4693db to your computer and use it in GitHub Desktop.
Hides Spell and paint listings in buyorders. Press 'raw' to install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Backpack.tf Buy Order Cleaner | |
| // @namespace http://tampermonkey.net/ | |
| // @version 1.0 | |
| // @description Does something i guess. | |
| // @author hashdash | |
| // @match https://backpack.tf/* | |
| // @grant none | |
| // ==/UserScript== | |
| (function() { | |
| 'use strict'; | |
| const url = window.location.href; | |
| const badAttributes = ['data-paint_name', 'data-spell_1', 'data-spell_2']; | |
| const listingSelector = url.includes("premium") ? "li.item" : "div.item"; | |
| const listings = document.querySelectorAll(listingSelector); | |
| if (!listings || !listings.length) return; | |
| let listingsAffected = 0; | |
| let listingsPruned = false; | |
| function processBuyListings() { | |
| listingsAffected = 0; | |
| listingsPruned = !listingsPruned; | |
| for (const listing of listings) { | |
| const isBuyOrder = listing.getAttribute('data-listing_intent') === 'buy'; | |
| const hasBadAttribute = badAttributes.some(attribute => listing.getAttribute(attribute) !== null); | |
| if (hasBadAttribute && isBuyOrder) { | |
| console.log(listing); | |
| toggleListingVisibility(listing); | |
| listingsAffected++; | |
| } | |
| } | |
| console.log(`${listingsAffected} listings affected`); | |
| } | |
| function toggleListingVisibility(listing) { | |
| const currentStyle = listing.parentNode.parentNode.style; | |
| currentStyle.display = currentStyle.display === 'none' ? null : 'none'; | |
| } | |
| function addShinyThings() { | |
| const shinyElement = document.createElement('li'); | |
| shinyElement.classList.add('list-group-item', 'justify-content-between', 'align-items-center'); | |
| shinyElement.style.marginBottom = '12px'; | |
| shinyElement.style.display = 'flex'; | |
| shinyElement.style.justifyContent = 'space-between'; | |
| shinyElement.style.alignItems = 'center'; | |
| const shinyButtons = document.createElement('div'); | |
| shinyButtons.style.display = 'flex'; | |
| shinyButtons.style.alignItems = 'center'; | |
| const toggleBtn = document.createElement('button'); | |
| toggleBtn.onclick = processBuyListings; | |
| toggleBtn.textContent = 'Toggle'; | |
| shinyButtons.appendChild(toggleBtn); | |
| const badgeSpan = document.createElement('span'); | |
| badgeSpan.classList.add('badge', 'badge-primary', 'badge-pill'); | |
| badgeSpan.textContent = listingsAffected; | |
| const statsDiv = document.createElement('div'); | |
| statsDiv.style.display = 'flex'; | |
| statsDiv.style.gap = '6px'; | |
| statsDiv.style.alignItems = 'center'; | |
| statsDiv.textContent = 'Listings Affected' | |
| statsDiv.appendChild(badgeSpan); | |
| shinyElement.appendChild(shinyButtons); | |
| shinyElement.appendChild(statsDiv); | |
| const buyOrderDiv = document.querySelector('.col-md-6:nth-child(2)'); | |
| const dropzone = buyOrderDiv.querySelector('.item').parentElement.parentElement.parentElement; | |
| dropzone.insertBefore(shinyElement, dropzone.firstChild); | |
| console.log('shiny thing loaded'); | |
| } | |
| processBuyListings(); | |
| if (listingsAffected) addShinyThings(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment