// Wolffauer's KoL Scripts
// Questions, comments, bug reports or donations to: Wolffauer (#1137554)
//
// ==UserScript==
// @name          Wolffauer's Potion Hints
// @namespace     http://www.knauer.org/mike/kol/
// @description   Version 1.25 - Adds info about what each potion does. 
// @include       *kingdomofloathing.com/main.php*
// @include       *kingdomofloathing.com/charpane.php*
// @include       *kingdomofloathing.com/inventory.php*
// @include       *kingdomofloathing.com/multiuse.php*
// @include       *kingdomofloathing.com/charsheet.php*
// @include    	  *kingdomofloathing.com/ascend.php*
// @include    	  *kingdomofloathing.com/fight.php*
// @include       *127.0.0.1:*/main.php*
// @include       *127.0.0.1:*/charpane.php*
// @include       *127.0.0.1:*/inventory.php*
// @include       *127.0.0.1:*/multiuse.php*
// @include       *127.0.0.1:*/charsheet.php*
// @include    	  *127.0.0.1:*/ascend.php*
// @include    	  *127.0.0.1:*/fight.php*
// @exclude       http://images.kingdomofloathing.com/*
// @exclude       http://forums.kingdomofloathing.com/*
// ==/UserScript==


/********************************** Recent Changes *****************************************
Recent Updates:
Version 1.25: Added special handling for sugar sheets
Version 1.24: Broke the KoL re-load when using items, so that I can grab the Bang potion results
Version 1.23: Added special handling for sushi-rolling mat
Version 1.22: Added special handling for the Scratch 'n' sniff stickers
Version 1.21: Now works even when the inventory images are off
Version 1.20: Improved processing of itemDB
Version 1.18: Plays nicer with OneTonTomato's Price Gun
Version 1.17: Fixed a bug causing the page to constantly reload when trying to ascend.
Version 1.16: Returning after too long.  Updating some interaction with KoLmafia.
              Works with the action bar now.
Version 1.13: Ok, got rid of the loop, now trying to fix the actual detection.
Version 1.12: Testing a fix to a bug causing an infinite loop when funkslinging. 
Version 1.10: Now trys to learn both potions when using funkslinging.
			  Plays nice with Picklish's Use Acquired script.
Version 1.00: Database completed for NS13 - testing done.
Version 0.90: Added detection of bang potions in combat
Version 0.85: Removed bang potion predictions
Version 0.82: Changed how level is displayed
Version 0.80: NS13 Update.  Adding level information to food & booze
Version 0.76: Tried to add IDing booze potion while in oxy or teetotaler - failed...
Version 0.75: Added EZ-Cook Oven
Version 0.74: Added [chug]
Version 0.73: Bug fixes.  Worked on Use Multiple.
Version 0.72: Added KoLMafia links
Version 0.71: Bug fixes.  Added hedge maze.
Version 0.70: Auto Bang Potion ID
Version 0.68: Simple Bang Potion ID
Version 0.67: Adding Food and Drink
Version 0.65: Finished conversion to remote database
Version 0.60: Put in Picklish's version checker
Version 0.5x: Additional updates
Version 0.5: Initial version of the script - testing and adding potions

Inspired by and based in part off of Naltrexone's Bang Potion Minder and
Hellion's Guide to Identifying your Bang Potions
********************************************************************************************/

// Set to true to see hints on Multi Use dropdown (gets messy, needs more testing)
var multiUseHint = false;

// ---------------------------------------------------------------------------
// Picklish's VERSION CHECKER 1.3

// - BEGIN MANUAL SECTION -
var currentVersion = "1.25";
var scriptURL = "http://www.knauer.org/mike/kol/WolffauerPotionHints.user.js";
var scriptName = "Wolffauer's Potion Hints";

var potionhintdb = "http://www.knauer.org/mike/kol/itemhintdb.txt";
var gotNewPotionHintDB = "newpotionhintdb";
var g_dbLine = "phdb_";

// The version checker will show non-errors if and only if this boolean
// is false and GM_getValue("showOnlyErrors") is false or unset.
var showOnlyErrors = true;

// The elements of resources are five element arrays which contain a
// resource name (for displaying), a resource link (for downloading
// the resource), a downloaded value name (for storing the result of the
// resource in a greasemonkey variable of that name), and a time in days
// before re-checking this resource, and finally a variable to set to "1"
// whenever a variable has been gotten.
//var resources = "";
var resources = new Array(
    new Array(
        "Item Database",
        potionhintdb,
        "potionhintdb",
        7,
        gotNewPotionHintDB
    )
);

// - END MANUAL SECTION -

// - BEGIN CUT AND PASTE SECTION -
var datePrefix = "CheckTime-";

function MakeBullet(message)
{
    return "<tr><td><font size=-2>&nbsp;&#42;" + message + "</font></td></tr>";
}

// Check for an updated script version and print the result box...
function CheckScriptVersion()
{
    // Preemptively set error, in case request fails...
    GM_setValue("webVersion", "Error")

    GM_xmlhttpRequest({
        method: "GET",
        url: scriptURL,
        headers:
        {
            "User-agent": "Mozilla/4.0 (compatible) Greasemonkey",
            "Accept": "text/html",
        },
        onload: function(responseDetails)
        {
            if (responseDetails.status == "200")
            {
                var m = responseDetails.responseText.match(
                    /description\s*Version (\w+(?:\.\w+)?)/);
                if (m && !isNaN(m[1]))
                {
                    GM_setValue("webVersion", m[1]);
                }
            }

            var message;
            var warningLevel = 0;
            var forceGet = false;

            var webVer = parseFloat(GM_getValue("webVersion"));
            if (GM_getValue("webVersion", "Error") == "Error")
            {
                message = "Failed to check website for updated version of script.";
                warningLevel = 1;
            }
            else if (isNaN(webVer))
            {
                message = "Couldn't find suitable version number.";
                warningLevel = 1;
            }
            else
            {
                if (webVer > parseFloat(currentVersion))
                {
                    message = "Right click <a href='" + scriptURL + "' TARGET='_blank'>here</a> and select 'Install User Script' for Version " + webVer + ".";
                    warningLevel = 2;
                }
                else
                {
                    if (webVer < parseFloat(currentVersion))
                    {
                        message = "Script is newer than web version.";
                        warningLevel = 0;
                        forceGet = true;
                    }
                    else
                    {
                        message = "Script is latest version.";
                        warningLevel = 0;
                    }
                }
            }

            // In either case, check remaining resources...
            CheckResource(0, warningLevel, MakeBullet(message), forceGet);
        }
    });
}

function CheckResource(index, warningLevel, message, forceGet)
{
    if (index >= resources.length)
    {
        PrintCheckVersionBox(warningLevel, message, forceGet);
        return;
    }

    var name = resources[index][0];
    var url = resources[index][1];
    var varname = resources[index][2];
    var daylimit = parseFloat(resources[index][3]);
    var gotvar = resources[index][4];

    var now = new Date();

    // if the script version has changed, update resource.
    var oldVersion = GM_getValue(varname + "_version", "0.0");
    if (parseFloat(oldVersion) < parseFloat(currentVersion))
    {
        forceGet = true;
    }

    // if don't need to get...
    if (!forceGet && GM_getValue(datePrefix + varname, 0) != 0 &&
        (now.getTime() <= Date.parse(GM_getValue(datePrefix + varname)) +
        daylimit * 86400000))
    {
        var timeString;
        if (daylimit == 1.0)
            timeString = daylimit + " day";
        else
            timeString = daylimit + " days";
        message += MakeBullet(name + ": Less than " + timeString +
            " old, using cached version.");
        CheckResource(index + 1, warningLevel, message, forceGet);
        return;
    }

    // otherwise we need to get this resource...
    GM_xmlhttpRequest({
        method: 'GET',
        url: url,
        headers: {'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
            'Accept': 'text/html',},
        varname: varname,
        name: name,
        index: index,
        gotvar: gotvar,
        onload: function(responseDetails)
        {
            if (responseDetails.status != 200)
            {
                GM_log("Error getting " + this.name + "@" + this.url + ": " +
                    responseDetails.status);

                if (GM_getValue(varname, "") == "")
                {
                    if (warningLevel < 2)
                        warningLevel = 2;
                    message += MakeBullet(this.name + ": Error accessing resource.  No cached version to use.");
                }
                else
                {
                    if (warningLevel < 1)
                        warningLevel = 1;
                    message += MakeBullet(this.name + ": Error accessing stale resource.  Using cached version.");
                }
            }
            else
            {
                GM_setValue(this.varname, responseDetails.responseText);
                var size = GM_getValue(this.varname).length;
                message += MakeBullet(this.name + ": Downloaded new version (" + size + " bytes.)");
                GM_log("Got " + this.varname + " (" + size + " bytes)");

                var now = new Date();
                GM_setValue(datePrefix + this.varname, now.toString());

                GM_setValue(gotvar, 1);
                GM_setValue(varname + "_version", currentVersion);
            }

            CheckResource(index + 1, warningLevel, message, forceGet);
        }
    });
}

function PrintCheckVersionBox(resourceWarningLevel, resourceMessage, forceBox)
{
    // set color from warning level
    var color;
    if (resourceWarningLevel > 1)
    {
        color = "red";
    }
    else if (resourceWarningLevel > 0)
    {
        color = "orange";
    }
    else
    {
        color = "blue";

        // if no errors, return...
        if (!forceBox && (showOnlyErrors ||
            GM_getValue("showOnlyErrors", false)))
        {
            return;
        }
    }

    var span = document.createElement("center");
    span.innerHTML = "<table style='border: 1px solid " + color + "; margin-bottom: 4px;' width=95% cellpadding=1 cellspacing=0><tr><td bgcolor=" + color + "><font color=white size=-2><b>" + scriptName + "</b> " + currentVersion + ":</font></td></tr>" + resourceMessage + "</table>";

    document.body.insertBefore(span, document.body.firstChild);
}

if (window.location.pathname == "/main.php")
{
    CheckScriptVersion();
}
// - END CUT AND PASTE SECTION -
// ---------------------------------------------------------------------------

function trimString(targetString)
{
  	targetString = targetString.replace( /^\s+/g, "" );
  	targetString = targetString.replace( /\s+$/g, "" );
  	return targetString;
}

function ParseDB()
{
	// Get the database string from GM
    var database = GM_getValue("potionhintdb", "");
    if (database == "")
        return;

	// Convert the database string into an array of items
    var lines = database.split("\n");

	// For each item in the array
    var numLines = lines.length;
    for (var i = 0; i < numLines; i++)
    {
		// Ignore comments
		if (lines[i][0] != '*')
		{
        	// Make an array of the fields for that item
        	var split = lines[i].split("|");
        	if (split.length >= 8)
        	{
            	var itemnum = split[0];
            	GM_setValue(g_dbLine + itemnum, lines[i]);
        	}
		}
    }
}

// If we need to, parse the database...
if (GM_getValue(gotNewPotionHintDB, 1) == 1)
{
    ParseDB();
    GM_setValue(gotNewPotionHintDB, 0);
}


if (window.location.pathname == "/charpane.php")
{
  	var boldThing = document.getElementsByTagName("b")[0]
	if (boldThing)
	{
		var charName = boldThing.innerHTML;
  		GM_setValue("CurCharName",charName);
	}
}

