-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
33 lines (29 loc) · 1.06 KB
/
content.js
File metadata and controls
33 lines (29 loc) · 1.06 KB
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
$('a').click(function (b) {
if (b.which == 2) { // If middle click detected
var tab = new Object();
tab.url = $(this).attr("href");
chrome.extension.sendRequest(parseUrl(tab));
return false; // Stop current page from also loading link
}
});
function parseUrl(tab) {
var isAbsoluteUrl = /^\w+:\/\//
if (!(isAbsoluteUrl.test(tab.url))) {
if (/^\//.test(tab.url)) {
// If starts with / then append tohostname
tab.url = window.location.protocol + "//" + window.location.hostname + tab.url;
} else if (/.*\/$/.test(window.location.href)) {
// else if starts with any other character then if ends in / append to current level
tab.url = window.location.href + tab.url;
} else if (/^.*[^/]+\.[^./]+$/.test(window.location.href)) {
// else if ends in a file, lose last bit until / and append to current level
var str = window.location.href.split("/");
str.pop();
tab.url = str.join("/") + "/" + tab.url;
} else {
// else doesn't end in / so append / and relative url
tab.url = window.location.href + "/" + tab.url;
}
}
return tab;
}