In my first experimentation with js, I'm writing a greasemonkey script
which adds links to a page which, when clicked, will replace their
parent element with the contents of an element from another URL.
in the following function, pageHTML contains the entire text of an HTML
page, pulled in via GM_xmlhttpreque st. The page contains a ul with
id="commentlist ing". What I want to do, but can't seem to do, is turn
that lump of html in the pageHTML variable into a document that I can
run document.evalua te and document.getEle mentById on, just like I can
on the original page.
The second catch below alerts me with "TypeError:
tempnode.getEle mentById is not a function"
function getExpandedHTML (oldid, pageHTML)
{
GM_log("getExpa nded started");
var tempNode;
try {
tempnode = document.create Element("docume nt");
tempnode.innerH TML = pageHTML;
}
catch (e)
{
alert(e);
}
var listnode;
try {
listnode = tempnode.getEle mentById("comme ntlisting");
} catch (e)
{
alert(e);
}
//var innerlinks = listnode.evalua te("//a[@href]", listnode,
null, XPathResult.UNO RDERED_NODE_SNA PSHOT_TYPE, null);
//addlinkevenets( oldid, innerlinks);
GM_log("getExpa nded finished");
return listnode.innerH TML;
}
which adds links to a page which, when clicked, will replace their
parent element with the contents of an element from another URL.
in the following function, pageHTML contains the entire text of an HTML
page, pulled in via GM_xmlhttpreque st. The page contains a ul with
id="commentlist ing". What I want to do, but can't seem to do, is turn
that lump of html in the pageHTML variable into a document that I can
run document.evalua te and document.getEle mentById on, just like I can
on the original page.
The second catch below alerts me with "TypeError:
tempnode.getEle mentById is not a function"
function getExpandedHTML (oldid, pageHTML)
{
GM_log("getExpa nded started");
var tempNode;
try {
tempnode = document.create Element("docume nt");
tempnode.innerH TML = pageHTML;
}
catch (e)
{
alert(e);
}
var listnode;
try {
listnode = tempnode.getEle mentById("comme ntlisting");
} catch (e)
{
alert(e);
}
//var innerlinks = listnode.evalua te("//a[@href]", listnode,
null, XPathResult.UNO RDERED_NODE_SNA PSHOT_TYPE, null);
//addlinkevenets( oldid, innerlinks);
GM_log("getExpa nded finished");
return listnode.innerH TML;
}
Comment