From 9b3f22fd07c0cfcc1e2368c7f32a0423a3a4bd85 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Fri, 23 Jul 2010 21:33:08 +0200 Subject: More resistance to differences with bugzilla.mozilla.org Fixes #30 --- lib/bzpage.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'lib/bzpage.js') diff --git a/lib/bzpage.js b/lib/bzpage.js index ff84aa9..084b924 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -477,6 +477,22 @@ BZPage.prototype.setConfigurationButton = function setConfigurationButton () { }, false); }; +/* + * From element diggs out just plain email + * address + * + * @param aElement Element with href attribute or something else + * @return String with the address or null + * + */ +BZPage.prototype.parseMailto = function parseMailto(aElement) { + if (aElement) { + var email = decodeURI(aElement.getAttribute("href")). + split(":")[1]; + } + return null; +}; + /** * Get the current email of the reporter of the bug. * @@ -485,10 +501,7 @@ BZPage.prototype.setConfigurationButton = function setConfigurationButton () { BZPage.prototype.getReporter = function getReporter () { var reporterElement = this.doc. querySelector("#bz_show_bug_column_2 > table .vcard:first-of-type > a"); - if (reporterElement) { - return reporterElement.textContent; - } - return ""; + return this.parseMailto(reporterElement); }; /** @@ -523,8 +536,8 @@ BZPage.prototype.commentsWalker = function commentsWalker (fce) { BZPage.prototype.checkComments = function checkComments () { var that = this; this.commentsWalker(function(x) { - var email = x.getElementsByClassName("vcard")[0] - .getElementsByTagName("a")[0].textContent; + var email = that.parseMailto(x.getElementsByClassName("vcard")[0] + .getElementsByTagName("a")[0]); if (new RegExp(that.reporter).test(email)) { x.style.backgroundColor = that.ReporterColor.toString(); } @@ -667,9 +680,7 @@ BZPage.prototype.getOwner = function getOwner () { var priorityParent = this.doc.querySelector("label[for~='target_milestone']") .parentNode.parentNode.parentNode; var assigneeAElement = priorityParent.querySelector("tr:nth-of-type(1) a.email"); - var assgineeHref = decodeURI(assigneeAElement.getAttribute("href")); - var email = assgineeHref.split(":")[1]; - return email; + return this.parseMailto(assigneeAElement); }; /** -- cgit