-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html
154 lines (153 loc) · 4.5 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript' src='underscore.js'></script>
<script type='text/javascript'>
/**
* @param {!number} tab_id
* @param {!Object} change_info
* @param {!Object} tab
*/
function check_for_cloudkick (tab_id, change_info, tab) {
if (tab.url.indexOf('www.cloudkick.com') > -1) {
chrome.pageAction.show(tab_id);
}
};
/**
* Toggles easy info on cloudkick overview page.
*/
function toggle_easy_info () {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id,
{topic: "toggle_easy_info"},
function(response) { /*do nuthin'*/ }
);
});
}
/**
* Toggles the JAVASCRIPT_DBUG=True option for the tab.
*/
function toggle_js_debug () {
toggle_debug('JAVASCRIPT');
}
/**
* Toggles the CSS_DBUG=True option for the tab.
*/
function toggle_css_debug () {
toggle_debug('CSS');
}
/**
* @param {!string} type
* Toggles a debug type query parameter.
*/
function toggle_debug (type) {
chrome.tabs.getSelected(null, function(selected_tab) {
chrome.tabs.get(selected_tab.id, function (tab) {;
var url, parts;
url = tab.url;
parts = get_url_parts(url);
if (url.indexOf(type + '_DEBUG=True') !== -1) {
parts.query = _.filter(parts.query, function (query_parts) {
if (query_parts.key === type + '_DEBUG') {
return false;
}
return true;
});
} else {
if (!parts.query) {
parts['query'] = [];
}
parts.query.push({
key: type + '_DEBUG',
value: 'True'
});
}
chrome.tabs.update(selected_tab.id, {url: create_url(parts)});
});
});
}
/**
* Create a new URL from a set or properties.
* @param {!Object} obj
* @return {!string} The new URL
*/
function create_url (obj) {
var url, query_parts;
console.log('create_url from', obj);
url = obj.protocol + obj.host;
if (obj.path) {
url += obj.path;
}
console.log('url.query', url.query);
if (obj.query && obj.query.length) {
url += '?';
query_parts = [];
_.each(obj.query, function (parts) {
query_parts.push(parts.key + '=' + parts.value);
});
url += query_parts.join('&');
}
if (obj.hash) {
url += obj.hash;
}
return url;
}
/**
* @param {!string} url
* @return {!Object}
*/
function get_url_parts (url) {
var protocol, index, index, rest, query, query_string,
query_parts, hash, host, path;
console.log(url);
index = url.indexOf('://') + 3;
protocol = url.substr(0, index);
rest = url.substr(index);
console.log('protocol', protocol);
index = rest.indexOf('#');
if (index !== -1) {
hash = rest.substr(index);
rest = rest.substr(0, index);
}
index = rest.indexOf('?');
if (index !== -1) {
query_string = rest.substr(index + 1);
rest = rest.substr(0, index);
query_parts = query_string.split('&');
query = [];
_.each(query_parts, function (part) {
var parts, obj;
parts = part.split('=');
obj = {key: parts[0]};
if (parts.length > 1) {
obj.value = parts[1];
}
query.push(obj)
});
}
index = rest.indexOf('/');
if (index !== -1) {
host = rest.substr(0, index);
path = rest.substr(index);
}
return {
protocol: protocol,
host: host,
path: path,
hash: hash,
query: query
}
}
/**
* Custom CK node search
*/
chrome.omnibox.onInputEntered.addListener(function(query) {
chrome.tabs.getSelected(null, function(tab) {
var url = 'https://www.cloudkick.com/a/cloudk1ck/#!filter/1//';
chrome.tabs.update(tab.id, {url: url + query});
});
});
chrome.tabs.onUpdated.addListener(check_for_cloudkick);
</script>
</head>
</html>