-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathmain.js
59 lines (51 loc) · 1.66 KB
/
main.js
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
function getCurrentProjectId() {
var queryString = window.location.search.substring(1);
var queries = queryString.split('&');
var projectId = null;
queries.forEach(function(query) {
var keyAndValue = query.split('=');
if (keyAndValue[0] === 'project') {
projectId = keyAndValue[1];
}
});
return projectId;
}
function getCurrentHeader() {
return document.querySelector('[md-theme=platform-bar]') || document.querySelector('.cfc-platform-bar-blue') || document.querySelector('.cfc-platform-bar-white.gm2-platform-bar') || document.querySelector('.cfc-platform-bar-container');
}
function changeHeaderColor() {
var defaultSetting = {
conditions: []
};
chrome.storage.sync.get(defaultSetting, function(setting) {
var header = getCurrentHeader();
if (!header) {
console.error("can't get valid header");
return;
}
var projectId = getCurrentProjectId();
if (!projectId) {
console.error("can't get projectId");
return;
}
var conditions = setting.conditions;
for (var i = 0; i < conditions.length; i++) {
var condition = conditions[i];
if (projectId.match(condition.pattern)) {
var colorRgb = 'rgb(' + condition.color.r + ', '
+ condition.color.g + ', '
+ condition.color.b + ')';
header.style.backgroundColor = colorRgb;
return;
}
}
// No patterns matched, so back to original color
header.style.backgroundColor = null;
});
}
(function() {
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
changeHeaderColor();
});
changeHeaderColor();
}());