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

« back to all changes in this revision

Viewing changes to firefox27/firefox/h5xyzl6e.default/gm_scripts/LP_Highlight_Me/lp_highlight_me.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_Highlight_Me
 
3
// @namespace      https://launchpad.net/launchpad-gm-scripts
 
4
// @description    Highlight the logged in user in various listings.
 
5
// @include        https://launchpad.net/*/+milestone/*
 
6
// @include        https://*.launchpad.net/*/+milestone/*
 
7
// @include        https://*.edge.launchpad.net/*/+milestone/*
 
8
// @version        0.1.2
 
9
// @date           2008-01-25
 
10
// @creator        Gavin Panella <gavin@gromper.net>
 
11
// ==/UserScript==
 
12
//
 
13
// Features:
 
14
//
 
15
//   1. Highlight rows on milestone pages that contain the logged-in
 
16
//   users name.
 
17
//
 
18
 
 
19
 
 
20
function addGlobalStyle(css) {
 
21
    var head = document.getElementsByTagName('head')[0];
 
22
    if (head) {
 
23
        var style = document.createElement('style');
 
24
        style.type = 'text/css';
 
25
        style.innerHTML = css;
 
26
        head.appendChild(style);
 
27
    }
 
28
}
 
29
 
 
30
function findParent(element, tagName) {
 
31
    // Find a parent element matching tagName, which should probably
 
32
    // be all capitals.
 
33
    var parent = element.parentNode;
 
34
    return (parent == null || parent.tagName == tagName) ?
 
35
        parent : arguments.callee(parent, tagName);
 
36
}
 
37
 
 
38
function getLoggedInUserLink() {
 
39
    // Returns the lp username of the logged-in user.
 
40
    var forms = document.getElementsByTagName('form');
 
41
    for (var i = 0; i < forms.length; i++) {
 
42
        var form = forms[i];
 
43
        if (form.action.match(/[/][+]logout$/)) {
 
44
            href = form.getElementsByTagName('a')[0].href;
 
45
            if (debug) {
 
46
                GM_log("User href: "+href);
 
47
            }
 
48
            return href.split('~')[1];
 
49
        }
 
50
    }
 
51
}
 
52
 
 
53
function highlightMilestoneRows() {
 
54
    // Highlight rows for specs and bugs that are assigned to the
 
55
    // logged-in user.
 
56
    var user = getLoggedInUserLink();
 
57
    if (debug) {
 
58
        GM_log("User: "+user);
 
59
    }
 
60
    if (user == null) {
 
61
        return;
 
62
    }
 
63
 
 
64
    addGlobalStyle(
 
65
        'tr.highlight-for-user td { background-color: #ffcc56; }');
 
66
 
 
67
    var highlight = function(table) {
 
68
        if (table == null) return;
 
69
        var links = table.getElementsByTagName('a');
 
70
        var count = 0;
 
71
        for (var i = 0; i < links.length; i++) {
 
72
            var link = links[i];
 
73
            var link_user = link.href.split('~')[1];
 
74
            //if (debug) {
 
75
            //    GM_log("Link found: "+link);
 
76
            //}
 
77
            if ( String(link_user) == String(user) ) {
 
78
                if (debug) {
 
79
                    GM_log("Found a match!")
 
80
                }
 
81
                var row = findParent(link, 'TR');
 
82
                if (row) {
 
83
                    if (row.className) {
 
84
                        row.className += ' highlight-for-user';
 
85
                    }
 
86
                    else {
 
87
                        row.className = 'highlight-for-user';
 
88
                    }
 
89
                    count += 1;
 
90
                }
 
91
            }
 
92
        }
 
93
        return count;
 
94
    };
 
95
 
 
96
    var spec_count = highlight(document.getElementById('milestone_specs'));
 
97
    var spec_header = document.getElementById("specification-count");
 
98
    spec_header.innerHTML += ' - ' + spec_count + ' assigned to you';
 
99
 
 
100
    var bug_count = highlight(document.getElementById('milestone_bugtasks'));
 
101
    var bug_header = document.getElementById("bug-count");
 
102
    bug_header.innerHTML += ' - ' + bug_count + ' assigned to you';
 
103
}
 
104
 
 
105
var debug = 0;
 
106
 
 
107
var location = document.location.href;
 
108
 
 
109
if (location.indexOf('/+milestone/') >= 0) {
 
110
    // Milestone page
 
111
    highlightMilestoneRows();
 
112
}
 
113
 
 
114
 
 
115
 
 
116
 
 
117
// End