aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-04-07 19:40:24 +0200
committerMatěj Cepl <mcepl@redhat.com>2011-06-05 14:44:01 +0200
commit67ab098bf0ad332c651e79919f728e4f276ed918 (patch)
treef722fc8d280aa05df5666668da64c1f6628a2947
parentd0eb80db9a8839dabe0a9c24fdab38bdd66c97dd (diff)
downloadbugzilla-triage-67ab098bf0ad332c651e79919f728e4f276ed918.tar.gz
Don't create new elements, just add relational <link>s.
-rw-r--r--data/lib/jumpNextBug.js54
-rw-r--r--lib/main.js2
2 files changed, 44 insertions, 12 deletions
diff --git a/data/lib/jumpNextBug.js b/data/lib/jumpNextBug.js
index af0ff39..8f64b0d 100644
--- a/data/lib/jumpNextBug.js
+++ b/data/lib/jumpNextBug.js
@@ -1,15 +1,47 @@
// 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);
-});
-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.log("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/lib/main.js b/lib/main.js
index 80144cc..f3de753 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -114,8 +114,8 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms
var contentScriptLibraries = [
self.data.url('lib/urltest.js'),
- self.data.url("lib/jumpNextBug.js"),
self.data.url("lib/util.js"),
+ self.data.url("lib/jumpNextBug.js"),
self.data.url("lib/queries.js"),
self.data.url("lib/preprocessDuplicates.js"),
self.data.url("lib/viewSource.js"),