Tools to help with Bootlegging
当前为
// ==UserScript==
// @name Bootlegging Plus
// @namespace Phantom Scripting
// @version 0.1
// @description Tools to help with Bootlegging
// @license MIT
// @author ErrorNullTag
// @match *.torn.com/loader.php*
// @grant unsafeWindow
// @run-at document-start
// ==/UserScript==
const originalFetch = fetch;
unsafeWindow.fetch = async (input, init) => {
const response = await originalFetch(input, init);
if (input.includes('crimesData')) {
crimesMain(response.clone()).catch(console.error);
}
return response;
};
async function crimesMain(res) {
const crimesData = await res.json();
const crimeType = crimesData?.DB?.currentUserStatistics?.[1]?.value;
if (crimeType === 'Counterfeiting') {
counterfeiting(crimesData.DB);
} else {
console.log(crimesData);
}
}
async function counterfeiting(db) {
const { generalInfo, currentUserStats, crimesByType } = db;
const CDs = {
have: generalInfo.CDs,
sold: {
1: currentUserStats.CDType1Sold,
2: currentUserStats.CDType2Sold,
3: currentUserStats.CDType3Sold,
4: currentUserStats.CDType4Sold,
5: currentUserStats.CDType5Sold,
6: currentUserStats.CDType6Sold,
7: currentUserStats.CDType7Sold,
8: currentUserStats.CDType8Sold
},
genres: {
'Action': '1',
'Comedy': '2',
'Drama': '3',
'Fantasy': '4',
'Horror': '5',
'Romance': '6',
'Thriller': '7',
'Sci-Fi': '8'
}
};
const currentQueue = crimesByType?.['0']?.additionalInfo?.currentQueue || [];
currentQueue.forEach(cdID => CDs.have[cdID] += 1);
updateGenreButtons(CDs);
}
function updateGenreButtons(CDs) {
const GREEN_HSL = 120;
const MAX_HSL = 240;
const totalHave = sumValues(CDs.have);
const totalSold = sumValues(CDs.sold);
document.querySelectorAll('button[class^=genreStock]').forEach((genreButton) => {
const genre = genreButton.getAttribute('aria-label').split(' - ')[0].replace('Copying ', '');
const typeID = CDs.genres[genre];
const target = Math.floor((CDs.sold[typeID] / totalSold) * totalHave);
let h = Math.floor((CDs.have[typeID] / target) * GREEN_HSL);
h = Math.min(h, MAX_HSL);
genreButton.style.backgroundColor = `hsl(${h}, 100%, 90%)`;
});
createColorExplanationBox();
}
function sumValues(obj) {
return Object.values(obj).reduce((a, b) => a + b, 0);
}
function createColorExplanationBox() {
const box = document.createElement('div');
box.style.position = 'absolute';
box.style.top = '10px';
box.style.right = '10px';
box.style.zIndex = '9999';
box.style.border = '1px solid #333';
box.style.borderRadius = '5px';
box.style.padding = '10px';
box.style.backgroundColor = 'white';
box.style.boxShadow = '0px 0px 10px rgba(0, 0, 0, 0.2)';
// Adding the title
const title = document.createElement('div');
title.innerText = 'Phantom Scripting';
title.style.color = 'gold';
title.style.fontWeight = 'bold';
title.style.marginBottom = '10px';
box.appendChild(title);
// The content explaining the colors
box.innerHTML += `
<strong>Color Guide:</strong><br>
<div style="background-color: hsl(120, 100%, 90%); width: 15px; height: 15px; display: inline-block; vertical-align: middle;"></div> - Target stock<br>
<div style="background-color: hsl(240, 100%, 90%); width: 15px; height: 15px; display: inline-block; vertical-align: middle;"></div> - Overstock<br>
`;
document.body.appendChild(box);
}