// Detect the use of a bang potion in combat
if (window.location.pathname == "/fight.php")
{
	// Is there an action bar?
  	var docHead = document.getElementsByTagName("head")[0];
	actBarIdx = docHead.innerHTML.indexOf('actionbar');

	results = document.getElementsByTagName("table");
	if ((results.length > 0) && (actBarIdx > 0))
	{
		prevResult = results;
		results = prevResult[1].getElementsByTagName("table");
	}
	else 
	{	
		prevResult = results;
		results = prevResult[0].getElementsByTagName("table");
	}	
	
	if (results.length > 0)
	{
		pageData = results[0].innerHTML;
		var lastIndex = 0;
		var firstIndex = 0;

		while (firstIndex != -1)
		{
			firstIndex = pageData.indexOf('You throw the ', lastIndex);
		   	if ((firstIndex > -1) && (pageData.indexOf('potion', firstIndex) > -1))
			{
			    var effectName = '';
				var effectNum = 0;
				var effectIdx = pageData.indexOf('looks confused', firstIndex);
	          	if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
				{
					effectName = '-30% Mys (20)';
					effectNum = 1;
				}
	          	else 
				{
					effectIdx = pageData.indexOf('like a wino', firstIndex);
					if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
					{
						effectName = '+1-3 Drunkenness';
						effectNum = 2;
					}
		          	else 
					{
						effectIdx = pageData.indexOf('feels better', firstIndex);
						if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
						{
							effectName = '+14-16 HP and MP';
							effectNum = 3;
						}
			          	else 
						{
							effectIdx = pageData.indexOf('more stylish', firstIndex);
							if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
							{
								effectName = '+25% Mox (10)';
								effectNum = 4;
							}
				          	else 
							{
								effectIdx = pageData.indexOf('much stronger', firstIndex);
								if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
								{
									effectName = '+25% Mus (10)';
									effectNum = 5;
								}
					           	else 
								{
									effectIdx = pageData.indexOf('much smarter', firstIndex);
									if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
									{
										effectName = '+25% Mys (10)';
										effectNum = 6;
									}
						           	else 
									{
										effectIdx = pageData.indexOf('blinks', firstIndex);
										if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
										{
											effectName = '+12.5% Items (10)';
											effectNum = 7;
										}
							         	else 
										{
											effectIdx = pageData.indexOf('yawns', firstIndex);
											if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
											{
												effectName = '-30% Mus (20)';
												effectNum = 8;
											}
								         	else 
											{
												effectIdx = pageData.indexOf('starts disappearing', firstIndex);
												if ((effectIdx > -1) && (firstIndex + 200 > effectIdx))
												{
													effectName = 'Teleportitis (10)';
													effectNum = 9;
												}
											}
										}
									}
								}
							}
						}
					}
				}
	 
	 			if (effectNum > 0)
				{
				    var potionName = pageData.substring(firstIndex + 14,
		            	pageData.indexOf('potion', firstIndex)+6);
	 				if (potionName == "milky potion") 		{ potionNum = 819; }
					else if (potionName == "swirly potion") { potionNum = 820; }
					else if (potionName == "bubbly potion") { potionNum = 821; }
					else if (potionName == "smoky potion") 	{ potionNum = 822; }
					else if (potionName == "cloudy potion") { potionNum = 823; }
					else if (potionName == "effervescent potion") { potionNum = 824; }
					else if (potionName == "fizzy potion") 	{ potionNum = 825; }
					else if (potionName == "dark potion") 	{ potionNum = 826; }
					else if (potionName == "murky potion") 	{ potionNum = 827; }
					else { potionNum = 0; }
	
			   		var charName = GM_getValue("CurCharName","");
					if (charName != "")
					{
		        	  	GM_setValue(charName + '-' + potionNum, effectName + "|" + effectNum);
					}
				}
			}
			lastIndex = firstIndex + 1;
   		}
	}
}

