I have this html code in a page
<tr class="tt_row">
<td class="ttr_type"><a href="?cat=17"><img src="/pic/abc-aaa-bb.png" alt="aa/bb-cccc" /></a></td>
<td class="ttr_name"><a href="abc?id=2221" title="Test.2123.123"><b>Test.2123.123</b></a><br /><span class="pre">Test test</span> <span class="newtag">NEW!</span></td>
<td class="td_dl"><a href="upload/222083/1348hgfhfchf5675675/Test.2123.123"><img src="/pic/aaab.gif" style="vertical-align: middle;" alt="Upload" /></a></td>
<td class="ttr_size">1.65 MB<br /><a class="small" href="abc?id=2221&filelist=1#filelist">15 Files</a></td>
<td class="ttr_comments">0</td>
<td class="ttr_added">2014-03-03<br />11:11:11</td>
<td class="ttr_snatched">0<br />times</td>
<td class="ttr_seeders"><b><a href="abc?id=2221&peers=1#seeders">0</a></b></td>
<td class="ttr_leechers">0</td>
</tr>
And this script with Greasemonkey
function initMenu(aEvent) {
// Executed when user right click on web page body
// aEvent.target is the element you right click on
var node = aEvent.target.parentNode;
var node1 = aEvent.target;
var item = document.querySelector("#userscript-search-by-image menuitem");
if (node.localName == "a") {
if (node1.getAttribute("src") == "/pic/aaab.gif") { // ABV
body.setAttribute("contextmenu", "userscript-search-by-image");
item.setAttribute("imageURL", node.href);
}
This script modifies the contextual menu with a new entry when i right click on
<img src="/pic/aaab.gif" style="vertical-align: middle;" alt="Upload" />
and with parentNode i go to
<a href="upload/222083/1348hgfhfchf5675675/Test.2123.123">
and save href with
item.setAttribute("imageURL", node.href);
What i can't do is to save alt from
<img src="/pic/abc-aaa-bb.png" alt="aa/bb-cccc" />
I tried
node3 = node.parentNode.parentNode.firstChild.firstChild.firstChild
to get to
<img src="/pic/abc-aaa-bb.png" alt="aa/bb-cccc" />
and
item.setAttribute("imageALT", node3.alt);
What should i do? I'm new to javascript and DOM.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…