Skip to content

Instantly share code, notes, and snippets.

@fosron
Created January 23, 2024 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fosron/6595b6515d2bfde35688248c9ff5632b to your computer and use it in GitHub Desktop.
Save fosron/6595b6515d2bfde35688248c9ff5632b to your computer and use it in GitHub Desktop.
get all packs in chrome dev tools
// Create an object to hold the titles and their counts
let titleCounts = {};
// Select all elements with the class 'ut-store-pack-details-view'
let packs = document.querySelectorAll('.ut-store-pack-details-view');
// Iterate over the NodeList
packs.forEach((pack) => {
// Determine if the pack is tradeable or untradeable
let tradeStatus = pack.classList.contains('is-tradeable') ? 'Tradeable' : 'Untradeable';
// Get the text content of the span inside the title element
let titleText = pack.querySelector('.ut-store-pack-details-view--title span').textContent.trim();
// Create a unique key for each title with its trade status
let key = titleText + ' (' + tradeStatus + ')';
// Check if the key is already in the object
if (titleCounts[key]) {
// If it is, increment the count
titleCounts[key]++;
} else {
// If not, add it to the object with a count of 1
titleCounts[key] = 1;
}
});
// Function to convert data to CSV format
function convertToCSV(objArray) {
const array = typeof objArray !== 'object' ? JSON.parse(objArray) : objArray;
let str = `Title,Trade Status,Count\n`;
for (let i = 0; i < array.length; i++) {
let line = '';
for (let index in array[i]) {
if (line !== '') line += ',';
line += array[i][index];
}
str += line + '\r\n';
}
return str;
}
// Convert the title counts to an array and then to CSV
let titlesArray = Object.keys(titleCounts).map(key => {
let [title, tradeStatus] = key.split(' (');
tradeStatus = tradeStatus.replace(')', ''); // Remove closing parenthesis
return { title, tradeStatus, count: titleCounts[key] };
});
let csvContent = convertToCSV(titlesArray);
// Log the CSV content
console.log(csvContent);
// Optional: Automatically download the CSV file
var blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
var link = document.createElement("a");
var url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", "titles.csv");
link.style.visibility = 'hidden';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment