There are 15 previous versions of this script.
Add Syntax Highlighting (this will take a few seconds, probably freezing your browser while it works)
// Copyright (c) 2009 Foppe Hemminga
// Licence: GNU General Public Licence (GPL)
// Feel free to copy, distribute, sell, modify and enjoy this script
// as long as you obey either the GPL 2 or GPL 3 licence.
//
// This script is for Torn (http://www.torn.com). It will keep track of
// your different crimes and your successrate.
// Usage: simply do your crimes. Stats (total number, green/brown/red)
// will be shown on the result page.
// ==UserScript==
// @name TornMagic
// @version 20100816.1
// @namespace http://www.hemminga.net
// @description Keeps track of your crimes in the RPG Torn
// @author Foppe Hemminga 'Afwas' #1337627
// @include http://torncity.com/*
// @include http://www.torncity.com/*
// @include http://torn.com/*
// @include http://www.torn.com/*
// @require http://code.jquery.com/jquery-1.3.2.js
// @require http://hemminga.net/greasemonkey/jquery.corner.js
// ==/UserScript==
const DEBUG = false;
// Usage: console.info("Hello world");
console = {
log :
function (text) {
if ( DEBUG ) unsafeWindow.console.log( text );
},
info :
function (text) {
if ( DEBUG ) unsafeWindow.console.info( text );
},
warn :
function (text) {
if ( DEBUG ) unsafeWindow.console.warn( text );
},
error :
function (text) {
if ( DEBUG ) unsafeWindow.console.error( text );
}
}
var TM_color = {
green: '#c1dec1',
blue: '#c1cfde',
red: '#dec1de',
brown: '#decfc1'
}
function TM_crimesTotal (crime){
// TODO still not happy, the code calls GM_getValue
// too often. Return an array with values?
// TODO: solution: put it all in TM_settings
// This function returns the sum of committed crimes
var crimeG = crime+'_g';
var crimeB = crime+'_b';
var crimeR = crime+'_r';
// This holds crime total, but we're going to calculate
// this dynamically instead of storing it
GM_deleteValue(crime);
// Get the totals
crimeG = GM_getValue(crimeG, 0);
crimeB = GM_getValue(crimeB, 0);
crimeR = GM_getValue(crimeR, 0);
crimeTotal = crimeG + crimeB + crimeR;
return crimeTotal;
}
function TM_crimeSettings (color, result, crime) {
// This code is able to change setting for the number of
// crimes from the settings menu
// This function replaces three identical snippets
// lateron.
var TM_Id = "#TM_"+color+"s";
var TM_shortId = '';
switch(color){
case 'green':
TM_shortId = '#TM_g';
break;
case 'brown':
TM_shortId = '#TM_b';
break;
case 'red':
TM_shortId = '#TM_r';
break;
}
GM_log('TM_Id: '+TM_Id);
GM_log('TM_shortId: '+TM_shortId);
GM_log('TM_thisResult: '+result);
// User enters a number in the g/b/r field
// Either an integer or +int or -int
$(TM_Id).change(function() {
var newNumber = $(this).val();
var TM_sign = newNumber.substr(0, 1);
// The first character is a ??
switch (TM_sign) {
case "+":
case "-":
// User entered +5 or -5
newnumber = newNumber.substr(1, newNumber.length);
try {
// This try / catch block is for the parseInt to
// make sure we're dealing with an integer
if (TM_sign=="+") {
newNumber = GM_getValue(result, 0)
+ parseInt(newNumber);
} else {
//User entered -5
newNumber = GM_getValue(result, 0)
- parseInt(newNumber);
}
} catch (err) {
GM_log("Value in newNumber ($(\""+TM_Id+"\").val()) "
+"not a number. "+err);
console.error("Value in newBrowns ($(\""+TM_Id+"\")"
+".val()) not a number. ", err);
break;
}
// Crime cannot be negative
if (newNumber<0) {
newNumber=0
};
// Changes the setting
GM_setValue(result, newNumber);
GM_log('Stored? GM_getValue(result, 0): '+GM_getValue(result, 0));
// For displaying purposes. I have no idea why
if (newNumber==0) {
newNumber="0"
}
// Visually updates the number of browns
// in the result table
$(TM_shortId).html(newNumber);
break;
default:
// User entered 5
try {
newNumber = parseInt(newNumber);
} catch (err) {
GM_log("Value in newNumber ($(\""+TM_Id+"\").val()) "
+"not a number. "+err);
console.error("Value in newNumber ($(\""+TM_Id+"\")"
+".val()) not a number. ", err);
break;
}
// Crime cannot be negative
if (newNumber<0) {
newNumber=0
};
// Save the new value
GM_setValue(result, newNumber);
// For displaying purposes. I have no idea why
if (newNumber==0) {
newNumber="0"
}
// Directly change the new value in the table
$(TM_shortId).html(newNumber);
}
// Finally normalise the number of totals
var TM_newTotal = TM_crimesTotal(crime);
// Directly change the new value in the table
$("#TM_t").html(TM_newTotal);
} );
}
// TM_settings[0] holds the number of images to be saved
// and later shown in crime history
// TODO Does it make sense to be able to change this on a per crime base?
var TM_settings = [GM_getValue('TM_history', -1)];
// First time around need to create the setting and fill it with default 20
if (TM_settings[0] == -1) {
GM_setValue('TM_history', 20);
TM_settings[0] = GM_getValue('TM_history');
}
// Setting for showing the resultsbar. Who would not want that?
TM_settings[1] = GM_getValue('TM_resultsBar', -1);
if (TM_settings[1] == -1) {
GM_setValue("TM_resultsBar", " checked=\"checked\"");
TM_settings[1] = GM_getValue("TM_resultsBar");
}
// Sets the backgroundcolor. Options available
// from enum above (blue / green / brown / red)
// Default blue, changes color after crime.
TM_settings[3] = TM_color.blue;
// TM_settings[2] sets a target for an individual crime.
// Default is 'not set' or zero
// See for the code lateron when the variable crime is set.
// These are the keywords as used in $_GET (from the <form>)
var TM_keywords = ['searchtrainstation', 'searchbridge', 'searchbins',
'searchfountain', 'searchdumpster', 'searchmovie', 'cdrock',
'cdheavymetal', 'cdpop', 'cdrap', 'cdreggae', 'dvdhorror',
'dvdaction', 'dvdromance', 'dvdsci', 'dvdthriller',
'chocolatebars', 'bonbons', 'extrastrongmints', 'tanktop',
'trainers', 'jacket', 'watch', 'necklace', 'ring', 'hobo',
'kid', 'oldwoman', 'businessman', 'lawyer', 'tim',
'apartment', 'house', 'mansion', 'cartheft', 'office',
'swiftrobbery', 'thoroughrobbery', 'swiftconvenient',
'thoroughconvenient', 'swiftbank', 'thoroughbank',
'swiftcar', 'thoroughcar', 'cannabis', 'amphetamines',
'cocaine', 'drugspills', 'drugscanabis', 'drugscocaine',
'simplevirus', 'polymorphicvirus', 'tunnelingvirus',
'armoredvirus', 'stealthvirus', 'assasination', 'driveby',
'carbomb', 'murdermobboss', 'home', 'Carlot',
'OfficeBuilding', 'aptbuilding', 'warehouse', 'motel',
'govbuilding', 'parkedcar', 'movingcar', 'carshop',
'pawnshop', 'pawnshopcash', 'makemoney2', 'maketokens2',
'makecard', 'napkid', 'napwomen', 'napcop', 'napmayor',
'trafficbomb', 'trafficarms', 'bombfactory', 'bombbuilding',
'hackbank', 'hackfbi'];
// console.info('length TM_keywords = '+TM_keywords.length);
// This is a nicer readable translation for the various
// crimes as used in output
var TM_description = ['searched the trainstation', 'searched the bridge',
'searched the bins', 'searched the fountain',
'searched the dumpster', 'searched the movie theatre',
'stole a rock cd', 'stole a heavy metal cd',
'stole a pop cd', 'stole a rap cd', 'stole a reggae cd',
'stole a horror dvd', 'stole an action dvd',
'stole a romance dvd', 'stole a sci dvd',
'stole a thriller dvd', 'stole chocolate bars',
'stole bonbons', 'stole extra strong mints',
'stole a tanktop', 'stole trainers', 'stole a jacket',
'stole a watch', 'stole a necklace', 'stole a ring',
'picked a hobo\'s money', 'picked a kid\'s cash',
'picked an old woman\'s purse',
'picked a businessman\'s wallet',
'picked a lawyer\'s pocket', 'picked Tim\'s profits',
'broke into an appartment', 'broke into the house',
'broke into a mansion', 'broke into a car',
'broke into the office', 'swiftly robbed the sweetshop',
'thoroughly robbed the sweetshop',
'swiftly robbed the convenient store',
'thoroughly robbed the convenient store',
'swiftly robbed the bank', 'thoroughly robbed the bank',
'swiftly robbed a car', 'thoroughly robbed a car',
'transported cannabis', 'transported amphetamines',
'transported cocaine', 'sold pills', 'sold cannabis',
'sold cocaine', 'spreaded the simple virus',
'spreaded the polymorphic virus',
'spreaded the tunneling virus',
'spreaded the armored virus',
'spreaded the stealth virus',
'assasinated a target', 'did a drive by shooting',
'planted a car bomb', 'mobbed the boss',
'burned down the home', 'burned down a car lot',
'burned down an office building',
'burned down an appartment building',
'burned down a warehouse', 'burned down the motel',
'burned down the government building',
'stole a parked car', 'hijacked a car',
'stole a car from the showroom',
'robbed the pawn shop through the side doar',
'robbed the pawn shop through the rear door',
'counterfeited money', 'counterfeited casino tokens',
'counterfeited credit cards', 'kidnapped a kid',
'kidnapped a woman', 'kidnapped an undercover cop',
'kidnapped the mayor', 'transported a bomb',
'transported arms', 'bombed the factory',
'bombed the gouvernement building', 'hacked the bank',
'hacked the FBI'];
// This is the filename for the image used for the various crimes
var TM_images = ["a1", "a2", "a3", "a4", "a5", "a6", "b1", "b3", "b3", "b4",
"b5", "b6", "b7", "b8", "b9", "b10", "c1a", "c1b", "c1c",
"c2a", "c2b", "c2c", "c3a", "c3b", "c3c", "d1", "d2", "d3",
"d4", "d5", "d6", "e1", "e3", "e3", "e4", "e5", "f1", "f3",
"f3", "f4", "f5", "f6", "f7", "f8", "g1", "g2", "g3", "g5",
"g4", "g6", "h", "h1", "h2", "h3", "h4", "i1", "i2", "i3",
"i4", "j1", "j3", "j3", "j4", "j5", "j6", "j7", "k1", "k2",
"k3", "l1", "l2", "m1", "m2", "m3", "n1", "n2", "n3", "n4",
"o1", "o2", "p1", "p2", "q1", "q2"];
// Three hardcoded images for the 'latest 20 results' action
var TM_greenURI = 'data:image/gif;base64,R0lGODlhCQAbAIABAABmAP%2F%2F%2FyH5BAEKAAEALAAAAAAJABsAAAIUhI%2Bpy%2B0PT5i02ouz3rz7D4aiVgAAOw%3D%3D';
var TM_brownURI = 'data:image/gif;base64,R0lGODlhCQAbAIABAGYzAP%2F%2F%2FyH5BAEKAAEALAAAAAAJABsAAAIUjI%2Bpy%2B0PD5i02ouz3rzTCIbiqBQAOw%3D%3D';
var TM_redURI = 'data:image/gif;base64,R0lGODlhCQAbAIABAP8AAP%2F%2F%2FyH5BAEKAAEALAAAAAAJABsAAAIUjI%2Bpy%2B0Po5y0NoCz3rz7D4ZiVgAAOw%3D%3D';
var TM_iconInfo = 'data:image/gif;base64,R0lGODlhIwAjAPfLAMTk%2F%2BTx%2F9To%2F9fu%2F%2Bf1%2F%2Ff%2F%2FwAZhPb5%2Fb3e%2FwAzme7u7sTg%2F%2BLl6fL2%2BavG3pyktvDx9M7U3kNjm7jEzrbO5JKwzrvG1eTr8ZO11972%2Fy9DanqcvbDV%2BPj497%2FEz73l%2F6nQ%2Bldlg9bk8pWtw%2B7%2F%2F%2Bbo7arH6LrZ9Km6yt3g54qtzc3r%2F5OdsHuayJm31N3p9Zazzb3U5uD%2F%2Fyg8ZIytxp%2FC5%2Bfu95692NPX3%2Bf%2F%2F53B8crh%2Bdvg67O9zAAajaO%2F1xswWoWmxwAqlx4xWtPl%2BfXz8LPU9sfa8czQ2QAAO2ySuYyy07W7x1FtlafQ%2F9zr%2BQAvo6qvvWt4ldze3gwhT4iSp6StvytfzBAnVAAIYnmHoiA7acfg%2BXJ9lqW4zBpOvYWdx8LS35%2FG7hosV6uywXWWyObl4pywwiE4Y2SHrKXP%2BRxDjWBui2ZyjnGh1RgqUsvd73GQs4WivztKbMPI00lWd3uHnzFPhd%2Fl7k1sonKq3yI%2FbWCKtBMzbbjb%2Btb3%2F3aCmwIdV7bY8StJhMnR3wcZRWWRvgAKbTxjlYioxV9%2Bo3SXyhpJqnyfz3mYyLHE1QAYfoOZtYClzmmNwWOHyXqVwFGF4wAAZqGwxQo%2BplZ%2FrJS%2B5sPN126h1nOawAALfICo2pvN8qXF5QsdShk1Y15tjB9HkzFKdLjD4IqUqj9ijj1SeJG64IOpy9bb6Obm5j5dh3yo14qv1FZ8p7jc%2F06G3wART6PE64icvWmBpwAASAIwjz1OcihLe1yKubTP6wQsgQAnmrzK20VafrHY%2FzVQfpqt1%2B%2F4%2F97v%2F83m%2F%2F%2F%2F%2F%2F%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAMsALAAAAAAjACMAAAj%2FAJcJHEiwoMGDCBMue8FAgcOHFy64YqBQYYQIRTIq28ixQwdlB3qUqFjQBgOPHzlOiNKA44EDyo71ICmQxysFLTkqW5UkSSCYHI%2B1FBahIg8zJXJyJKTLgI9LcXSCtHEAzoSER5O6hHkhS4JaUIzFPHZs47EXxxx4OHhhCgMIG1%2FKVQaGkSVKBQocI8C3gDICaCMVLRhhygWzZBP7Vea3AN%2FHBPw%2BeXJEy8iBNnCkIDA28bG8oAOIHo2stGMRAaSQIRgGBx6ykAkcy7Vl0J0%2BtnAVCFC6NzISRIg4kEJR4AQkaI%2BNFn0MDLBPPnwcqlSg94DrAwgQORKD11rjnEQQ%2F1g%2BOq8pIVAMtCBReoCA9wIG7IgRY8iDgRMsiPftu0AeAwmoR4J78MG3AwX1sYCffrxZhx0JEgCoXg4CJGPhhclwQQEFQCgoEAoWwNEedtjlEGGAjuSwAoYXnkCBAx0O9EMPYcRXIHwZnGhAGTJcCMCPP%2F7iAAYxCmQBCo8ccR2LyeQoYRkZWLjAlFOe4IADTYxxn0AM%2FIACKjtUyKKTAS6SAZBAImDCDxhsMcd3AsGAghcULLDCCkCuIEOEQkAyiQw%2FIiComjfcMMsoXRQnEARynEEnF2gCcMIaQmSSwBqCADComi7A4AkWGqxWkAWJnAGDAydM%2BUcjWQTzxRVXfOaxCygA0MJBDRjA0MIeY9iBECYbjDDCDSYYgQAHOhADwrIfOOEEB7e4UEEFSoRARRsKWZEGDcK64IIoRhjhxwfk3orBtK1ogsUbbJDERBtpyEEDDUEEocISNXCgxrkqBMGHtTMAQtMyOFTRBCyKbKDwBiqIIYYsSqjSSyFDhPBACgMvAwEdVZQyzAynxKGCDjpIQsobc7DxQAQNZDwQBDAjUUcxS2wCQixodOFBCi27fFAKGhjCihpuaBCFzxV5oIEvoXQygxVIV4RECG7ogcaWUSekgBaIaIB11gkxkQodYJdtts8BAQA7';
jQuery(document).ready(function() {
// crime is the name of the crime as sent
// through GET to server (from the submit form)
try{
var crime = $(":input[name=crime]").not("input:radio").val();
}
catch(err){
// Error console: this is not an error!
}
// Variable names for storing success into GM / FF
var crimeSuccess = crime+"_g"; // generates 'chocolatebars_g', g for green.
var crimeUndecided = crime+"_b";
var crimeFailure = crime+"_r";
var crimeArray = crime+"_a"; // Array stores latest 20 results
// TM_settings[2] stores a target for an individual crime
var crimeTarget = crime+"_t";
// Target for individual crimes. This defaults to 'not set' or zero
TM_settings[2] = GM_getValue(crimeTarget, 0);
// Retrieve the crimeArray from FF settings
// What's actually stored there is a string
var thisCrimeArray = GM_getValue(crimeArray, -1);
// Make an array out of the stored string
if (thisCrimeArray != -1) { // There is a crimeArray stored for this crime
thisCrimeArray = thisCrimeArray.split(',');
} else { // There is no crimeArray stored for this crime
thisCrimeArray = [];
}
// crimeText is basically says 'no crime committed', reading:
// "You will have to wait for your nerve bar to refill
// before you try doing more crimes!"
var crimeText = $("div[align=left] center table tr td center").text();
if (crime && !crimeText) {
// There is a known type of crime (crime)
// and there is no failure (empty nerve bar) (=> crimeText)
// Using the function to determine the number of committed crimes
var numberOfCrimes = TM_crimesTotal(crime);
// A crime is about to be committed ...
numberOfCrimes = numberOfCrimes + 1;
// Remove first item (oldest) if the array has a length
// greater than or equal to TM_settings[0] (default 20)
// Repeat until the array has a length one smaller than
// it says to be in TM_setting[]
// This is both taking care of the array if the setting
// changed and got smaller than the existing array
// and just before a new crime is committed because that
// action will add one item to the array
while (thisCrimeArray.length >= TM_settings[0]) {
thisCrimeArray.shift()
}
// The font in the resultpage will turn green, brown or red
// depending on the outcome. We use that.
hasGreen = $("div[align=left] center table tbody tr td")
.find("font[color=#006600]").attr("color");
hasBrown = $("div[align=left] center table tbody tr td")
.find("font[color=#663300]").attr("color");
hasRed = $("div[align=left] center table tbody tr td")
.find("font[color=#ff0000]").attr("color");
if (hasGreen == '#006600') {
// Number of successes or green
var numberOfCrimesGreen = GM_getValue(crimeSuccess, 0);
numberOfCrimesGreen = numberOfCrimesGreen + 1;
GM_setValue(crimeSuccess, numberOfCrimesGreen);
// Add the result to the crimeArray
thisCrimeArray.push('1');
// Set background to green
TM_settings[3] = TM_color.green;
}
if (hasBrown == '#663300') {
// Brown / undecided
var numberOfCrimesBrown = GM_getValue(crimeUndecided, 0);
numberOfCrimesBrown = numberOfCrimesBrown + 1;
GM_setValue(crimeUndecided, numberOfCrimesBrown);
// Add the result to the crimeArray
thisCrimeArray.push('2');
// Set background to brown
TM_settings[3] = TM_color.brown;
}
if (hasRed == '#ff0000') {
// Red / failure
var numberOfCrimesRed = GM_getValue(crimeFailure, 0);
numberOfCrimesRed = numberOfCrimesRed + 1;
GM_setValue(crimeFailure, numberOfCrimesRed);
// Add the result to the crimeArray
thisCrimeArray.push('3');
// Set background to red
TM_settings[3] = TM_color.red;
}
// Store the changed crimeArray
thisCrimeArray = thisCrimeArray.join(",");
GM_setValue(crimeArray, thisCrimeArray);
}
if (crime) {
// This is for output purposes only.
// This is triggered at the crime result page regardless of the outcome
// of the actual crime, so also when no crime has been committed.
var numberOfCrimes = TM_crimesTotal(crime);
var numberOfCrimesGreen = GM_getValue(crimeSuccess, 0);
var numberOfCrimesBrown = GM_getValue(crimeUndecided, 0);
var numberOfCrimesRed = GM_getValue(crimeFailure, 0);
// Calculate percentages
if (numberOfCrimes!=0) {
var percentageGreen = numberOfCrimesGreen / numberOfCrimes * 100;
percentageGreen = percentageGreen.toFixed(2);
var percentageBrown = numberOfCrimesBrown / numberOfCrimes * 100;
percentageBrown = percentageBrown.toFixed(2);
var percentageRed = numberOfCrimesRed / numberOfCrimes * 100;
percentageRed = percentageRed.toFixed(2);
} else {
// You don't want to divide by zero (although jS doesn't mind)
var percentageGreen = "~ ";
var percentageBrown = "~ ";
var percentageRed = "~ ";
}
// Generate text from the three arrays at the start of this script
var TM_index = TM_keywords.indexOf(crime);
if (crime!=-1) {
// The crime exists in the array
var TM_crime = TM_description[TM_index];
var TM_image = "<td rowspan=\"4\"><img src=\"/images/crimes/"
+TM_images[TM_index]+".png\" alt=\""
+TM_description[TM_index]+"\" /></td>";
} else {
var TM_crime = crime
var TM_image = "";
}
// Create the HTML for latest 20 result row
if (TM_settings[1]==" checked=\"checked\"") {
// Get the result string from FF settings
var TM_latestResultsArray = GM_getValue(crimeArray, '');
// Transform the string into an array to work with
TM_latestResultsArray = TM_latestResultsArray.split(',');
// The array will look like ["1","1","2","1","1","3"]
// this generates the HTML for the result bar
var TM_latestResults = "\n\t\t</tbody>\n\t</table>\n\t<table>"
+"\n\t\t<tbody>\n\t\t\t<tr>\n\t\t\t\t<td>"
+"Latest "+TM_latestResultsArray.length
+" results<span id=\"TM_newSetting\">"
+"</span>: </td>";
for (i in TM_latestResultsArray) {
// Convert "1", "2" and "3" to HTML images using the
// hard coded images at the top of this script
switch (TM_latestResultsArray[i]) {
case "1":
TM_latestResultsArray[i] = "<img src=\""+TM_greenURI
+"\" alt=\"green\" />";
break;
case "2":
TM_latestResultsArray[i] = "<img src=\""+TM_brownURI
+"\" alt=\"brown\" />";
break;
case "3":
TM_latestResultsArray[i] = "<img src=\""+TM_redURI
+"\" alt=\"red\" />";
break;
}
// Wrap <td> tags around the HTML images
TM_latestResults += "\n\t\t\t\t<td>\n\t\t\t\t\t"
+TM_latestResultsArray[i]+"\n\t\t\t\t</td>";
}
} else {
var TM_latestResults="";
}
// Close the table
TM_latestResults += "\n\t\t\t</tr>\n\t\t</tbody>\n\t</table>";
// Create the HTML for the Crime Target line
if (TM_settings[2]) {
var TM_targetToGo=TM_settings[2]-numberOfCrimesGreen;
var TM_targetHTML="\n\t<p>You set a target of "+TM_settings[2]
+"<span id=\"TM_targetSpan\"></span>. You want to"
+" repeat this crime at least "+TM_targetToGo
+" times.</p>";
} else {
var TM_targetHTML="";
}
// Output number of attempts and successes plus success percentage
$("hr:eq(1)").before("\n\n<div id=\"TM_total\">\n\t"+
"<table class=\"TM_table\">\n\t\t<tbody>\n\t\t\t"
+"<tr>\n\t\t\t\t"+TM_image+"\n\t\t\t\t"
+"<td>You "+TM_crime+" at least <span id=\"TM_t\">"
+numberOfCrimes+"</span> times.</td>\n\t\t\t\t"
+"<td rowspan=\"4\" width=\"35px\">"
+"<img src=\""+TM_iconInfo+"\" alt=\"info\""
+"id=\"TM_info\" /></td>\n\t\t\t</tr>\n\t\t\t<tr>"
+"<td>Number of success: <font color=\"#006600\">"
+"<span id=\"TM_g\">"+numberOfCrimesGreen+"</span>"
+" ("+percentageGreen+"%)</font>.</td></tr>"
+"\n\t\t\t<tr><td>Number of undecided:"
+" <font color=\"#663300\"><span id=\"TM_b\">"
+numberOfCrimesBrown+"</span> ("+percentageBrown
+"%)</font>.</td></tr>\n\t\t\t<tr><td>"
+"Number of failure: <font color=\"#ff0000\">"
+"<span id=\"TM_r\">"+numberOfCrimesRed+"</span>"
+" ("+percentageRed+"%)</font>.</td></tr>"
// +"\n\t\t</tbody>\n\t</table>"
+TM_latestResults
+TM_targetHTML+"\n</div>\n\n");
// This adds the purple background (and some other styles to come)
GM_log('TM_settings[2] : '+TM_settings[3]);
$("#TM_total").corner().css( {
'width':'75%',
'background-color': TM_settings[3]
} );
// This is the action for the settings <div>
// it gets displayed after hovering the I image
// All events are taking place in here because it only happens if the
// <div> is shown
$("#TM_info").hover(function() {
// This snippet sets the form of the TM settings down at the crime
// result page, just HTML output
$("hr:eq(3)").after(
"\n\n<div class=\"TM_remove\">"
+"\n\t<table>\n\t\t<caption>Settings for Torn Magic</caption>"
+"\n\t\t<tbody>\n\t\t\t<tr><th colspan=\"3\">Settings for \""
+TM_crime+"\"</th></tr>"
+"\n\t\t\t<tr><td>Change number of Greens</td><td>"
+"<input id=\"TM_greens\" size=\"5\" type=\"text\" />"
+"</td><td>Set a value or use +/- to change a value.</td></tr>"
+"\n\t\t\t<tr><td>Change number of Browns</td><td>"
+"<input id=\"TM_browns\" size=\"5\" type=\"text\" /></td>"
+"<td>Set a value or use +/- to change a value.</td></tr>"
+"\n\t\t\t<tr><td>Change number of Reds</td><td>"
+"<input id=\"TM_reds\" size=\"5\" type=\"text\" /></td>"
+"<td>Set a value or use +/- to change a value.</td></tr>"
+"\n\t\t\t<tr><td>Set a target</td><td>"
+"<input id=\"TM_target\" size=\"5\" type=\"text\" /></td>"
+"<td>Leave blank or set to zero to disable.</td></tr>"
+"\n\t\t\t<tr><th colspan=\"3\">Global settings</th></tr>"
+"\n\t\t\t<tr><td>Show Latest results</td>"
+"<td><input id=\"TM_latest\" type=\"checkbox\""
+TM_settings[1]+" /></td><td></td></tr>"
+"\n\t\t\t<tr><td>Set number of latest results</td><td>"
+"<input id=\"TM_latestNo\" size=\"5\" type=\"text\" /></td>"
+"<td>Deletes older values if set lower than current.</td></tr>"
+"\n\t\t\t<tr><td colspan=\"3\">Some changes will take effect"
+" after a crime is committed</td></tr>\n\t\t"
+"</tbody>\n\t</table>\n</div>\n\n");
// this snippet applies some style
$(".TM_remove").corner().css( {
'width':'75%',
'background-color': TM_settings[3]
});
TM_crimeSettings('green', crimeSuccess, crime);
TM_crimeSettings('brown', crimeUndecided, crime);
TM_crimeSettings('red', crimeFailure, crime);
// Sets the setting for Crime target and TM_settings[2]
$("#TM_target").change(function() {
// the try / catch block is to catch non integer input
// (e.g. a character), which fails on parseInt
try {
var TM_target = parseInt($(this).val());
// User deliberately set target to zero
if (TM_target==0) {
GM_deleteValue(crimeTarget);
}
// Else User set a clear target
GM_setValue(crimeTarget, TM_target);
TM_settings[2]=GM_getValue(crimeTarget, 0);
// Visually update the new target
$("#TM_targetSpan").html(" ["+TM_settings[2]+"]");
// That's it here. The rest is at the point where the
// HTML for the stats table is generated
} catch (err) {
GM_log("Value in TM_settingts[2] ($(\"#TM_target\").val())"
+" not a number. "+err);
console.error("Value in TM_settings[2] ($(\"#TM_target\")"
+".val()) not a number. ", err);
}
} );
// Change the setting for displaying the results bar
$("#TM_latest").change(function() {
if (GM_getValue("TM_resultsBar")==" checked=\"checked\"") {
// Ugly
// The empty value means 'not set' and defaults to 'checked'
// so the unchecked needs a (phoney) value
GM_setValue("TM_resultsBar", " alt=\"unchecked\"");
} else {
GM_setValue("TM_resultsBar", " checked=\"checked\"");
}
TM_settings[1] = GM_getValue("TM_resultsBar");
} );
// Change the number of history dots in the results bar
$("#TM_latestNo").change(function() {
// the try / catch block is to catch non integer input
// (e.g. a character), which fails on parseInt
try {
var TM_latestResultsNew = parseInt($(this).val());
GM_setValue('TM_history', TM_latestResultsNew);
TM_settings[0] = GM_getValue('TM_history');
// Instant feedback to the user. The actual bar will
// only shrink after the next crime.
$("#TM_newSetting").html(" ["+TM_settings[0]+"]");
} catch (err) {
console.error("An error has occured while changing the"
+" number of history dots: ", err);
// With errors the javaScript console
// is as usefull as Firebug
GM_log("An error has occured while changing the number"
+" of history dots: "+err);
}
} );
},
// Prevent a second hover event to not show the <div> twice
// Actually this is the onmouseout event ;)
function() {
$(this).unbind()
} );
}
} );
// @name Script Update Checker
// @namespace http://www.crappytools.net
// @description Code to add to any Greasemonkey script to let it check for updates.
// @include *
// NOTES:
// Feel free to copy this into any script you write; that's what it's here for. A credit and/or URL back to here would be appreciated, though.
// I was careful to use as few variables as I could so it would be easy to paste right into an existing script. All the ones you need to set are at the very top.
// The target script needs to be uploaded to userscripts.org. The update checks will -not- increase the install count for the script there.
// This script is set up to check for updates to itself by default. It may be a good idea to leave it like this.
var SUC_script_num = 61783; // Change this to the number given to the script by userscripts.org (check the address bar)
try {
function updateCheck(forced) {
if ((forced) || (parseInt(GM_getValue('SUC_last_update', '0')) + 86400000 <= (new Date().getTime()))) { // Checks once a day (24 h * 60 m * 60 s * 1000 ms)
try {
GM_xmlhttpRequest( {
method: 'GET',
url: 'http://userscripts.org/scripts/source/'+SUC_script_num+'.meta.js?'+new Date().getTime(),
headers: {'Cache-Control': 'no-cache'
},
onload: function(resp) {
var local_version, remote_version, rt, script_name;
rt=resp.responseText;
GM_setValue('SUC_last_update', new Date().getTime()+'');
remote_version=parseInt(/@uso:version\s*(.*?)\s*$/m.exec(rt)[1]);
local_version=parseInt(GM_getValue('SUC_current_version', '-1'));
if (local_version!=-1) {
script_name = (/@name\s*(.*?)\s*$/m.exec(rt))[1];
GM_setValue('SUC_target_script_name', script_name);
if (remote_version > local_version) {
if (confirm('There is an update available for the Greasemonkey script "'+script_name+"\"."
+"\nLocal version is "+local_version+", while the version on the server is "+remote_version+"."
+"\nWould you like to go to the install page now?")) {
GM_openInTab('http://userscripts.org/scripts/show/'+SUC_script_num);
GM_setValue('SUC_current_version', remote_version);
}
} else if (forced)
alert('No update is available for "'+script_name+'."');
} else
GM_setValue('SUC_current_version', remote_version+'');
}
});
} catch (err) {
if (forced)
alert('An error occurred while checking for updates:\n'+err);
}
}
}
GM_registerMenuCommand(GM_getValue('SUC_target_script_name', '???') + ' - Manual Update Check', function() {
updateCheck(true);
});
updateCheck(false);
} catch (err) {}