// Detect the use of a bang potion
if ((window.location.pathname == "/inventory.php")||
    (window.location.pathname == "/multiuse.php"))
{
	results = document.getElementsByTagName("blockquote");
    var alreadyStoredEffect = 0;

    for (var i=0; i < results.length; i++ )
	{
      	curItem = results[i];
        if ((alreadyStoredEffect==0)
			&& (((curItem.innerHTML.indexOf('You drink the ') > -1)
			&& (curItem.innerHTML.indexOf('potion.') > -1))
			|| (curItem.innerHTML.indexOf('This smells like liquid fire') > -1)))
		{
		    var effectName = '';
			var effectNum = 0;
          	if (curItem.innerHTML.indexOf('liquid fire') > -1)
			{
				effectName = '+1-3 Drunkenness';
				effectNum = 2;
			}
          	else if (curItem.innerHTML.indexOf('hit points') > -1)
			{
				effectName = '+14-16 HP and MP';
				effectNum = 3;
			}
    		else
			{
          		effectName = trimString(curItem.getElementsByTagName("b")[0].innerHTML);
				if (effectName.indexOf('<') > 0) { effectName = trimString(effectName.substring(0,effectName.indexOf('<'))); }

	            if (effectName == 'Confused') { effectName = "-30% Mys (20)"; effectNum = 1; }
	          	else if (effectName == "Izchak's Blessing") { effectName = "+25% Mox (10)"; effectNum = 4; }
	          	else if (effectName == 'Strength of Ten Ettins') { effectName = "+25% Mus (10)"; effectNum = 5; }
	          	else if (effectName == 'Strange Mental Acuity') { effectName = "+25% Mys (10)"; effectNum = 6; }
	          	else if (effectName == 'Object Detection') { effectName = "+12.5% Items (10)"; effectNum = 7; }
	          	else if (effectName == 'Sleepy') { effectName = "-30% Mus (20)"; effectNum = 8; }
	          	else if (effectName == 'Teleportitis') { effectName = "Teleportitis (10)"; effectNum = 9; }
           }

 			if (effectNum > 0)
			{
			    var potionName = curItem.innerHTML.substring(curItem.innerHTML.indexOf('You drink the ') + 14,
	            	curItem.innerHTML.indexOf('potion')+6);
 				if (potionName == "milky potion") 		{ potionNum = 819; }
				else if (potionName == "swirly potion") { potionNum = 820; }
				else if (potionName == "bubbly potion") { potionNum = 821; }
				else if (potionName == "smoky potion") 	{ potionNum = 822; }
				else if (potionName == "cloudy potion") { potionNum = 823; }
				else if (potionName == "effervescent potion") { potionNum = 824; }
				else if (potionName == "fizzy potion") 	{ potionNum = 825; }
				else if (potionName == "dark potion") 	{ potionNum = 826; }
				else if (potionName == "murky potion") 	{ potionNum = 827; }
				else { potionNum = 0; }

		   		var charName = GM_getValue("CurCharName","");
				if (charName != "")
				{
	        	  	GM_setValue(charName + '-' + potionNum, effectName + "|" + effectNum);
				}
          		alreadyStoredEffect = 1;
			}
   		}
	}
}

