~minos-archive/minos/firefox-minos-settings

« back to all changes in this revision

Viewing changes to firefox27/firefox/h5xyzl6e.default/gm_scripts/LP_WordHighlighter-2/lp_highlight_words.user.js

  • Committer: Javier Lopez
  • Date: 2015-07-08 01:10:19 UTC
  • Revision ID: git-v1:d8c3500bae00a8a67d74f8f96235ec11d75231be
rename mozilla-minos-settings -> firefox-minos-settings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ==UserScript==
 
2
// @name           LP_WordHighlighter
 
3
// @namespace      http://murraytwins.com/greasemonkey/
 
4
// @description    Highlight keywords in bug pages
 
5
// @exclude        https://launchpad.net/*/+bug/*/+edit
 
6
// @exclude        https://launchpad.net/*/+bug/*/+nominate
 
7
// @exclude        https://*.launchpad.net/*/+bug/*/+edit
 
8
// @exclude        https://*.launchpad.net/*/+bug/*/+nominate
 
9
// @exclude        https://*.edge.launchpad.net/*/+bug/*/+edit
 
10
// @exclude        https://*.edge.launchpad.net/*/+bug/*/+nominate
 
11
// @include        https://launchpad.net/*/+bug/*
 
12
// @include        https://*.launchpad.net/*/+bug/*
 
13
// @include        https://*.edge.launchpad.net/*/+bug/*
 
14
// @creator        Brian Murray <brian@ubuntu.com>
 
15
// 
 
16
// ==/UserScript==
 
17
// Based on http://userscripts.org/scripts/show/15637
 
18
 
 
19
function xpath(query, context) {
 
20
  context = context ? context : document;
 
21
  return document.evaluate(query, context, null,
 
22
                           XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
 
23
}
 
24
 
 
25
(function()
 
26
{
 
27
    // Regex of words to highlight : color to highlight them (hint don't use black!)
 
28
    var color_map = {
 
29
        'DistroRelease: [^ ]+ [^ ]+|SourcePackage: [^ ]+|LiveMediaBuild:|oneiric|natty|maverick|lucid|hardy|dapper': "yellow",  // things that might be helpful
 
30
        'regression': "red", // critical importance
 
31
        'karmic|jaunty|intrepid|gutsy|feisty|edgy|breezy|hoary|warty': "orange", // unsupported releases
 
32
    }; 
 
33
 
 
34
    for (var key in color_map) {
 
35
        var search = '(.*?)('+key+')(.*)';
 
36
        var regex = new RegExp(search,'i');
 
37
        // Get all text nodes below elements with class report or boardComment
 
38
        var text = xpath("//*[@id = 'edit-description' or (@class and " +
 
39
            "contains(concat(' ', normalize-space(@class), ' '), ' boardComment ')" +
 
40
            ")]//text()");
 
41
 
 
42
        for (var i = 0; i < text.snapshotLength; i++) {
 
43
            var texti = text.snapshotItem(i);
 
44
            var textiparent = texti.parentNode;
 
45
            while ( (match = regex.exec(texti.textContent)) != null ) {
 
46
                // split texti up into parts
 
47
                span = document.createElement("span");
 
48
                span.style.background = color_map[key];
 
49
                span.style.color = "black";
 
50
                span.textContent = match[2];
 
51
                // Insert the colored match
 
52
                textiparent.insertBefore(span, texti);
 
53
                // Insert the text preceeding the match
 
54
                beforeText = document.createTextNode(match[1]);
 
55
                textiparent.insertBefore(beforeText, span);
 
56
                // The remaining text after the match
 
57
                texti.textContent = match[3];
 
58
            }
 
59
        }
 
60
    }
 
61
})();