Improving bugzilla and hitting the wall

M

matej

I am trying to write new GM script after couple of months of not
working with Firefox at all, and I am hitting the wall even with the
simplest preliminary steps to it. What I would like to achieve is to
add key shortcut for setting status of the bug to NEEDINFO and
information required from the reporter (which is like 75 % of bugs I
manage). For that I would like to add new <A> element to the end of the
bottom button bar (see e.g.
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=212188 which is
the bug where I am testing my script) just behind the words "Format for
printing" with acceskey and event listener calling function in the
script.

However, just the preliminary attempts to add simple text node and an
empty element are miserably failing and I cannot find why (JavaScript
console is silent):

// Some embellishments to RH Bugzilla
// version 0.1 ALPHA!
// 2006-01-02
// Copyright (c) 2006, Matěj Cepl
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
//
// ==UserScript==
// @name Bugzilla Improved
// @namespace http://www.ceplovi.cz/matej/progs/scripts
// @description some embellishments for RH Bugzilla
// @include
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=*
// ==/UserScript==

//function needInfoReporter(event) {
// alert("Event happened!");
// event.preventDefault();
// return false;
//}

//var StatusSelectTag = document.getElementsByName("newstatus");

//id('navigate')/table/tbody/tr/td[2]/a[3]

//var buttonTab = document.evaluate(
// '//div[@id="navigate"]//td[@align="right"]',
// document.body,
// null,
// XPathResult.ANY_UNORDERED_NODE_TYPE,
// null);
var buttonTab =
document.getElementById("navigate").getElementsByTagName("TD")[1];

var delimiterNode = document.createTextNode("&nbsp;|&nbsp;");
//var newNode = document.createElement("a");
//var newNodeText = document.createTextNode("NEEDINFO from reporter");
//newNode.appendChild(newNodeText);
//newNode.accessKey = "R";
//newNode.addEventListener('click', needInfoReporter, false);

//if (buttonTab.lastChild.nodeType==3) {
buttonTab.replaceChild(delimiterNode,buttonTab.lastChild);
//};
//buttonTab.appendChild(delimiterNode);
//buttonTab.appendChild(newNode);

--------------------------------------------------------------------------------

Any idea what's going on, please?

Thanks a lot,

Matěj
 
M

Martin Honnen

matej said:
I am trying to write new GM script after couple of months of not
working with Firefox at all, and I am hitting the wall even with the
simplest preliminary steps to it. What I would like to achieve is to
add key shortcut for setting status of the bug to NEEDINFO and
information required from the reporter (which is like 75 % of bugs I
manage). For that I would like to add new <A> element to the end of the
bottom button bar (see e.g.
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=212188 which is
the bug where I am testing my script) just behind the words "Format for
printing" with acceskey and event listener calling function in the
script.
var buttonTab =
document.getElementById("navigate").getElementsByTagName("TD")[1];

There is only one cell in that table in the div id="navigate" element so
to find that cell you need e.g.

var buttonTab =
document.getElementById("navigate").getElementsByTagName("TD")[0];

I don't remember for sure however whether Greasemonkey script accessing
the DOM of the page need to be run in a load event listener. You might
want to try to put your code accessing those elements and adding stuff
in a load event listener.
var delimiterNode = document.createTextNode("&nbsp;|&nbsp;");

createTextNode expects plain text not HTML markup (and character/entity
references like &nbsp; are markup) so you need e.g.
buttonTab.appendChild(document.createTextNode('\u00A0|\u00A0'));
to insert those characters as a text node in the cell.
 
M

matej

There is only one cell in that table in the div id="navigate" element so
to find that cell you need e.g.

either I am blind of stupid, but I see two TD elements on page
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=212188 -- one
with align="left" and other with align="right". Moreover, I have tested
existence of the second cell with alert(buttonTab.nodeType);
I don't remember for sure however whether Greasemonkey script accessing
the DOM of the page need to be run in a load event listener. You might
want to try to put your code accessing those elements and adding stuff
in a load event listener.

Do you have any examples of such listener?
references like &nbsp; are markup) so you need e.g.
buttonTab.appendChild(document.createTextNode('\u00A0|\u00A0'));
to insert those characters as a text node in the cell.

Hmm, tried that (I use replaceChild, because the lastChild of buttonTab
is apparently textNode):

var delimiterNode = document.createTextNode('\u00A0|\u00A0');
buttonTab.replaceChild(delimiterNode,buttonTab.lastChild);

but still no difference on the page and no message in the Javascript
console.

Any more ideas, please? Thanks for the response so far.

Matěj
 
M

Martin Honnen

matej said:
Do you have any examples of such listener?

function loadHandler (evt) {
// put code here to run once the document has been loaded
}

window.addEventListener('load', loadHandler, false);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top