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>
17
// Based on http://userscripts.org/scripts/show/15637
19
function xpath(query, context) {
20
context = context ? context : document;
21
return document.evaluate(query, context, null,
22
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
27
// Regex of words to highlight : color to highlight them (hint don't use black!)
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
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 ')" +
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];