NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name crime stats
// @namespace torn.com
// @version 1.9.1
// @description try to take over the world!
// @author You
// @match *www.torn.com/forums.php*
// @match *www.torn.com/preferences.php*
// @updateURL https://openuserjs.org/meta/Ahab/crime_stats.meta.js
// @downloadURL https://openuserjs.org/install/Ahab/crime_stats.user.js
// @license MIT
// ==/UserScript==
document.head.innerHTML += '<style>#getCrimes:hover, #updateapiKey:hover { background: var(--breadcrumbs-dark-active-bg-gradient); !important; } .center-screen {position: sticky;width:50%;background-color:#8DA5C6;z-index: 999;top: 0px;}</style>';
var pos = 0
var crimes = {}
var threadId = 000000
function add(){
if(localStorage.crimeKey === undefined || localStorage.crimeKey.length == 0 || localStorage.crimeKey == 'null'){
$('div[id*="forums-page-wrap"]>div[class*="content-title"]').append('<button id="createKey" style="color: #ddd; font-size: larger; background-color: #444; cursor: pointer; border-radius: 10px; width: 170px; padding: 5px 0 5px 0; margin: 8px 0 0 0;">Create api key</button>')
$('button[id*="createKey"]').on('click', function(event) {
window.open('https://www.torn.com/preferences.php#tab=api?step=addNewKey&title=CrimePull&user=crimes,workstats&torn=crimes')
var keyGrabbed = setInterval(function(){
if(localStorage.crimeKey.length != 0){
clearInterval(keyGrabbed);
$('#createKey').replaceWith('<button id="getCrimes" style="color: #ddd; font-size: larger; background-color: #444; cursor: pointer; border-radius: 10px; width: 170px; padding: 5px 0 5px 0; margin: 8px 0 0 0;">Get crime successes</button>')
}
}, 500);
})
}else{
$('div[id*="forums-page-wrap"]>div[class*="content-title"]').append('<button id="getCrimes" style="color: #ddd; font-size: larger; background-color: #444; cursor: pointer; border-radius: 10px; width: 170px; padding: 5px 0 5px 0; margin: 8px 0 0 0;">Get crime successes</button>')
}
$('div[id*="forums-page-wrap"]>div[class*="content-title"]').append('<button id="updateapiKey" style="color: #ddd; font-size: larger; background-color: #444; cursor: pointer; border-radius: 10px; width: 170px; padding: 5px 0 5px 0; margin: 8px 0 0 5px;">Update API Key</button>')
$('button[id*="updateapiKey"]').on('click', function(event) {
localStorage.crimeKey = prompt('Add API KEY')
})
}
function crimeData(crimeList){
$.each($('div[class*="editor-content"]'), function(i , value){
$('div[class*="editor-content"]')[i].children[0].textContent = ""
})
$.each(crimeList, function(index , value){
$.ajax({
url: "https://api.torn.com/v2/user/"+crimeList[pos].id+"/crimes",
type: "GET",
headers: {
'accept': 'application/json',
'Authorization': 'ApiKey '+localStorage.crimeKey,
},
async: false,
success: function(response){
$.each($('div[class*="editorContentWrapper"]>div[class*="editor-content"]'), function(i , value){
$('div[class*="editorContentWrapper"]>div[class*="editor-content"]')[i].children[0].innerText += crimeList[pos].name+': '+response.crimes.attempts.success+'\n'
})
crimes[crimeList[pos].name] = response
pos += 1
if(pos == crimeList.length){
$.ajax({
url: "https://api.torn.com/user/?selections=workstats&key="+localStorage.crimeKey,
type: "GET",
success: function(response){
$.each($('div[class*="editorContentWrapper"]>div[class*="editor-content"]'), function(i , value){
$('div[class*="editorContentWrapper"]>div[class*="editor-content"]')[i].children[0].innerText += '\n'
$('div[class*="editorContentWrapper"]>div[class*="editor-content"]')[i].children[0].innerText += 'Manual Labor: '+response.manual_labor+'\n'+'Intelligence: '+response.intelligence+'\n'+'Endurance: '+response.endurance+'\n'
})
alert("Crime stats loaded")
}
})
}
}
})
})
}
$(document).on('click', '#getCrimes', function(event){
pos = 0
$(document).scrollTop($(document).height());
$.ajax({
url: "https://api.torn.com/v2/torn/crimes",
type: "GET",
headers: {
'accept': 'application/json',
'Authorization': 'ApiKey '+localStorage.crimeKey,
},
success: function(response){
if('error' in response){
$.each($('div[class*="editor-content"]'), function(i , value){
$('div[class*="editor-content"]')[i].children[0].textContent = ""
})
$.each($('div[class*="editorContentWrapper"]>div[class*="editor-content"]'), function(i , value){
$('div[class*="editorContentWrapper"]>div[class*="editor-content"]')[i].children[0].innerText += response.error.error
})
}
else{
crimeData(response.crimes)
}
}
})
})
if($(window)[0].location.href.indexOf('api') > -1){
var newkeyExists = setInterval(function(){
if($('input[id*=key-popup]').length){
clearInterval(newkeyExists);
localStorage.crimeKey = $('input[id*=key-popup]')[0].value
alert('New key saved, can close this page')
}
}, 100);
}
var elementExists = setInterval(function(){
if($('#editor-wrapper').length && $('button[id*="updateapiKey"]').length == 0 && window.location.href.indexOf(threadId) > -1){
clearInterval(elementExists);
add()
}
}, 10);
var blehTarget = $('body')[0];
var blehConfig = { attributes: false, childList: true, characterData: false, subtree: true };
var bleh = new MutationObserver(function(mutations) {
$.each(mutations, function(i , value){
if(this.addedNodes.length > 7 && this.addedNodes[7].className.indexOf('new-post') > -1 && $('button[id*="updateapiKey"]').length == 0 && window.location.href.indexOf(threadId) > -1){
add()
}
})
})
bleh.observe(blehTarget, blehConfig);