if (window.location.pathname == "/inventory.php")
{
	var itemElements = document.getElementsByTagName("td");
	var potionEffect = '';
	var firstPart = '';
	var secondPart = '';
	var isBang = 0;
	for (var i=0; i < itemElements.length; i++ )
	{
		nested = itemElements[i].getElementsByTagName("td");

		curItems = itemElements[i].getElementsByTagName("a");
		for (var j=0; j < curItems.length; j++)
		{
			curItem = curItems[j];
			if ((nested.length == 0) && (curItem) && ((curItem.text == "[use]") || (curItem.text == "[eat]")
					|| (curItem.text == "[drink]") || (curItem.text == "[chug]")))
			{
				potionEffect = "";
				fdsEffect = "";
	
				var m = curItem.href.match(/whichitem=(\w+(?:\.\w+)?)/);
				if (m)
				{
					if ((m[1] > 818) && (m[1] < 828))
					{
				   		var charName = GM_getValue("CurCharName","");
	    	    	  	var effect = GM_getValue(charName + '-' + m[1], "(Unknown)|0");
						var effectName = effect.split("|")[0];
						potionEffect = "0|0|0|" + effectName + "|0|0|0|0";
						isBang = 1;
					}
					else
					{
						potionEffect = GM_getValue(g_dbLine + m[1], "");
					}
	
					if (potionEffect != "")
					{
				        // Make an array of the fields for that item
				        var details = potionEffect.split("|");
						potionEffect = details[3];
						var fullness = details[4];
						var drunkness = details[5];
						var spleen = details[6];
						var level = details[7];
						if (((spleen > 0) || (fullness > 0) || (drunkness > 0)) && (level == 0))
						{
							GM_log("Missing level req for item: " + m[1]);
							fdsEffect = fdsEffect + "<font color=red>[?L]</font>";
						}
						if (fullness > 0)
						{
							if (level > 1)
								fdsEffect = fdsEffect + "[" + level + "L " + fullness + "f]";
							else
								fdsEffect = fdsEffect + "[" + fullness + "f]";
						}
						if (drunkness > 0)
						{
							if (level > 1)
								fdsEffect = fdsEffect + "[" + level + "L " + drunkness + "d]";
							else
								fdsEffect = fdsEffect + "[" + drunkness + "d]";
						}
						if (spleen > 0)
						{
							if (level > 1)
								fdsEffect = fdsEffect + "[L" + level + " " + spleen + "s]";
							else
								fdsEffect = fdsEffect + "[" + spleen + "s]";
						}
					}
					else
					{
						GM_log("Missing item ID: " + m[1]);
						potionEffect = "<font color=red>unknown item</font>";
					}
				}
				else
				{
					if (curItem.href.match(/uneffect/))
					{
						potionEffect = "Remove effects";
					}
					else if (curItem.href.match(/cook/))
					{
						potionEffect = "Make food";
					}
					else if (curItem.href.match(/cocktail/))
					{
						potionEffect = "Make cocktails";
					}
					else if (curItem.href.match(/jewelry/))
					{
						potionEffect = "Make jewelry";
					}
					else if (curItem.href.match(/combine/))
					{
						potionEffect = "Make stuff";
					}
					else if (curItem.href.match(/paster/))
					{
						potionEffect = "Make stuff";
					}
					else if (curItem.href.match(/sugarsheets/))
					{
						potionEffect = "Make stuff";
					}
					else if (curItem.href.match(/smith/))
					{
						potionEffect = "Make equipment";
					}
					else if (curItem.href.match(/starchart/))
					{
						potionEffect = "Make star stuff";
					}
					else if (curItem.href.match(/sushi/))
					{
						potionEffect = "Make sushi";
					}
					else if (curItem.href.match(/hedgepuzzle/))
					{
						potionEffect = "";
					}
					else if (curItem.href.match(/sticker=3509/))
					{
						potionEffect = "+25% Items (20)";
					}
					else if (curItem.href.match(/sticker=3510/))
					{
						potionEffect = "+2 Stats Per Fight (20)";
					}
					else if (curItem.href.match(/sticker=3511/))
					{
						potionEffect = "+25% Meat (20)";
					}
					else if (curItem.href.match(/sticker=3512/))
					{
						potionEffect = "+10% Mus/Mys/Mox (20)";
					}
					else if (curItem.href.match(/sticker=3513/))
					{
						potionEffect = "+3 Prismatic Damage (20)";
					}
					else if (curItem.href.match(/sticker=3514/))
					{
						potionEffect = "+20 Weapon/Spell Damage (20)";
					}
					else
					{
						GM_log("Missing [use] link: " + curItem.href);
						potionEffect = "<font color=red>unknown item</font>";
					}
				}
	
				if (fdsEffect != "")
				{
					var newNode = document.createElement("strong");
					newNode.innerHTML = " " + fdsEffect;
					curItem.parentNode.insertBefore(newNode, curItem.previousSibling);
				}
				if (potionEffect != "")
				{
					if (isBang == 1)
					{
						var last = curItem.parentNode.innerHTML;
						curItem.parentNode.innerHTML = "<br><strong>" + potionEffect + "</strong>" + last;
					}
					else
					{
						var newNode = document.createElement("strong");
						newNode.innerHTML = potionEffect;
						curItem.parentNode.insertBefore(newNode, curItem);
	
						newNode = document.createElement("br");
						curItem.parentNode.insertBefore(newNode, curItem);
					}
				}
			}
		}
	}
}

