Skip to content

Commit 8c23bb8

Browse files
committed
Update style of links to match original font colour, and underline to make noticeable
1 parent 2d5eb25 commit 8c23bb8

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ https://github.com/raggleton/github-linkify-cmssw/releases/latest
1212

1313
3) Drag and drop the `github-linkify-cmssw.crx` package onto the window. Click OK when it asks permission to access github.com. This should install it.
1414

15-
## TODO
16-
- [ ] keep the colour of the links to their original colour
17-
1815
Maybe I'll do a Firefox equivalent some day. If I ever get this one done.
1916

2017
Robin Aggleton 2014

contentscript.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,25 @@ for (var i = 0; i < rows.length; i++) {
3939
path = path.replace(/[<>\"]/g,""); //g inmportant - global so replaces all instances
4040
var link = rootURL.concat(path);
4141

42+
// get color of original text by getting class name of <span> or <td> tag that houses it,
43+
// then ask style sheet for color attribute for that class
44+
var header_class = "";
45+
for (var k = 0; k < cell.childNodes.length; k++) {
46+
if (cell.childNodes[k].textContent.indexOf(path) != -1) {
47+
header_class = cell.childNodes[k].className;
48+
}
49+
}
50+
if (!header_class){
51+
header_class = cell.className.split(" ")[0];
52+
}
53+
54+
var color = window.getComputedStyle(document.querySelector("."+header_class)).getPropertyValue("color");
55+
4256
// let's replace the text with a link
43-
// TODO keep same styling as before
44-
cell.innerHTML = cell.innerHTML.replace(path, "<a href=\""+link+"\">"+path+"</a>");
45-
// for (var k = 0; k < cell.childNodes.length; k++) {
46-
// if (cell.childNodes[k].textContent.indexOf(path) != -1) {
47-
// var cell_html = cell.childNodes[k].innerHTML;
48-
// }
49-
// }
57+
// keep same colour as before, but underline it to make it noticeable for user
58+
cell.innerHTML = cell.innerHTML.replace(path, "<a href=\""+link+"\" style=\"text-decoration:underline;color:"+color+"\">"+path+"</a>"); // <font color=\"#df5000\">
5059
}
60+
5161
// tests for python imports/fragments
5262
var config = "";
5363
if (py_pattern1.test(line)) {
@@ -72,10 +82,23 @@ for (var i = 0; i < rows.length; i++) {
7282
path = path.replace(parts[parts.length-1],"python/"+parts[parts.length-1]+".py")
7383
var link = rootURL.concat(path)
7484

85+
// get color of original text by getting class name of <span> or <td> tag that houses it,
86+
// then ask style sheet for color attribute for that class
87+
// should probably put this as a function since we do the same for py and c++
88+
var header_class = "";
89+
for (var k = 0; k < cell.childNodes.length; k++) {
90+
if (cell.childNodes[k].textContent.indexOf(config) != -1) {
91+
header_class = cell.childNodes[k].className;
92+
}
93+
}
94+
if (!header_class){
95+
header_class = cell.className.split(" ")[0];
96+
}
97+
var color = window.getComputedStyle(document.querySelector("."+header_class)).getPropertyValue("color");
98+
7599
// let's replace the text with a link
76-
// TODO keep same styling as before
77-
var cell_html = cell.innerHTML;
78-
cell.innerHTML = cell_html.replace(config, "<a href=\""+link+"\">"+config+"</a>");
100+
// keep same colour as before, but underline it to make it noticeable for user
101+
cell.innerHTML = cell.innerHTML.replace(config, "<a href=\""+link+"\" style=\"text-decoration:underline;color:"+color+"\">"+config+"</a>");
79102
}
80103
}
81104
}

0 commit comments

Comments
 (0)