Disappearing menu commands after user input in Tampermonkey

Tampermonkey is a Google Chrome extension that attempts to emulate Greasemonkey functionality. To be clear, I got my script to work in Chrome and change the default JavaScript to display. However, I wanted to check the menu commands and entered the six-digit hexadecimal color code after pressing the command in the Tampermonkey menu. I reloaded the page and the commands disappeared from the menu! My script was still there (and a checkmark was checked).

No matter what I did or what code I changed, I could never emulate this initial functionality after user input was installed. This makes me think that there is some persistent data that I cannot delete, which is why my script will fail prematurely. NOTE. This exact script works fine and error free in Firefox.

This is obviously not a Tampermonkey forum, but people here are very well versed in cross-platform compatibility. After all the changes below, I have not heard a single call to the Chrome console, and at the moment I just have no ideas. Here are some things I've tried (without success). Any console errors are listed:

  • Change jQuery version from 1.5.1 to 1.3.2
  • Call localStorage.getItem ('prevoColor') from the console after loading the page (both null)
  • Changing client-side storage from localStorage to get / setValue
  • Call GM_getValue from console = ReferenceError: GM_getValue not defined
  • Delete localStorage entries for veekun.com in Chrome settings
  • Updating, reinstalling the script and restarting the browser more than I can count
  • Repeating all the above commands using Firebug Lite (bookmarklet)

Here is the code I used:

// ==UserScript==
// @name           Veekun Comparison Highlighter
// @namespace      tag://veekun
// @description    Highlights moves exclusive to pre-evolutions on veekun.com family comparison pages (user-defined colors available)
// @include        http://veekun.com/dex/gadgets/*
// @author         Matthew Ammann
// @version        1.0.3
// @date           3/11/11
// @require        http://sizzlemctwizzle.com/updater.php?id=98824
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==

/*
Goal: Change checkmark color & move name to user-specified color on family comparison pages if 
[DONE] Baby poke has a LEVEL-UP move unlearned by any evolutions
    [DONE] a) Make sure move is not a TM or tutor move
[DONE] Any other mid-evolution has a move unlearnable by a final evo (Caterpie, Weedle families)
    [DONE] a) Make sure move is not a TM or tutor move
[DONE] Any pre-evo has a TUTOR move unlearned by any evo (Murkrow in HG/SS)
[] Implement auto-update after uploading to userscripts.org

Credits: Brock Adams, for helping with Chrome compatibility
         Metalkid, for the jQuery consult
*/

var isLevelupMove = false;
var isTutorMove = false;
var isTM = false;
var TMhead = $('#moves\\:machine');
var hasSecondEvo = false;
var hasFinalEvo1 = false;
var hasFinalEvo2 = false;
var header = $('.header-row').eq(1);
var TMmoves = new Array();

//This section deals with the user-defined colors 

GM_registerMenuCommand("Color for pre-evolutionary-only moves", prevoColorPrompt)
GM_registerMenuCommand("Color for first evolution-only moves", evoColorPrompt)


var prevoColor = GM_getValue('prevoColor', '#FF0000');
var evoColor = GM_getValue('evoColor', '#339900');

function prevoColorPrompt()
{
    var input = prompt("Please enter a desired 6-digit hex color-code for pre-evolutionary pokemon:") 
    GM_setValue('prevoColor', '#'+input);
}

function evoColorPrompt()
{
    var input = prompt("Please enter the desired 6-digit hex color-code for first-evolution pokemon:") 
    GM_setValue('evoColor', '#'+input);
}

//This loop tests each 'th' element in a sample header row, determining how many Evos are currently present in the chart.

$('.header-row').eq(1).find('th').each(function(index) 
{
    if($(this).find('a').length != 0)
    {
        switch(index)
        {
            case 2:
            hasSecondEvo = true;
            break;

            case 3:
            hasFinalEvo1 = true;
            break;

            case 4:
            hasFinalEvo2 = true;
            break;
        }
    }
});

//All 'tr' siblings are TM moves, since it the last section on the page
//This array puts only the names of the available TMs into the TMmoves array
TMhead.nextAll().each(function(index)
{
    TMmoves.push($(this).children(":first").find('a').eq(0).html());
});

$('tr').each(function(index) 
{
    var moveName = $(this).children(":first").find('a').eq(0).html();   
    moveName = $.trim(moveName);

    switch($(this).attr('id'))
    {
        case 'moves:level-up':
            isLevelupMove = true;   
            break;

        case 'moves:egg':
            isLevelupMove = false;
            break;  

        case 'moves:tutor':
            isTutorMove = true;

        case 'moves:machine':
            isTM = true;    
    }

    if(isLevelupMove || isTutorMove)
    {
        var babyMoveCell = $(this).find('td').eq(0);
        babyMoveText = $.trim(babyMoveCell.html());

        secondEvoCell = babyMoveCell.next();
        secondEvoText = $.trim(secondEvoCell.html());

        finalEvo1Cell = secondEvoCell.next();
        finalEvo1Text = $.trim(finalEvo1Cell.html());

        finalEvo2Cell = finalEvo1Cell.next();
        finalEvo2Text = $.trim(finalEvo2Cell.html());

        //This checks if evolutions have checkmarks

        if(babyMoveText.length > 0)
        {
            if(hasSecondEvo && secondEvoText.length == 0 || hasFinalEvo1 && finalEvo1Text.length == 0 || 
                hasFinalEvo2 && finalEvo2Text.length == 0)
            {
                //See if the move is a TM before proceeding 
                var tm = tmCheck(moveName);

                if(!tm)
                {

                    if(secondEvoText.length > 0)
                    {       
                        babyMoveCell.css("color", evoColor);
                        secondEvoCell.css("color", evoColor);
                        babyMoveCell.prev().find('a').eq(0).css("color", evoColor); //highlights move name
                    }
                    else
                    {
                        babyMoveCell.css("color", prevoColor);
                        babyMoveCell.prev().find('a').eq(0).css("color", prevoColor);
                    }
                }
            }
        }
        else if(secondEvoText.length > 0)
        {
            if(hasFinalEvo1 && finalEvo1Text.length == 0 || hasFinalEvo2 && finalEvo2Text.length == 0)
            {
                var tm = tmCheck(moveName); 

                if(!tm)
                {
                    secondEvoCell.css("color", evoColor);
                    babyMoveCell.prev().find('a').eq(0).css("color", evoColor);
                }
            }
        }
    }

});

function tmCheck(input)
{
    var isTM = false;

    //Iterate through TMmoves array to see if the input matches any entries
    for(var i = 0; i < TMmoves.length; i++)
    {   
        if(input == TMmoves[i])
        {
            isTM = true;
            break;
        }
    }

    if(isTM == true)
        return true;
    else
        return false;       
}

//alert("evoColor: " + localStorage.getItem('evoColor') + ". prevoColor: " + localStorage.getItem('prevoColor'));

Any ideas as to why this is happening?

: , : " Tampermonkeys @require . updater, updater , , . script, , . script, , Tampermonkey , . Chrome, , . , NinjaKit ."

+1
1

URL- ? http://veekun.com/dex/gadgets/stat_calculator.

script Tampermonkey. / , script.

, -, sizzlemctwizzle.com. // @require . , script.

, , , , Tampermonkey script. ( - , , .)

. :).

+1

All Articles