Problem using menu registered with GM_registerMenuCommand

96 views
Skip to first unread message

QAZ

unread,
May 12, 2008, 10:39:57 PM5/12/08
to greasemonkey-users
Hi,

I'm trying to create content on the fly and on demand, by registering
a callback using GM_registerMenuCommand. However, I'm not able to
consistently see the result of that callback. For example:

// ==UserScript==
// @name Test Greasemonkey on Amazon
// @description Test Greasemonkey on Amazon
// @include http://www.amazon.com/*
// ==/UserScript

// Register this cool app
function registerUserMenu() {
GM_registerMenuCommand('Test', showTest);
}

function showTest() {
var element, cell;
element = document.createElement("div");
cell = document.createTextNode((new Date()).toLocaleString());
element.appendChild(cell);

var body = document.getElementsByTagName("body")[0];
body.appendChild(element);

GM_log("Inserted");
}

//showTest();
window.addEventListener("load", registerUserMenu, false);
// ---------- ---------- ---------- ----------

When going to the test web site (amazon.com for example, then the
Kindle page), often times when I click on the user script menu item, I
can see the test message is logged into the error console, but the
test div has not been added to the page content. If I refresh the
current page, the test menu would always work. What gives?

I'm using the latest GM addon with FF 2.0 and 3.0b5.

Thanks.
- alex

Anthony Lieuallen

unread,
May 13, 2008, 9:56:54 AM5/13/08
to greasemon...@googlegroups.com
On 5/12/2008 10:39 PM, QAZ wrote:
> window.addEventListener("load", registerUserMenu, false);

First, this event listener is pointless. Just call gm register menu
command.

Second this:

> var body = document.getElementsByTagName("body")[0];
> body.appendChild(element);

Would be much more straightforward as "document.body.appendChild(element);"

That said, Amazon is doing something strange. If I run the same script
on www.example.com, it works fine. That's all I've got right now.

Reply all
Reply to author
Forward
0 new messages