S
sammy
I have finaly got the GM_HTTP handlers to work but I still have a
problem with calling a global function as onclick handler ( for radio
button ).
The error says: "nrun is not defined"
In desperation I have tried to prepend "this." and "namespace."
but can't figure it out.
Although I am not going to call this one function from elsewhere,
I'd rather not paste the whole text of the function in the onclick quotes.
Thanks in advance.
<code>
// ==UserScript==
// @name page reader greasemonkey script
// @author Sambo
// @description insert some text on some page
// @include http://olg.ca/*
// @namespace sams_cluster
// @email (e-mail address removed)
// @version 0.1
// ==/UserScript==
var SCRIPT = {
url : 'file:///home/public/devel/linux/js/greasemonkey/sams_first.user.js',
version : '0.1' //same value as @version
};
//set global variables
var server = location.hostname;
var rootPath = "http://" + server + "/";
//var lang = new Array();
//var dom = new DOMUtils();
var raw = true;
var command_done = false;
var commands = ""
function response_handler(responseDetails)
{
GM_log(responseDetails.responseText);
}
function command_handler(responseDetails)
{
GM_log(responseDetails.responseText);
}
function fetch_command()
{
GM_log( "sfetch_command")
obj1 = { method:"GET",
url:"http://192.168.0.6:7777/command/"+location.host,
headers:{
"User-Agent":"monkeyagent",
"Accept":"text/monkey,text/xml",
"Content-type":"application/x-www-form-urlencoded" },
onload: command_handler };
GM_xmlhttpRequest( obj1 )
command_done = true;
}
function nrun()
{
GM_log("clicked");
run_flag = GM_getValue( "Rum_sams_reader", -1 )
item = document.getElementById("samspot").firstChild
if ( run_flag==0 )
{
run_flag = 1;
GM_setValue( "Rum_sams_reader", 1 )
item.checked=true
return( "True?" )
}
else
{
run_flag = 0;
GM_setValue( "Rum_sams_reader", 0 )
item.checked=false
return( "False?" )
}
}
function main()
{
run_flag = GM_getValue( "Rum_reader", -1 )
oloc = document.getElementById("tp1")
// oparent = oloc.parentNode() !!BAD
// GM_log(oloc.innerHTML);
// now insert and handle script on/off button
var osam=document.createElement("p");
osam.setAttribute("id", "samspot" );
if (run_flag == 0)
{
osam.innerHTML='<input type="checkbox" onclick="nrun();"
checked="false">';
}
else
{
osam.innerHTML='<input type="checkbox" onclick="nrun();"
checked="true">';
}
item = document.getElementById("side_info")
if ( item != null )
{
item.appendChild(osam);
}
else
{
document.body.appendChild( osam );
}
// GM_log( document.nrun )
if ( run_flag == 0 )
{
return
}
page_data = read_page()
obj1 = { method:"POST", url:"http://192.168.0.6:7777/info",
headers:{
"User-Agent":"monkeyagent",
"Accept":"text/monkey,text/xml",
"Content-type":"application/x-www-form-urlencoded" },
data: page_data ,
onload: response_handler };
GM_xmlhttpRequest( obj1 )
setTimeout( fetch_command, 1500 )
}
function read_page()
{
var vill_htm = "";
var page_contents = location.hostname + "\r\n";
var i = 0;
var x1 = 0;
page_contents = page_contents + "Current Page: " +
location.href + "\r\n"
if ( raw == true )
{
// GM_log( document.getElementsByTagName("head")[0].innerHTML
+ "\r\n" )
n1 = document.body;
s1 = location.href;
pos1 = s1.indexOf( 'travian' );
s1 = s1.slice( pos1 );
pos1 = s1.indexOf( '/' ) + 1;
cur_page = s1.slice( pos1);
pos1 = cur_page.indexOf( '?' );
if ( pos1 != -1 )
{
cur_page = cur_page.slice( 0, pos1 )
}
page_contents = page_contents + "\r\n";
GM_log( page_contents );
page_contents = page_contents + n1.innerHTML;
}
else
{
s1 = location.href;
}
return( page_contents )
}
function get_server_time(time_htm)
{
// var str_htm = document.getElementById('tp1').innerHTM;
var result = ""
strin1 = "Server time:"
// var obj1= obj.childNodes().innerHTM;
// var spos = obj.indexOf( "Server time: ")
// var epos = obj.indexOf( "</span>"
result = result.concat( time_htm )
result = result.concat( "\r\n" )
return result;
}
if (document.body)
{
// if DOM.location.hostname == "http://s8.trunameavian.us/dorf1.php
main();
}
</code>
problem with calling a global function as onclick handler ( for radio
button ).
The error says: "nrun is not defined"
In desperation I have tried to prepend "this." and "namespace."
but can't figure it out.
Although I am not going to call this one function from elsewhere,
I'd rather not paste the whole text of the function in the onclick quotes.
Thanks in advance.
<code>
// ==UserScript==
// @name page reader greasemonkey script
// @author Sambo
// @description insert some text on some page
// @include http://olg.ca/*
// @namespace sams_cluster
// @email (e-mail address removed)
// @version 0.1
// ==/UserScript==
var SCRIPT = {
url : 'file:///home/public/devel/linux/js/greasemonkey/sams_first.user.js',
version : '0.1' //same value as @version
};
//set global variables
var server = location.hostname;
var rootPath = "http://" + server + "/";
//var lang = new Array();
//var dom = new DOMUtils();
var raw = true;
var command_done = false;
var commands = ""
function response_handler(responseDetails)
{
GM_log(responseDetails.responseText);
}
function command_handler(responseDetails)
{
GM_log(responseDetails.responseText);
}
function fetch_command()
{
GM_log( "sfetch_command")
obj1 = { method:"GET",
url:"http://192.168.0.6:7777/command/"+location.host,
headers:{
"User-Agent":"monkeyagent",
"Accept":"text/monkey,text/xml",
"Content-type":"application/x-www-form-urlencoded" },
onload: command_handler };
GM_xmlhttpRequest( obj1 )
command_done = true;
}
function nrun()
{
GM_log("clicked");
run_flag = GM_getValue( "Rum_sams_reader", -1 )
item = document.getElementById("samspot").firstChild
if ( run_flag==0 )
{
run_flag = 1;
GM_setValue( "Rum_sams_reader", 1 )
item.checked=true
return( "True?" )
}
else
{
run_flag = 0;
GM_setValue( "Rum_sams_reader", 0 )
item.checked=false
return( "False?" )
}
}
function main()
{
run_flag = GM_getValue( "Rum_reader", -1 )
oloc = document.getElementById("tp1")
// oparent = oloc.parentNode() !!BAD
// GM_log(oloc.innerHTML);
// now insert and handle script on/off button
var osam=document.createElement("p");
osam.setAttribute("id", "samspot" );
if (run_flag == 0)
{
osam.innerHTML='<input type="checkbox" onclick="nrun();"
checked="false">';
}
else
{
osam.innerHTML='<input type="checkbox" onclick="nrun();"
checked="true">';
}
item = document.getElementById("side_info")
if ( item != null )
{
item.appendChild(osam);
}
else
{
document.body.appendChild( osam );
}
// GM_log( document.nrun )
if ( run_flag == 0 )
{
return
}
page_data = read_page()
obj1 = { method:"POST", url:"http://192.168.0.6:7777/info",
headers:{
"User-Agent":"monkeyagent",
"Accept":"text/monkey,text/xml",
"Content-type":"application/x-www-form-urlencoded" },
data: page_data ,
onload: response_handler };
GM_xmlhttpRequest( obj1 )
setTimeout( fetch_command, 1500 )
}
function read_page()
{
var vill_htm = "";
var page_contents = location.hostname + "\r\n";
var i = 0;
var x1 = 0;
page_contents = page_contents + "Current Page: " +
location.href + "\r\n"
if ( raw == true )
{
// GM_log( document.getElementsByTagName("head")[0].innerHTML
+ "\r\n" )
n1 = document.body;
s1 = location.href;
pos1 = s1.indexOf( 'travian' );
s1 = s1.slice( pos1 );
pos1 = s1.indexOf( '/' ) + 1;
cur_page = s1.slice( pos1);
pos1 = cur_page.indexOf( '?' );
if ( pos1 != -1 )
{
cur_page = cur_page.slice( 0, pos1 )
}
page_contents = page_contents + "\r\n";
GM_log( page_contents );
page_contents = page_contents + n1.innerHTML;
}
else
{
s1 = location.href;
}
return( page_contents )
}
function get_server_time(time_htm)
{
// var str_htm = document.getElementById('tp1').innerHTM;
var result = ""
strin1 = "Server time:"
// var obj1= obj.childNodes().innerHTM;
// var spos = obj.indexOf( "Server time: ")
// var epos = obj.indexOf( "</span>"
result = result.concat( time_htm )
result = result.concat( "\r\n" )
return result;
}
if (document.body)
{
// if DOM.location.hostname == "http://s8.trunameavian.us/dorf1.php
main();
}
</code>