forked from gcLabs/HappyPath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html
54 lines (52 loc) · 1.84 KB
/
background.html
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
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
<script src="jquery.url.js"></script>
<script>
function createContextMenu() {
// This is just to set up the context menus for the first time
var CMcurrentPathName="";
var CMcurrentPathUrl="";
var CMcountLinks=0;
var CMcMenu=new Array();
chrome.contextMenus.removeAll();
if (localStorage.getItem('links')) {
var CMstringLSRead=localStorage.getItem('links'); // get String for 'url' from Local Storage
var CMjsonLSRead=JSON.parse(CMstringLSRead); // parse string to get JSON array
$.each(CMjsonLSRead.links, function() {
CMcountLinks++;
CMcurrentPathName=this.pathName;
CMcurrentPathUrl=this.pathUrl;
if (CMcurrentPathUrl==0) {
CMcMenu[CMcountLinks]=chrome.contextMenus.create({"title": CMcurrentPathName });
}else{
CMcMenu[CMcountLinks]=chrome.contextMenus.create({"title": " - "+CMcurrentPathName, "onclick": goCMPath });
}
});
} else {// If the link store is empty, use the default
cMenu[0]=chrome.contextMenus.create({"title": "root", "onclick": goCMPath(1)});
}
}
createContextMenu();
function goCMPath(cmId) {
chrome.tabs.getSelected(null,function(tab) {
var currentPathUrl="";
if (localStorage.getItem('links')) {
var countLinks=0;
var stringLSRead=localStorage.getItem('links'); // get String for 'url' from Local Storage
var jsonLSRead=JSON.parse(stringLSRead); // parse string to get JSON array
$.each(jsonLSRead.links, function() {
countLinks++;
if(countLinks==cmId.menuItemId){
currentPathUrl=this.pathUrl;
}
});
}
var tablink = tab.url;
var url=$.url(tablink);
var urlProtocol=url.attr('protocol');
var urlHost=url.attr('host');
var urlDomain=urlProtocol+"://"+urlHost;
var newUrl=urlDomain+currentPathUrl
chrome.tabs.update(tab.id, {url: newUrl});
});
}
</script>