Here is my script code:
// ==UserScript==
// @name test
// @description test
// @include http://*
// @copyright Bruno Tyndall
// ==/UserScript==
var main = function() {
var b = document.getElementsByTagName('body')[0];
var t = document.createElement('div');
t.innerHTML = '<a href="javascript:void(0);" style="color:white;">Hello World</a>';
t.style.position = 'absolute';
t.style.zIndex = 1000;
t.style.bottom = '5px';
t.style.right = '5px';
t.firstChild.setAttribute('onclick', 'test();');
b.appendChild(t);
}
var test = function() {
alert("Hello World");
}
main();
The only issue I have is when Hello World is clicked the page cannot find the test() function. Please tell me I don't have to solve it by innerHTML'ing the function onto the page like this. Is there another way?
Thanks.