diff options
Diffstat (limited to 'data/lib')
-rw-r--r-- | data/lib/bugzillaDOMFunctions.js | 66 | ||||
-rw-r--r-- | data/lib/jumpNextBug.js | 62 | ||||
-rw-r--r-- | data/lib/queries.js | 6 |
3 files changed, 119 insertions, 15 deletions
diff --git a/data/lib/bugzillaDOMFunctions.js b/data/lib/bugzillaDOMFunctions.js index 98a2031..aedf131 100644 --- a/data/lib/bugzillaDOMFunctions.js +++ b/data/lib/bugzillaDOMFunctions.js @@ -283,6 +283,72 @@ function getProduct() { return null; } +function commentsWalker (fce) { + var comments = document.getElementById("comments"). + getElementsByClassName("bz_comment"); + Array.forEach(comments, function(item) { + fce(item); + }); +} + + +/** + * Parse the row with the attachment + * + * @param DOM + * element to be parsed + * @return array with string name of the attachment, integer its id number, + * string of MIME type, integer of size in kilobytes, and the whole + * element itself + * + * TODO error handling is missing ... it's bleee + */ +function parseAttachmentLine(inElem) { + var MIMEtype = ""; + var size = 0; + + // Skip over obsolete attachments + if (inElem.getElementsByClassName("bz_obsolete").length > 0) { + return ([]); + } + + // getting name of the attachment + var attName = inElem.getElementsByTagName("b")[0].textContent.trim(); + + // TODO probably could use url.URL object + var aHrefsArr = inElem.getElementsByTagName("a"); + var aHref = Array.filter(aHrefsArr, function(x) { + return x.textContent.trim() === "Details"; + })[0]; + var id = parseURL(aHref.getAttribute("href")).params.id; + + // getting MIME type and size + var stringArray = inElem.getElementsByClassName("bz_attach_extra_info")[0].textContent. + replace(/[\n ()]+/g, " ").trim().split(", "); + size = parseInt(stringArray[0], 10); + MIMEtype = stringArray[1].split(" ")[0]; + + return [ attName, id, MIMEtype, size, inElem ]; +} + + +/** + * collect the list of attachments in a structured format + * + * @return Array of arrays, one for each attachments; each record has string + * name of the attachment, integer its id number, string of MIME type, + * integer of size in kilobytes, and the whole element itself + */ +function getAttachments () { + var outAtts = []; + var atts = document.getElementById("attachment_table"). + getElementsByTagName("tr"); + for ( var i = 1, ii = atts.length - 1; i < ii; i++) { + outAtts.push(parseAttachmentLine(atts[i])); + } + return outAtts; +} + /** * Get login of the currently logged-in user. * diff --git a/data/lib/jumpNextBug.js b/data/lib/jumpNextBug.js index 68e719b..b777fe8 100644 --- a/data/lib/jumpNextBug.js +++ b/data/lib/jumpNextBug.js @@ -1,16 +1,54 @@ // Released under the MIT/X11 license // http://www.opensource.org/licenses/mit-license.php "use strict"; -var nextElement = {}; -var nextRE = new RegExp("Next"); -var aNavigElements = document.querySelectorAll("#bugzilla-body .navigation a"); -var filteredElements = Array.filter(aNavigElements, function(elem) { - return nextRE.test(elem.textContent); -}); -console.log("filteredElements.length = " + filteredElements.length); -if (filteredElements.length > 0) { - nextElement = filteredElements[0]; - nextElement.setAttribute("accesskey", "n"); - nextElement.innerHTML = "<u>N</u>ext"; -} +(function createRelationElements() { + var relation = {}; + var linkLabels = [ + "First", "Last", "Prev", "Next" + ]; + var labelToRelation = { + "First" : { + rel : "start" + }, + "Last" : { + rel : "last" + }, + "Prev" : { + rel : "prev" + }, + "Next" : { + rel : "next" + } + }; + + function createLinkRel(rel, href) { + var newLinkElement = document.createElement("link"); + newLinkElement.setAttribute("rel", rel); + newLinkElement.setAttribute("href", href); + document.getElementsByTagName("head")[0] + .appendChild(newLinkElement); + } + + var aNavigElements = document + .querySelectorAll("#bugzilla-body .navigation a"); + Array.forEach(aNavigElements, function(elem) { + var labelText = elem.textContent.trim(); + if (isInList(labelText, linkLabels)) { + labelToRelation[labelText].href = elem + .getAttribute("href"); + } + ; + }); + console.myDebug("labelToRelation = " + + labelToRelation.toSource()); + + for ( var key in labelToRelation) { + if (labelToRelation.hasOwnProperty(key)) { + relation = labelToRelation[key]; + if (relation.href) { + createLinkRel(relation.rel, relation.href); + } + } + } +})(); diff --git a/data/lib/queries.js b/data/lib/queries.js index 066991e..ccb2927 100644 --- a/data/lib/queries.js +++ b/data/lib/queries.js @@ -2,7 +2,7 @@ // http://www.opensource.org/licenses/mit-license.php "use strict"; -function getSelection() { +function getSel() { var text = ""; var selectionObject = window.getSelection(); if (selectionObject.rangeCount > 0) { @@ -64,7 +64,7 @@ function queryInNewTab(text, component, product, equivComps) { * function this.queryInNewTab, and run it. */ function queryForSelection() { - var text = getSelection(); + var text = getSel(); if (!text) { self.postMessage(new Message("GetClipboard", "queryLocal")); } @@ -107,7 +107,7 @@ function queryUpstream(qUpBug) { alert("We don't have constantData.queryUpstreamBug set up!"); return null; } - var text = getSelection(); + var text = getSel(); if (!text) { self .postMessage(new Message("GetClipboard", "queryUpstream")); |