if ((window.location.pathname == "/multiuse.php") && multiUseHint)
{
    // Handle items in the drop down list on the "Use Multiple Items" page.
    var itemElements = document.getElementsByTagName("option");

    for (var i=0; i < itemElements.length; i++ )
    {
        curItem = document.getElementsByTagName("option")[i];

        var potionEffect = "";

		if ((curItem.value > 818) && (curItem.value < 828))
		{
	   		var charName = GM_getValue("CurCharName","");
    	  	var effect = GM_getValue(charName + '-' + curItem.value, "(Unknown)|0");
			var effectName = effect.split("|")[0];
			potionEffect = "0|0|0|" + effectName + "|0|0|0";
		}
		else
		{
			potionEffect = GM_getValue(g_dbLine + curItem.value, "");
		}

		if (potionEffect != "")
		{
	        var details = potionEffect.split("|");
			potionEffect = details[3];
		}

        curItem.innerHTML = curItem.innerHTML + ' ' + potionEffect;
    }
}

function clearEffects()
{
	GM_log("Clear Effects called");
  	var charName = GM_getValue("CurCharName","");
	if (charName != "")
	{
	   	GM_setValue(charName + '-819', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-820', '(Unknown Effect)|0');
	 	GM_setValue(charName + '-821', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-822', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-823', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-824', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-825', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-826', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-827', '(Unknown Effect)|0');
		self.location.reload();
	}
}

if (window.location.pathname == "/charsheet.php")
{
  	var charName = GM_getValue("CurCharName","");

	var cells = document.getElementsByTagName('B');
	for(var i=0;i<cells.length;i++) 
	{
		var c;
		if((c=cells[i].firstChild) && c.nodeValue == "Current Familiar:") 
		{
			target=cells[i].parentNode;
			
			newNode = document.createElement("p");
			newNode.innerHTML = 
				'<b>Bang Potion Effects:</b> (<span style="cursor: pointer;" title="Click to reset potions" id="resetEffect" ' + 
				'>reset</span>)<br>' +
				'<table><tr><td colspan=2 bgcolor=black height=1></td></tr>' +
			    '<tr><td><b>bubbly potion</b>:</td><td>' + GM_getValue(charName +'-821', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>cloudy potion</b>:</td><td>' + GM_getValue(charName +'-823', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>dark potion</b>:</td><td>' + GM_getValue(charName +'-826', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>effervescent potion</b>:</td><td>' + GM_getValue(charName +'-824', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>fizzy potion</b>:</td><td>' + GM_getValue(charName +'-825', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>milky potion</b>:</td><td>' + GM_getValue(charName +'-819', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>murky potion</b>:</td><td>' + GM_getValue(charName +'-827', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>smoky potion</b>:</td><td>' + GM_getValue(charName +'-822', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td><b>swirly potion</b>:</td><td>' + GM_getValue(charName +'-820', '(Unknown Effect)').split("|")[0] + '</td></tr>'+
			    '<tr><td colspan=2 bgcolor=black height=1></td></tr></table>';

			target.parentNode.appendChild(newNode);
		}
	}
	var el = document.getElementById("resetEffect");
	el.addEventListener("click", clearEffects, false);
}

// If the player is ascending, we need to clear these values-- they don't keep from one ascension to the next.
if (window.location.pathname == "/ascend.php")
{
  	var charName = GM_getValue("CurCharName","");
	if (charName != "")
	{
	   	GM_setValue(charName + '-819', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-820', '(Unknown Effect)|0');
	 	GM_setValue(charName + '-821', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-822', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-823', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-824', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-825', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-826', '(Unknown Effect)|0');
	  	GM_setValue(charName + '-827', '(Unknown Effect)|0');
	}
}

