Skip to content

Commit 3a5ab2b

Browse files
committed
Make src file checker asynchronous to stop freezing
1 parent 37c80d2 commit 3a5ab2b

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@ Maybe I'll do a Firefox equivalent some day. If I ever get this one done.
4141
- or auto lookup - e.g. if #include "myEvent.h" link to same folder/myEvent.h, or #include "../myObj.h" link to ../myObj.h ?
4242
- options page? (keyboard shortcut, etc)
4343
- allow you to custom define where header files are?
44+
- if on a header page, add link to src file!
4445

4546
Robin Aggleton 2014

contentscript.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,19 @@ function test_py_import(line) {
6666

6767

6868
// test if URL exists
69-
// slow??
70-
function UrlExists(url) {
69+
// make sure it's asynchronous otherwise hangs!
70+
function check_URL_add_link(url, cell) {
7171
var http = new XMLHttpRequest();
72-
http.open('HEAD', url, false);
72+
http.open('HEAD', url);
73+
http.onreadystatechange = function() {
74+
if (this.readyState == 4) {
75+
if (this.status != 404) {
76+
var srcText = "&nbsp&nbsp&nbsp<a href=\""+url+"\" style=\"text-decoration:underline;\">[goto src]</a>";
77+
cell.innerHTML = cell.innerHTML.concat(srcText);
78+
}
79+
}
80+
};
7381
http.send();
74-
return http.status != 404;
7582
}
7683

7784

@@ -117,18 +124,20 @@ for (var i = 0; i < rows.length; ++i) {
117124
// we add in a tag to go to the src file instead
118125
// THIS ASSUMES THE FILE IS IN /src/ DIRECTORY
119126
// but what if it is in /plugins???
120-
// brutal way atm to tell if it's .cpp or .cc. Need github API here!
121127
var srcPath = link.replace("interface", "src");
122128
var cppSrc = srcPath.replace(".h", ".cpp");
123129
var ccSrc = srcPath.replace(".h", ".cc");
124-
if (UrlExists(cppSrc))
125-
srcPath = cppSrc;
126-
else if (UrlExists(ccSrc))
127-
srcPath = ccSrc;
128-
if (srcPath != link.replace("interface", "src")) {
129-
var srcText = "&nbsp&nbsp&nbsp<a href=\""+srcPath+"\" style=\"text-decoration:underline;\">[goto src]</a>";
130-
cell.innerHTML = cell.innerHTML.concat(srcText);
131-
}
130+
check_URL_add_link(cppSrc, cell);
131+
check_URL_add_link(ccSrc, cell);
132+
// console.log(a);
133+
// if (check_URL_add_link(cppSrc))
134+
// srcPath = cppSrc;
135+
// else if (check_URL_add_link(ccSrc))
136+
// srcPath = ccSrc;
137+
// if (srcPath != link.replace("interface", "src")) {
138+
// var srcText = "&nbsp&nbsp&nbsp<a href=\""+srcPath+"\" style=\"text-decoration:underline;\">[goto src]</a>";
139+
// cell.innerHTML = cell.innerHTML.concat(srcText);
140+
// }
132141
}
133142

134143
// tests for python imports/fragments

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Github linkify for CMSSW",
33
"description": "Makes browsing CMSSW files waaaay easier.",
4-
"version": "0.3.0",
4+
"version": "0.3.1",
55
"content_scripts": [
66
{
77
"matches": [

0 commit comments

Comments
 (0)