This repository was archived by the owner on Oct 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
93 lines (85 loc) · 2.42 KB
/
Copy pathbackground.js
File metadata and controls
93 lines (85 loc) · 2.42 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
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
function getItem(key) { return getStorage().getItem(key); }
function setItem(key, map) { return getStorage().setItem(key, map); }
function removeItem(key) { return getStorage().removeItem(key); }
function getStorage() { return window.localStorage; }
function loadModifiers(json) {
var showPublic = localStorage["showPublic"];
var showProtected = localStorage["showProtected"];
var showNone = localStorage["showNone"];
var showPrivate = localStorage["showPrivate"];
if (showPublic === undefined || showProtected === undefined
|| showNone === undefined || showPrivate === undefined) {
showPublic = "true";
showProtected = showNone = showPrivate = "false";
}
var showModifiers = json["showModifiers"] = {};
showModifiers["showPublic"] = showPublic;
showModifiers["showProtected"] = showProtected;
showModifiers["showNone"] = showNone;
showModifiers["showPrivate"] = showPrivate;
}
function getClassInfo(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var json = JSON.parse(xhr.responseText)
loadModifiers(json);
callback(json);
} else {
callback('false');
}
}
}
xhr.open('GET', 'http://japarser.appspot.com/src?url=' + url, true);
//xhr.open('GET', 'http://localhost:8888/src/?url=' + url, true);
xhr.send(null);
return xhr;
}
chrome.extension.onRequest.addListener(function(request, sender, callback) {
switch (request.action) {
case 'isRunning':
if (getItem('isRunning') === 'true') {
var json = {};
loadModifiers(json);
callback(json);
} else {
callback('false');
}
break;
case 'getClassInfo':
if (getItem('isRunning') === 'true') {
getClassInfo(sender.tab.url, callback);
} else {
callback('false');
}
break;
}
});
chrome.browserAction.onClicked.addListener(function(tab) {
if (getItem('isRunning') !== 'true') {
setItem('isRunning', 'true');
chrome.browserAction.setBadgeText({
text : "on"
});
} else {
setItem('isRunning', 'false');
chrome.browserAction.setBadgeText({
text : "off"
})
}
chrome.tabs.executeScript(tab.id, {
code : "location.reload();"
});
});
(function() {
if (getItem('isRunning') !== 'true') {
chrome.browserAction.setBadgeText({
text : "off"
});
} else {
chrome.browserAction.setBadgeText({
text : "on"
})
}
})();