A
Axel Bock
Hello all,
I am new to the whole JavaScript stuff, but I would likt to get in
with a little AJAX. XMLHttpRequest to be precise, for a Greasemonkey
script.
My idea: To enhance EVERY Google search result with maybe the digg
count for the story.
But it does not work - my main problem is that the callback function
only applies to the LAST element in the search results list, which is
kind of weird. So only the very last google search result on the page
is modified.
Can anyone help me maybe? The script code is below.
thanks in advance for any answers!
Axel.
<pre>
var godren = {
stories : "http://services.digg.com/stories",
appkey : "http://the-me.de/digg",
GetLinksWrapper : function(link, parent_element) {
rq = new XMLHttpRequest();
ln = link;
pe = parent_element;
cb = function() {
if (rq.readyState == 4) {
GM_log("response: " + rq.responseText);
GM_log("url: " + url);
GM_log("request status: " + rq.status)
pe.appendChild(document.createTextNode(" yuddi"));
}
};
var url = godren.stories
+ "?appkey=" + escape(godren.appkey)
+ "&link=" + escape(link)
+ "&type=json";
rq.open("GET", url, true);
rq.setRequestHeader("User-Agent", "God-Ren/1.0");
rq.onreadystatechange = cb;
rq.send();
},
get_link_for : function(result) {
return result.childNodes[0].toString();
},
find_google_results : function() {
// google result links are tag "h3" with class "r"
elements = document.getElementsByTagName("h3");
results = new Array();
for (var i=0; i<elements.length; i++) {
element = elements;
if (element.className=="r") results.push(element)
}
return results;
}
}
// main loop
results = godren.find_google_results();
for (var i=0; i<results.length; i++) {
result = results;
// prevent multiple insertions - maybe pagerization?
if (result.childNodes.length == 1) {
link = godren.get_link_for(result);
new godren.GetLinksWrapper(link, result);
}
}
</pre>
I am new to the whole JavaScript stuff, but I would likt to get in
with a little AJAX. XMLHttpRequest to be precise, for a Greasemonkey
script.
My idea: To enhance EVERY Google search result with maybe the digg
count for the story.
But it does not work - my main problem is that the callback function
only applies to the LAST element in the search results list, which is
kind of weird. So only the very last google search result on the page
is modified.
Can anyone help me maybe? The script code is below.
thanks in advance for any answers!
Axel.
<pre>
var godren = {
stories : "http://services.digg.com/stories",
appkey : "http://the-me.de/digg",
GetLinksWrapper : function(link, parent_element) {
rq = new XMLHttpRequest();
ln = link;
pe = parent_element;
cb = function() {
if (rq.readyState == 4) {
GM_log("response: " + rq.responseText);
GM_log("url: " + url);
GM_log("request status: " + rq.status)
pe.appendChild(document.createTextNode(" yuddi"));
}
};
var url = godren.stories
+ "?appkey=" + escape(godren.appkey)
+ "&link=" + escape(link)
+ "&type=json";
rq.open("GET", url, true);
rq.setRequestHeader("User-Agent", "God-Ren/1.0");
rq.onreadystatechange = cb;
rq.send();
},
get_link_for : function(result) {
return result.childNodes[0].toString();
},
find_google_results : function() {
// google result links are tag "h3" with class "r"
elements = document.getElementsByTagName("h3");
results = new Array();
for (var i=0; i<elements.length; i++) {
element = elements;
if (element.className=="r") results.push(element)
}
return results;
}
}
// main loop
results = godren.find_google_results();
for (var i=0; i<results.length; i++) {
result = results;
// prevent multiple insertions - maybe pagerization?
if (result.childNodes.length == 1) {
link = godren.get_link_for(result);
new godren.GetLinksWrapper(link, result);
}
}
</pre>