aboutsummaryrefslogtreecommitdiffstats
path: root/data/lib/jumpNextBug.js
blob: b777fe8575cf7b313c5abb4e1034dd34b5f3fb42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
"use strict";

(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);
      }
    }
  }
})();