Safe inventory tool
From NexusWiki
Contents |
[edit] M-Type's Safe Inventory Tool
From M-Type of The Shining Ones, posted with permission:
Insane ALPHA warning!
If it don't work; tough luck.
It may blow up your computer, and do other bad things.
This code is a BOOKMARKLET; Make a new bookmark, and insert this code into the location field. Not tested with IE.
This version only does counts, nothing else. I'd appreciate some suggestions on where to go from here, and any code comments/improvements would be nice too.
update: Dec 2, 2006:
Safe-O-Mat Version 0.2 Now with 100% more Alchemy!
This version can finnally do some alchemy analysis. Next version may do more like tell you how many LBA/MEA/Pistols you can make from available parts.(Frankly however Its a bitch to test as these parts don't last long anyways in the safe!)
This also has refinements from Swot and Chester Katz code bits.
[edit] INSTRUCTIONS:
1. Create new bookmark, add below code into 'location' area.
2. Open Nexuswar.com, login, USE OLD INTERFACE!!! and get to the stronghold, and open up that Stronghold actions menu pane/bar/thingy
3. Run my little tool, and choose what you want counted, and hit the LIST button. (please ignore the Crafting button as it does not DO anything ATM)
[edit] CODE:
javascript:SafeOmat=open('','Safe-O-Mat','width=400,height=600,resizable'); SafeOmat.focus(); with(SafeOmat.document){write('<html> <head> <title>Safe-O-Mat Alpha</title> <script language="javascript" type="text/javascript"> function List() { ClearOutputp(); var ItemClassGroup = document.myform.option.value; CompList = GetComponents(ItemClassGroup, true); for(var property in CompList) { var value = CompList[property]; document.getElementById("outputp").innerHTML += property + "," + value +"<BR>"; } } function GetComponents(ItemClassGroup, display_total){ var total_components = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options.length; if (display_total == true ) {alert("Total is "+ (total_components -1));} CompList = new Object(); for (var i = 1; i < total_components; i++) { var CompName = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options[i].text; if (isNaN(CompList[CompName])) { CompList[CompName] = 1; } else {CompList[CompName] = CompList[CompName] + 1;} } return (CompList); } function ClearOutputp() { document.getElementById("outputp").innerHTML = ""; } function Craftable(){ var tc = "takecomponent"; CompList = GetComponents(tc, false); matchRecipes(CompList); } function matchRecipes(components) { var listSpan; var recipes = getRecipes(); var potions = {}; var listHTML = ""; for (var potion in recipes) { var max = 999999; var recipe = ""; for (var ingredient in recipes[potion]) { var needed = recipes[potion][ingredient]; var onHand = components[ingredient]; if (onHand) { var maxIndiv = Math.floor(onHand / needed); if (recipe) { recipe += ", "; } recipe += ingredient; if (needed > 1) { recipe += " x" + needed; } if (maxIndiv < max) { max = maxIndiv; } } else { var max = 0; } } if (max) { listHTML += potion + " : " + max + " (" + recipe + ")" + "<br/>"; } } if (!listHTML) { listHTML = "No recipes available."; } document.getElementById("outputp").innerHTML = listHTML; } function getRecipes() { var recipes = {}; recipes["Combat Clarity"] = {}; recipes["Combat Clarity"]["chunk of steel"] = 3; recipes["Combat Clarity"]["gold ingot"] = 1; recipes["Extended Invisiblity"] = {}; recipes["Extended Invisiblity"]["chunk of ivory"] = 1; recipes["Extended Invisiblity"]["handful of grave dirt"] = 1; recipes["Extended Invisiblity"]["spool of copper wire"] = 1; recipes["Extended Invisiblity"]["vial of angel%5C%27s tears"] = 2; recipes["Fire Resistance"] = {}; recipes["Fire Resistance"]["bunch of lilies"] = 1; recipes["Fire Resistance"]["chunk of iron"] = 1; recipes["Fire Resistance"]["piece of stygian coal"] = 1; recipes["Fire Resistance"]["small bottle of gunpowder"] = 1; recipes["Flying"] = {}; recipes["Flying"]["bottle of paradise water"] = 1; recipes["Flying"]["gold ingot"] = 1; recipes["Flying"]["lead brick"] = 1; recipes["Flying"]["rose"] = 3; recipes["Flying"]["skull"] = 1; recipes["Healing"] = {}; recipes["Healing"]["handful of grave dirt"] = 2; recipes["Healing"]["patch of lichen"] = 1; recipes["Healing"]["rose"] = 1; recipes["Invisibility"] = {}; recipes["Invisibility"]["batch of mushrooms"] = 1; recipes["Invisibility"]["chunk of ivory"] = 3; recipes["Invisibility"]["sprig of nightshade"] = 1; recipes["Invulnerability"] = {}; recipes["Invulnerability"]["bottle of holy water"] = 1; recipes["Invulnerability"]["bunch of paradise lilies"] = 3; recipes["Invulnerability"]["chunk of stygian iron"] = 1; recipes["Magic Recovery"] = {}; recipes["Magic Recovery"]["bottle of paradise water"] = 1; recipes["Magic Recovery"]["patch of moss"] = 1; recipes["Magic Recovery"]["piece of stygian coal"] = 1; recipes["Magic Recovery"]["rose"] = 12; recipes["Planar Protection"] = {}; recipes["Planar Protection"]["bottle of paradise water"] = 1; recipes["Planar Protection"]["piece of stygian coal"] = 1; recipes["Regeneration"] = {}; recipes["Regeneration"]["patch of moss"] = 1; recipes["Regeneration"]["rose"] = 1; recipes["Regeneration"]["sprig of nightshade"] = 3; recipes["Strength"] = {}; recipes["Strength"]["bunch of daisies"] = 1; recipes["Strength"]["chunk of iron"] = 1; recipes["Strength"]["gold ingot"] = 1; recipes["Strength"]["rose"] = 2; recipes["Water Breathing"] = {}; recipes["Water Breathing"]["batch of mushrooms"] = 1; recipes["Water Breathing"]["bunch of daisies"] = 1; recipes["Water Breathing"]["bunch of lilies"] = 3; recipes["Death Immunity"] = {}; recipes["Death Immunity"]["handful of grave dirt"] = 3; recipes["Death Immunity"]["sprig of nightshade"] = 1; recipes["Death Immunity"]["chunk of onyx"] = 1; return recipes; } </script> </head> <body style="color: rgb(255, 255, 255); background-color: black;"> <font color="white"> <p>Safe-O-Mat Alpha Version <span style="font-weight: bold;">0.20<br> </span></p> </font><font color="white"> <p><span style="font-weight: bold;"></span></p> </font> <hr style="width: 100%; height: 2px;"><font color="white"> <p><span style="font-weight: bold;"><br> </span></p> </font> <form name="myform"> <select name="option"> <option value="takecomponent">Crafting Components</option> <option value="takeweapon">Weapons</option> <option value="takeammo">Ammo</option> <option value="takespell">Spells</option> <option value="takemisc">Other</option> <option value="givesafe">Own Inventory</option> </select> <input type="button" value="List" onclick="List()"> <input type="button" value="Craftable" onclick="Craftable()"></form> <br> <p ID="outputp"></p> </body> </html>'); void(close())}
[edit] Notes
v.1: If you don't get a scrollbar, doing a Select All / Copy / Paste into your favorite editor or word processor works just fine to show everything, even what's not visible out of screen range. -- --Kyllian 15:24, 26 November 2006 (CST)
v.2: This version is a bit slower and less stable on my computer than the previous one, possibly because it's doing more. Note archived version below for original tool.--Kyllian 09:34, 2 December 2006 (CST)
[edit] Archive :
Original version and various stages of modification below. (Since this is an alpha tool, an earlier version may work better on some systems. Or, of course, the reverse.)--Kyllian 09:34, 2 December 2006 (CST)
[edit] Original Tool
javascript:SafeOmat=open('','Safe-O-Mat','width=400,height=600,resizable'); SafeOmat.focus(); with(SafeOmat.document){write('<html> <head> <title>Safe-O-Mat Alpha</title> <script language="javascript" type="text/javascript"> function List() { ClearOutputp(); var ItemClassGroup = document.myform.option.value; var total_components = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options.length; alert("Total is "+ (total_components -1)); CompList = new Object(); for (var i = 1; i < total_components; i++) { var CompName = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options[i].text; if (isNaN(CompList[CompName])) { CompList[CompName] = 1; } else {CompList[CompName] = CompList[CompName] + 1;} } for(var property in CompList) { var value = CompList[property]; document.getElementById("outputp").innerHTML += property + " = " + value +"<BR>"; } } function ClearOutputp() { document.getElementById("outputp").innerHTML = ""; } </script> </head> <body style="color: rgb(255, 255, 255); background-color: black;"> <font color="white"> <p>Safe-O-Mat Alpha Version <span style="font-weight: bold;">0.1<br> </span></p> </font><font color="white"> <p><span style="font-weight: bold;"></span></p> </font> <hr style="width: 100%; height: 2px;"><font color="white"> <p><span style="font-weight: bold;"><br> </span></p> </font> <form name="myform"> <select name="option"> <option value="takecomponent">Crafting Components</option> <option value="takeweapon">Weapons</option> <option value="takespell">Spells</option> <option value="takemisc">Other</option> </select> <input type="button" value="List" onclick="List()"> <input type="button" value="Craftable" onclick="Craftable()"></form> <br> <p ID="outputp"></p> </body> </html>'); void(close())}
[edit] Comment/Modification:
I slightly modified your tool to include an ammo count and a count of your own inventory (useful if you carry a lot of transcribed scrolls) and also took away the (currently) redundant "Craftable" button:
javascript:SafeOmat=open('','Safe-O-Mat','width=400,height=600,resizable'); SafeOmat.focus(); with(SafeOmat.document){write('<html> <head> <title>Safe-O-Mat Alpha</title> <script language="javascript" type="text/javascript"> function List() { ClearOutputp(); var ItemClassGroup = document.myform.option.value; var total_components = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options.length; alert("Total is "+ (total_components -1)); CompList = new Object(); for (var i = 1; i < total_components; i++) { var CompName = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options[i].text; if (isNaN(CompList[CompName])) { CompList[CompName] = 1; } else {CompList[CompName] = CompList[CompName] + 1;} } for(var property in CompList) { var value = CompList[property]; document.getElementById("outputp").innerHTML += property + " = " + value +"<BR>"; } } function ClearOutputp() { document.getElementById("outputp").innerHTML = ""; } </script> </head> <body style="color: rgb(255, 255, 255); background-color: black;"> <font color="white"> <p>Safe-O-Mat Alpha Version <span style="font-weight: bold;">0.1<br> </span></p> </font><font color="white"> <p><span style="font-weight: bold;"></span></p> </font> <hr style="width: 100%; height: 2px;"><font color="white"> <p><span style="font-weight: bold;"><br> </span></p> </font> <form name="myform"> <select name="option"> <option value="givesafe">Own Inventory</option><option value="takeammo">Ammo</option><option value="takecomponent">Crafting Components</option> <option value="takeweapon">Weapons</option> <option value="takespell">Spells</option> <option value="takemisc">Other</option> </select> <input type="button" value="List" onclick="List()"></form> <br> <p ID="outputp"></p> </body> </html>'); void(close())}
Swot 19:58, 27 November 2006 (CST)
I've modified this more to work with the enhances interface, I basically split the options in 2 so the top half is legacy and the bottom half is enhanced. It's crude but it works. The complete code is:
javascript:SafeOmat=open('','Safe-O-Mat','width=400,height=600,resizable'); SafeOmat.focus(); with(SafeOmat.document){write('<html> <head> <title>Safe-O-Mat Alpha</title> <script language="javascript" type="text/javascript"> function List() { ClearOutputp(); var ItemClassGroup = document.myform.option.value; var total_components = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options.length; alert("Total is "+ (total_components -1)); CompList = new Object(); for (var i = 1; i < total_components; i++) { var CompName = window.opener.document.getElementsByName(ItemClassGroup)[0].instanceID.options[i].text; if (isNaN(CompList[CompName])) { CompList[CompName] = 1; } else {CompList[CompName] = CompList[CompName] + 1;} } for(var property in CompList) { var value = CompList[property]; document.getElementById("outputp").innerHTML += property + " = " + value +"<BR>"; } } function ClearOutputp() { document.getElementById("outputp").innerHTML = ""; } </script> </head> <body style="color: rgb(255, 255, 255); background-color: black;"> <font color="white"> <p>Safe-O-Mat Alpha Version <span style="font-weight: bold;">0.1<br> </span></p> </font><font color="white"> <p><span style="font-weight: bold;"></span></p> </font> <hr style="width: 100%; height: 2px;"><font color="white"> <p><span style="font-weight: bold;"><br> </span></p> </font> <form name="myform"> <select name="option"><option value="null">++Select++</option><option value="null">---Legacy Interface---</option><option value="givesafe">Own Inventory</option><option value="takeammo">Ammo</option><option value="takecomponent">Crafting Components</option> <option value="takeweapon">Weapons</option> <option value="takespell">Spells</option> <option value="takemisc">Other</option><option value="null">---Enhanced Interface---</option> <option value="shgivesafe">Own Inventory</option><option value="shtakeammo">Ammo</option><option value="shtakecomponent">Crafting Components</option> <option value="shtakeweapon">Weapons</option> <option value="shtakespell">Spells</option> <option value="shtakemisc">Other</option> </select> <input type="button" value="List" onclick="List()"></form><br> <p ID="outputp"></p> </body> </html>'); void(close())}
If you want to modify the other versions easily, the new form is:
<form name="myform"> <select name="option"><option value="null">++Select++</option><option value="null">---Legacy Interface---</option><option value="givesafe">Own Inventory</option><option value="takeammo">Ammo</option><option value="takecomponent">Crafting Components</option> <option value="takeweapon">Weapons</option> <option value="takespell">Spells</option> <option value="takemisc">Other</option><option value="null">---Enhanced Interface---</option> <option value="shgivesafe">Own Inventory</option><option value="shtakeammo">Ammo</option><option value="shtakecomponent">Crafting Components</option> <option value="shtakeweapon">Weapons</option> <option value="shtakespell">Spells</option> <option value="shtakemisc">Other</option> </select> <input type="button" value="List" onclick="List()"></form>
Swot 12:26, 9 December 2006 (CST)
