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/*
10
// @creator Gavin Panella <gavin@gromper.net>
15
// 1. Highlight rows on milestone pages that contain the logged-in
20
function addGlobalStyle(css) {
21
var head = document.getElementsByTagName('head')[0];
23
var style = document.createElement('style');
24
style.type = 'text/css';
25
style.innerHTML = css;
26
head.appendChild(style);
30
function findParent(element, tagName) {
31
// Find a parent element matching tagName, which should probably
33
var parent = element.parentNode;
34
return (parent == null || parent.tagName == tagName) ?
35
parent : arguments.callee(parent, tagName);
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++) {
43
if (form.action.match(/[/][+]logout$/)) {
44
href = form.getElementsByTagName('a')[0].href;
46
GM_log("User href: "+href);
48
return href.split('~')[1];
53
function highlightMilestoneRows() {
54
// Highlight rows for specs and bugs that are assigned to the
56
var user = getLoggedInUserLink();
58
GM_log("User: "+user);
65
'tr.highlight-for-user td { background-color: #ffcc56; }');
67
var highlight = function(table) {
68
if (table == null) return;
69
var links = table.getElementsByTagName('a');
71
for (var i = 0; i < links.length; i++) {
73
var link_user = link.href.split('~')[1];
75
// GM_log("Link found: "+link);
77
if ( String(link_user) == String(user) ) {
79
GM_log("Found a match!")
81
var row = findParent(link, 'TR');
84
row.className += ' highlight-for-user';
87
row.className = 'highlight-for-user';
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';
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';
107
var location = document.location.href;
109
if (location.indexOf('/+milestone/') >= 0) {
111
highlightMilestoneRows();