Greasy Fork

Shined up real nice.

Fix monorail/bugs.chromium.org issues lists

Make monorail/bugs.chromium.org issues lists use real hyperlinks.

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
55
56
57
58
59
60
61
// ==UserScript==
// @name           Fix monorail/bugs.chromium.org issues lists
// @description:en Make monorail/bugs.chromium.org issues lists use real hyperlinks.
// @namespace      monorail_issues_fix
// @include        https://bugs.chromium.org/*
// @version        1.1
// @grant          GM_addStyle
// @description Make monorail/bugs.chromium.org issues lists use real hyperlinks.
// ==/UserScript==

/**
 * Monorail has issues lists like https://bugs.chromium.org/p/chromium/issues/list
 * where clicks are handled not by real hyperlinks but by an atrocious click handler
 * that handles clicks for any mouse button.  This prevents you from being able to
 * right- or middle-click to open an issue in a new tab (except through the link
 * in the ID column).
 *
 * Disable the click handler, scan the issues table for the hyperlinks in the
 * ID column, then wrap each <td> with that hyperlink.
 */

function q(parent, selector) {
	return parent.querySelectorAll(selector);
}

function moveNodes(source, dest) {
	while (source.hasChildNodes()) {
		dest.appendChild(source.firstChild);
	}
}

function a_href(href) {
	const a = document.createElement("a");
	a.href = href;
	return a;
}

const tbody = q(document, "#resultstable > tbody")[0];
if (tbody) {
	// Attach to the child tbody instead of #resultstable because on the #resultstable
	// it looks like we have no way to suppress the existing click/mousedown handler.
	tbody.addEventListener("mousedown", (event) => event.stopImmediatePropagation(), false);
	tbody.addEventListener("click",     (event) => event.stopImmediatePropagation(), false);

	q(tbody, "tr").forEach((tr) => {
		const href = q(tr, "td.id > a")[0].href;
		q(tr, "td").forEach((td) => {
			const a = a_href(href);
			moveNodes(td, a);
			td.appendChild(a);
		});
	});
}

// Fix a strange issue (only with some fonts) with "----" in the M (milestone)
// column wrapping to two lines.
GM_addStyle(`
#resultstable td {
	padding-right: 0;
}
`);