-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (64 loc) · 1.89 KB
/
Copy pathindex.js
File metadata and controls
69 lines (64 loc) · 1.89 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
let isActive = false;
let json;
const swith = document.getElementById('swith');
const textarea = document.getElementById('textarea');
const err = document.getElementById('err');
const reload = document.getElementById('reload');
function showError(msg) {
err.style.display = 'block';
err.innerText = msg;
}
function closeError() {
err.style.display = 'none';
err.innerText = '';
}
reload.onclick = function() {
if (isActive) {
json = textarea.value;
if (json) {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { messageType: 'open', code: json });
});
closeError();
} else {
showError('请输入内容');
}
} else {
showError('请先启用');
}
};
swith.onclick = function() {
isActive = !isActive;
if (isActive) {
json = textarea.value;
if (json) {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { messageType: 'open', code: json });
});
swith.classList.add('active');
closeError();
} else {
isActive = !isActive;
showError('请输入内容');
}
} else {
closeError();
swith.classList.remove('active');
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, { messageType: 'close' });
});
}
};
chrome.storage.local.get(['__ajaxProxyInfo__', '__ajaxProxyActive__'], function(value) {
if (value.__ajaxProxyInfo__ && value.__ajaxProxyInfo__.origin) {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
if (tabs[0].url.startsWith(value.__ajaxProxyInfo__.origin)) {
textarea.value = value.__ajaxProxyInfo__.code;
if (value.__ajaxProxyActive__) {
isActive = true;
swith.classList.add('active');
}
}
});
}
});