';
buttonText = (allPage)?"":' class="button"';
newButtons += '
Show All';
buttonText = ("Analyze" == getPageAction())?"":' class="button"';
newButtons += '
Analyze Item Updates';
buttonText = ("Delete" == getPageAction())?"":' class="button"';
newButtons += '
Delete Unfound Items from Browser';
document.getElementsByTagName('body')[0].innerHTML = bodyHTML.replace(allRegEx, newButtons);
} // function addRarityButton()
// Workhorse function that figures out what's going on w/the data you've collected.
function AnalyzeResults() {
var results = GM_listValues().sort();
var myResults = "";
var filteredItems = new Array();
var filteredItemList = Array();
var filtersType = ",";
var filtersRarity = ",";
var pageRoot = 'city.php?SPSBDebrisTracker=Analyze&filter=';
var buttonText = ' class="button"';
var filter = new RegExp("filter=(.+)?\&sor").exec(window.location.href)[1];
if(undefined == filter) { filter = ''; }
filter = filter.replace(/%20/g, ' ');
var sortCriteria = new RegExp("sort=(.+)?\&sa").exec(window.location.href)[1];
if(undefined == sortCriteria) { sortCriteria = ''; }
sortCriteria = sortCriteria.replace(/%20/g, ' ');
var myAnalyzedData = "";
var totalSearches = 0;
var badSearches = 0;
var moneyFound = 0;
filteredItemList["AllItems"] = "";
filteredItemList["Rarity"] = new Array();
filteredItemList["Type"] = new Array();
var myIntroText = "";
// Save Filter & Sort Criteria
// ---------------------------------------------------------
if(window.location.href.match(/save=1/)) {
GM_setValue(getGame() + "-SortCriteria", "filter=" + filter + "&sort=" + sortCriteria + "&save=0");
} // if(window.location.href.match(/save=1/))
// Get base data
// ---------------------------------------------------------
var city;
var cityTest = new RegExp("city([0-9]+)");
if(cityTest.test(filter)) {
city = cityTest.exec(filter)[1];
} else {
city = 0;
} // which city if filtering by city
for(var x in results) {
if(game == getGame(results[x])) {
var result = GM_getValue(results[x]).split(",");
if(results[x].match(/-Item-/i)) {
var metadata = result[0].split("|");
if((0>filtersType.indexOf(","+metadata[0]+","))) {
filtersType += metadata[0] + ",";
filteredItemList['Type'][metadata[0]] = "";
}
if((0>filtersRarity.indexOf(","+metadata[1]+","))) {
filtersRarity += metadata[1] + ",";
filteredItemList['Rarity'][metadata[1]] = "";
}
if((0 == filter.length || filter == metadata[0] || filter == metadata[1])) {
filteredItems[results[x]] = result;
filteredItemList['AllItems'] += results[x]+",";
filteredItemList['Type'][metadata[0]] += results[x]+",";
filteredItemList['Rarity'][metadata[1]] += results[x]+",";
} // This item should be included in our matches (matches type or rarity filter or no filter)
if(0 < city) {
if(0 < result[city]) {
filteredItems[results[x]] = result;
filteredItemList['AllItems'] += results[x]+",";
filteredItemList['Type'][metadata[0]] += results[x]+",";
filteredItemList['Rarity'][metadata[1]] += results[x]+",";
} // This item found in city
} // This item should be included in our matches (found in city)
} // if(results[x].match(/-Item-/i))
//myResults += x + ": " + results[x] + " " + GM_getValue(results[x]) + "
";
} // this data belongs to this game
} // for(var x in results)
// Generate Filters
// ---------------------------------------------------------
var myFilterText = '
Show All Finds';
myFilterText += 'Settings Saved':buttonText + '>Save Settings') + '';
myFilterText += ' |
';
var cities = GM_getValue(game + "-LocationName", defaultStorageValue).split(",");
myFilterText += '' + (("spybattle"==getGame())?"City:":"Station:") + ' | ';
for(var x in cities) {
if("0" != cities[x]) {
myFilterText += '' + cities[x] + '';
} // search done in this city
} // for(var x in cities)
myFilterText += ' |
Type: | ';
filtersType = filtersType.substr(1, (filtersType.length-2)).split(",").sort();
for(var x in filtersType) {
if("0" == filtersType[x] || undefined == filtersType[x] || 0 == filtersType[x].length || "undefined" == filtersType[x]) {
noRarityFound = true;
} else {
myFilterText += '' + filtersType[x] + 's';
} // No Type Found
} // for(var x in filtersType)
myFilterText += ' |
Rarity: | ';
var noRarityFound = false;
filtersRarity = filtersRarity.substr(1, (filtersRarity.length-2)).split(",").sort();
for(var x in filtersRarity) {
if("0" == filtersRarity[x] || undefined == filtersRarity[x] || 0 == filtersRarity[x].length || "undefined" == filtersRarity[x]) {
noRarityFound = true;
} else {
myFilterText += '' + filtersRarity[x] + '';
} // No Rarity Found
} // for(var x in filtersRarity)
myFilterText += " |
";
if(noRarityFound) {
myFilterText += "
Not all items have an assigned rarity or type. Visit the Item Guide and press the Analyze Item Updates button. This will automatically detect the rarity and type of all items in the game.";
} // if(noRarityFound)
// Generate Sort Critera
// ---------------------------------------------------------
pageRoot += filter + "&sort=";
var mySortText = '
Item Name ';
//mySortText += '
City ';
mySortText += '
Type ';
mySortText += '
Rarity ';
// Analyze base data
// ---------------------------------------------------------
if(0 < city) {
totalSearches = GM_getValue(game + "-Searches", defaultStorageValue).split(",")[city];
badSearches = GM_getValue(game + "-BadSearches", defaultStorageValue).split(",")[city];
moneyFound = GM_getValue(game + "-Money", defaultStorageValue).split(",")[city];
} else {
totalSearches = sumArray(GM_getValue(game + "-Searches", defaultStorageValue).split(","));
badSearches = sumArray(GM_getValue(game + "-BadSearches", defaultStorageValue).split(","));
moneyFound = sumArray(GM_getValue(game + "-Money", defaultStorageValue).split(","));
} // city results only
var allSearches = 0;
myAnalyzedData += '
';
switch(sortCriteria) {
case "Type":
filtersRarity = filtersType;
filteredItemList['Rarity'] = filteredItemList['Type'];
// Why duplicate the code? Just pass through...
case "Rarity":
//alert(filteredItemList['Type']['Consumable'])
for(var x in filtersRarity) {
var myLocalAnalyzedData = "";
var localSearches = 0;
if("0" == filtersRarity[x] || undefined == filtersRarity[x] || 0 == filtersRarity[x].length || "undefined" == filtersRarity[x]) {
// Do Nothing
} else {
myLocalAnalyzedData += getAnalyzedHeader(filtersRarity[x] + 's');
//alert((filteredItems['spybattle-Item-Expresso']).indexOf(filtersRarity[x]) + "\n" + filteredItems['spybattle-Item-Expresso'] + "\n" + filtersRarity[x]);
for(var item in filteredItems) {
var result = filteredItems[item];
//alert("Item: " + item + "\nResult: " + result + "\nRarity: " + filtersRarity[x] + "\nMatch: " + result.indexOf(filtersRarity[x]));
if(-1
', localSearches, totalSearches, '1px solid white');
if(0 < localSearches) { myAnalyzedData += myLocalAnalyzedData; }
} // No Rarity Found
} // for(var x in filtersRarity)
break;
default:
myAnalyzedData += getAnalyzedHeader('');
for(var x in filteredItems) {
var numberFound = (0 < city)?filteredItems[x][city]:sumArray(filteredItems[x]);
myAnalyzedData += getAnalyzedData(x, numberFound, totalSearches, 'none');
allSearches += parseInt(numberFound);
} // for(var x in myAnalyzedData)
myAnalyzedData += getAnalyzedData('', allSearches, totalSearches, '1px solid white');
} // switch(sortCriteria)
myAnalyzedData += '
';
if(noRarityFound) {
myAnalyzedData += "
Not all items have an assigned rarity or type. Visit the Item Guide and press the Analyze Item Updates button. This will automatically detect the rarity and type of all items in the game.";
} // if(noRarityFound)
var findsType = ((0 < filter.length && !(filter.match(/city/)))?filter:"Item");
myIntroText += '
';
myIntroText += findsType + " finds for " + ((0 < city)?cities[city]:("all " + (("spybattle"==getGame())?"cities":"stations"))) + ": |
";
myIntroText += 'Total Search Lines: | | ' + CommaFormatted(totalSearches) + ' | | |
';
myIntroText += 'Money Found: | $' + CommaFormatted(moneyFound) + ' | $' + CommaFormatted((moneyFound/totalSearches).toFixed(2)) + '/search |
';
myIntroText += 'Nothing Found: | ' + CommaFormatted(badSearches) + ' | ' + CommaFormatted((badSearches/totalSearches*100).toFixed(2)) + '% |
';
myIntroText += '' + findsType + 's Found: | ' + CommaFormatted(allSearches) + ' | ' + CommaFormatted((totalSearches/allSearches).toFixed(2)) + ' searches/item |
';
if("Item" == findsType) {
myIntroText += 'Total Finds: | ' + CommaFormatted(totalSearches-badSearches) + ' | ' + CommaFormatted((totalSearches/(totalSearches-badSearches)).toFixed(2)) + ' searches/find |
';
} // 'All items, not just a segment
myIntroText += '
';
// Generate Output
// ---------------------------------------------------------
myResults += PopOverSection('Sort Criteria
', mySortText);
myResults += PopOverSection('Filter Criteria
', myFilterText);
myResults += PopOverSection("Analyze Results", myIntroText + myAnalyzedData); // myIntroText + "
" +
PopOverHTML(myResults);
} // function AnalyzeResults()
// Standard function for formatting output
function CommaFormatted(amount) {
var nStr = amount;
nStr += '';
var x = nStr.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}
// CommaFormatted()
// This generates the confirmation that you want to wipe out all your data.
function ConfirmDeleteResults() {
var results = GM_listValues();
var counter = 0; var countOther = 0;
for(var x in results) {
if(game == getGame(results[x])) {
if(results[x].match(/-Item-/i)) {
counter += 1;
} else {
countOther += 1;
} // if(noResults(results[x]))
} // this data belongs to this game
} // for(var x in GM_listValues())
PopOverHTML(PopOverSection("Confirm Deletion",
'Deleting everything you have tracked can not be undone.
You are currently tracking ' + counter + ' item(s) and ' + countOther + ' other pieces of data.
You must click this link to confirm you want ' + 'to delete your stored results.If you prefer not to delete everything you have tracked, just
click here to close this window.
'));
} // function ConfirmDeleteResults()
// This will wipe out all the data you've collected for this particular game.
function DeleteResults() {
var results = GM_listValues().sort();
var deletedKeys = '
'
for(var x in results) {
if(game == getGame(results[x])) {
deletedKeys += results[x] + " (" + GM_getValue(results[x]) + ")
";
GM_deleteValue(results[x]);
} // this data belongs to this game
} // for(var x in GM_listValues())
deletedKeys += "
";
PopOverHTML(PopOverSection('Tracking Results Deleted','
Your stored results have been deleted:' + deletedKeys + '
'));
} // function DeleteResults()
// This will remove any rarity/type definitions for items you haven't actually found yet.
function DeleteUnfoundItems() {
var results = GM_listValues().sort();
var noResults = new RegExp(defaultStorageValue.substr(2));
var counter = 0; var countAll = 0;
for(var x in results) {
if(game == getGame(results[x])) {
countAll += 1;
if(noResults.test(GM_getValue(results[x], defaultStorageValue))) {
counter += 1;
GM_deleteValue(results[x]);
} // if(noResults(results[x]))
} // this data belongs to this game
} // for(var x in GM_listValues())
alert('You have removed the data on ' + counter + ' item(s) from your browser of the ' + countAll + ' item(s) being tracked.');
} // function DeleteUnfoundItems()
// This will output the data line when analyzing data
// Move here to reduce updates if a changes needs to be made
function getAnalyzedData(text, found, totalSearches, border) {
var removeText = new RegExp(getGame() + '-Item-');
return '
' + text.replace(removeText, '') + ' | | ' +
'' + CommaFormatted(found) + ' | | ' +
'' + CommaFormatted((totalSearches/found).toFixed(2)) + ' | | ' +
'' + CommaFormatted((found/totalSearches*100).toFixed(2)) + '% |
';
} // function getAnalyzedData(item)
// This will output a header line when analyzing data
// Move here to reduce updates if a changes needs to be made
function getAnalyzedHeader(text) {
return '
' + text + ' | ' +
'Found | | ' +
'Searches Per Find | | ' +
'Chance Per Search |
---|
' ;
//((0 < text.length)?'
' + text + ' |
---|
':'');
} // function getAnalyzedHeader(text)
// This will figure out what city you are in while searching
function getCity(Piece) {
// Piece = 1 for City Number, 2 for City Name, 0 For the Full Array
if(0>Piece || 2
(.+)
2');
if(CID.test(bodyHTML)) {
return CID.exec(bodyHTML)[Piece];
} else {
return '0';
} // if(CID.test(bodyHTML))
} // getCity(Piece)
// This will check the URL so we can separate Spy Battle and Star Pirates data
function getGame(testPath) {
if(undefined == testPath) { testPath = window.location.href; }
var PID = new RegExp("(spybattle|starpirates)", 'i');
if(PID.test(testPath)) {
return PID.exec(testPath)[1];
} else {
return 0;
} // Can get game name
} // getGame()
// This will check the URL for a page specific action
function getPageAction() {
var PID = new RegExp("SPSBDebrisTracker.+(Confirm|Analyze|Delete)");
if(PID.test(window.location.href)) {
return PID.exec(window.location.href)[1];
} else {
return 0;
} // Can get game name
} // getPageName
// This will check the URL to find out what page we are on at the moment
function getPageName() {
var PID = new RegExp("(SPSBDebrisTracker|pickdebris|spendpoints|city|itemguide)");
if(PID.test(window.location.href)) {
return PID.exec(window.location.href)[1];
} else {
return 0;
} // Can get game name
} // getPageName
// This will get the search lines for tracking what you've found.
function getSearchLines() {
var SID;
if("spybattle" == getGame()) {
SID = new RegExp('Run Smoking Bolt Op | (.+)
.+
Security is too high');
} else {
SID = new RegExp(' | Pick Through Space Debris |
(.+)
.+
All the space debris circling the station has been looted');
} // spybattle or star pirates
if(SID.test(bodyHTML)) {
return SID.exec(bodyHTML)[1].split(" ");
} else {
return '';
} // if(SID.test(bodyHTML))
} // getSearchLines()
// This function puts a header area on the screen.
// Moved here to reduce updates if a change needs to be made.
function PopOverHTML(newHTML) {
var resultsDiv = document.createElement("div");
var backgroundImage = ((game=="starpirates")?"bg_opt_dither":"spybattle_background");
resultsDiv.setAttribute("style", "position:absolute; display:block; top:75px; left:125px; z-index:50; width:655px; height:400px; overflow-y:scroll; overflow-x:hidden; border:1px solid #FFCC00; background:black url('images/" + backgroundImage + ".jpg');");
resultsDiv.setAttribute("id", "SPSBDebrisTracker_results");
var results = '";
resultsDiv.innerHTML = results;
document.getElementsByTagName('body')[0].appendChild(resultsDiv);
} // function SetBodyHTML(newBodyHTML)
// This function puts a content area on the screen.
// Moved here to reduce updates if a change needs to be made.
function PopOverSection(sectionTitle, sectionContent) {
if(firstPopOver) {
sectionTitle += '{close}';
} // if(firstPopOver)
firstPopOver = false;
return(' |
' + sectionTitle +
' |
' + sectionContent +
' |
');
} // function PopOverSection(sectionTitle, sectionContent)
// This will check for search lines and decide what they hold.
function ProcessSearch() {
// Get Results
for(var i in SearchLines) {
if(rfoundNothing.test(SearchLines[i])) {
foundNothing += parseInt(1);
} else if(rfoundMoney.test(SearchLines[i])) {
foundMoney += parseInt(rfoundMoney.exec(SearchLines[i])[1]);
} else if(rfoundItem.test(SearchLines[i])) {
if(undefined==foundItems[rfoundItem.exec(SearchLines[i])[1]]) {
foundItems[rfoundItem.exec(SearchLines[i])[1]] = 1;
} else {
foundItems[rfoundItem.exec(SearchLines[i])[1]] += parseInt(1);
} // if(undefined==this item key)
} // Determine what was found
} // for(var i in SearchLines) // Iterate through the search lines
// Process Results
if(0 < SearchLines.length) {
// Store Searches
var totalSearches = GM_getValue(game + "-Searches", defaultStorageValue).split(",");
totalSearches[city] = parseInt(totalSearches[city]) + parseInt(SearchLines.length);
GM_setValue(game + "-Searches", totalSearches.join(","));
// Store Bad Searches (Nothing Found)
var badSearches = GM_getValue(game + "-BadSearches", defaultStorageValue).split(",");
badSearches[city] = parseInt(badSearches[city]) + parseInt(foundNothing);
GM_setValue(game + "-BadSearches", badSearches.join(","));
// Store Money Found
var searchMoney = GM_getValue(game + "-Money", defaultStorageValue).split(",");
searchMoney[city] = parseInt(searchMoney[city]) + parseInt(foundMoney);
GM_setValue(game + "-Money", searchMoney.join(","));
// Store City Name
var locationNames = GM_getValue(game + "-LocationName", defaultStorageValue).split(",");
locationNames[city] = getCity(2);
GM_setValue(game + "-LocationName", locationNames.join(","));
// Store Items Found
for(var x in foundItems) {
var itemKey = game + "-Item-" + x;
var itemCounts = GM_getValue(itemKey, defaultStorageValue).split(",");
itemCounts[city] = parseInt(itemCounts[city]) + parseInt(foundItems[x])
GM_setValue(itemKey, itemCounts.join(","));
} // for(var x in foundItems)
} // if(foundSearchLines)
} // function ProcessSearch()
// This will track the rarity and item type of every item in the game
function SaveRarity() {
var itemRow = new RegExp('(.+[^=<>])');
var itemClass = new RegExp('
(Consumable|Helmet|Primary Hand|Secondary Hand|Armor)
', "im");
var itemRarity = new RegExp('Rarity | (.+[^=<>])<', "m");
var rows = document.getElementsByTagName('tr');
var lastItem = '';
var lastClass = '';
var counter = 0;
for(var i in rows) {
if(itemRow.test(rows[i].innerHTML)) {
lastItem = itemRow.exec(rows[i].innerHTML)[1];
if(itemClass.test(rows[i].innerHTML)) {
lastClass = itemClass.exec(rows[i].innerHTML)[1];
lastClass = ("CONSUMABLE" == lastClass)?"Consumable":lastClass;
} else if(lastItem.match(/(AWE|NOM)/)) {
lastClass = "Part";
} else if("starpirates" == getGame()) {
lastClass = "Ship Component";
} // determine item class
} // if(itemRow.test(rows[i].innerHTML))
if(itemRarity.test(rows[i].innerHTML)) {
counter += 1;
var itemKey = game + "-Item-" + lastItem;
var itemCounts = GM_getValue(itemKey, defaultStorageValue).split(",");
itemCounts[0] = lastClass + "|" + itemRarity.exec(rows[i].innerHTML)[1];
GM_setValue(itemKey, itemCounts.join(","));
lastItem = '';
lastClass = '';
} // if(itemRarity.test(rows[i].innerHTML))
} // for(var i in rows)
alert('You have analyzed ' + counter + ' items.');
} // function SaveRarity()
// This will add up all the numbers it finds in an array and ignore any text.
function sumArray(list) {
var result = 0;
for(var x in list) {
if(isNaN(list[x])) {
// Do Nothing
} else {
result += parseInt(list[x]);
} // if(isNaN(list[x]))
} // for(var x in list)
return result;
} // function sumCommaDelimitedList(list)
|