// ==UserScript==
// @name Torn OC Role Evaluator
// @namespace underko.torn.scripts.oc
// @version 1.5
// @description Evaluate OC roles based on influence and success chance
// @author underko[3362751]
// @match https://www.torn.com/factions.php*
// @grant none
// @require https://update.greasyfork.org/scripts/502635/1422102/waitForKeyElements-CoeJoder-fork.js
// @license MIT
// ==/UserScript==
(function () {
'use strict';
const influenceThresholds = {
high: { good: 75, ok: 60 },
medium: { good: 60, ok: 45 },
low: { good: 40, ok: 30 }
};
const ocRoleInfluence = {
"Pet Project": [
{ role: "Kidnapper", influence: 40.45 },
{ role: "Muscle", influence: 27.56 },
{ role: "Picklock", influence: 31.99 }
],
"Mob Mentality": [
{ role: "Looter #1", influence: 36.15 },
{ role: "Looter #2", influence: 25.92 },
{ role: "Looter #3", influence: 17.93 },
{ role: "Looter #4", influence: 20 }
],
"Cash Me if You Can": [
{ role: "Thief #1", influence: 44.43 },
{ role: "Thief #2", influence: 20.2 },
{ role: "Lookout", influence: 35.37 }
],
"Best of the Lot": [
{ role: "Picklock", influence: 23.73 },
{ role: "Car Thief", influence: 21.29 },
{ role: "Muscle", influence: 37.37 },
{ role: "Imitator", influence: 17.6 }
],
"Market Forces": [
{ role: "Enforcer", influence: 27.14 },
{ role: "Negotiator", influence: 25.26 },
{ role: "Lookout", influence: 19.44 },
{ role: "Arsonist", influence: 4.26 },
{ role: "Muscle", influence: 23.9 }
],
"Smoke and Wing Mirrors": [
{ role: "Car Thief", influence: 50.87 },
{ role: "Imitator", influence: 25.47 },
{ role: "Hustler #1", influence: 7.01 },
{ role: "Hustler #2", influence: 16.66 }
],
"Stage Fright": [
{ role: "Enforcer", influence: 16.82 },
{ role: "Muscle #1", influence: 22.27 },
{ role: "Muscle #2", influence: 1.8 },
{ role: "Muscle #3", influence: 9.31 },
{ role: "Lookout", influence: 6.84 },
{ role: "Sniper", influence: 42.96 }
],
"Snow Blind": [
{ role: "Hustler", influence: 52.28 },
{ role: "Imitator", influence: 31.42 },
{ role: "Muscle #1", influence: 8.15 },
{ role: "Muscle #2", influence: 8.15 }
],
"Leave No Trace": [
{ role: "Techie", influence: 23.34 },
{ role: "Negotiator", influence: 27.77 },
{ role: "Imitator", influence: 48.88 }
],
"No Reserve": [
{ role: "Car Thief", influence: 31.37 },
{ role: "Techie", influence: 36.87 },
{ role: "Engineer", influence: 31.76 }
],
"Counter Offer": [
{ role: "Robber", influence: 30.65 },
{ role: "Looter", influence: 3.54 },
{ role: "Hacker", influence: 23.49 },
{ role: "Picklock", influence: 16.79 },
{ role: "Engineer", influence: 25.54 }
],
"Honey Trap": [
{ role: "Enforcer", influence: 21.1 },
{ role: "Muscle #1", influence: 35.42 },
{ role: "Muscle #2", influence: 43.48 }
],
"Bidding War": [
{ role: "Robber #1", influence: 6.25 },
{ role: "Driver", influence: 21.38 },
{ role: "Robber #2", influence: 19.73 },
{ role: "Robber #3", influence: 26.89 },
{ role: "Bomber #1", influence: 10.39 },
{ role: "Bomber #2", influence: 15.37 }
],
"Blast from the Past": [
{ role: "Picklock #1", influence: 8.64 },
{ role: "Hacker", influence: 5.23 },
{ role: "Engineer", influence: 25.97 },
{ role: "Bomber", influence: 21.01 },
{ role: "Muscle", influence: 37.83 },
{ role: "Picklock #2", influence: 1.32 }
],
"Break the Bank": [
{ role: "Robber", influence: 21.91 },
{ role: "Muscle #1", influence: 19.46 },
{ role: "Muscle #2", influence: 5.72 },
{ role: "Thief #1", influence: 5.99 },
{ role: "Muscle #3", influence: 24.37 },
{ role: "Thief #2", influence: 22.55 }
],
"Stacking the Deck": [
{ role: "Cat Burglar", influence: 33.39 },
{ role: "Driver", influence: 3.24 },
{ role: "Hacker", influence: 25.49 },
{ role: "Imitator", influence: 37.89 }
],
"Ace in the Hole": [
{ role: "Imitator", influence: 13.15 },
{ role: "Muscle #1", influence: 18.59 },
{ role: "Muscle #2", influence: 18.59 },
{ role: "Hacker", influence: 38.87 },
{ role: "Driver", influence: 10.79 }
]
};
let crimeData = {};
let previousTab = "none";
function classifyOcRoleInfluence(ocName, roleName, successChance) {
const roleData = ocRoleInfluence[ocName]?.find(r => r.role === roleName);
const influence = roleData ? roleData.influence : 0;
let thresholds;
if (influence >= 30) thresholds = influenceThresholds.high;
else if (influence >= 10) thresholds = influenceThresholds.medium;
else thresholds = influenceThresholds.low;
if (successChance >= thresholds.good) return { evaluation: 'good', influence };
if (successChance >= thresholds.ok) return { evaluation: 'ok', influence };
return { evaluation: 'bad', influence };
}
function processCrime(wrapper) {
const ocId = wrapper.getAttribute('data-oc-id');
if (!ocId || crimeData[ocId]) return;
const titleEl = wrapper.querySelector('p.panelTitle___aoGuV');
if (!titleEl) return;
const crimeTitle = titleEl.textContent.trim();
const roles = [];
const roleEls = wrapper.querySelectorAll('.title___UqFNy');
roleEls.forEach(roleEl => {
const roleName = roleEl.textContent.trim();
const successEl = roleEl.nextElementSibling;
const chance = successEl ? parseInt(successEl.textContent.trim(), 10) : null;
const evaluation = chance !== null ? classifyOcRoleInfluence(crimeTitle, roleName, chance) : { evaluation: 'unknown', influence: null };
roles.push({ role: roleName, chance, evaluation });
if (successEl && evaluation.influence !== null) {
successEl.textContent = `${chance}/${Math.round(evaluation.influence)}`;
}
const slotHeader = roleEl.closest('button.slotHeader___K2BS_');
if (slotHeader) {
switch (evaluation.evaluation) {
case 'good':
slotHeader.style.backgroundColor = '#239b56'; break;
case 'ok':
slotHeader.style.backgroundColor = '#ca6f1e'; break;
case 'bad':
slotHeader.style.backgroundColor = '#a93226'; break;
}
}
});
crimeData[ocId] = { id: ocId, title: crimeTitle, roles };
}
function setupMutationObserver(root) {
const observer = new MutationObserver(() => {
const tabTitle = document.querySelector('button.active___ImR61 span.tabName___DdwH3')?.textContent.trim();
if (tabTitle !== 'Recruiting' && tabTitle !== 'Planning') return;
if (previousTab !== tabTitle) {
crimeData = {};
previousTab = tabTitle;
}
const allCrimes = document.querySelectorAll('.wrapper___U2Ap7');
allCrimes.forEach(crimeNode => {
processCrime(crimeNode);
});
});
observer.observe(root, { childList: true, subtree: true });
}
waitForKeyElements("#faction-crimes-root", (root) => {
setupMutationObserver(root);
});
})();