-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpopup.js
85 lines (79 loc) · 3.13 KB
/
popup.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
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
document.querySelectorAll("input").forEach(function(v){
chrome.storage.local.get([v.dataset.key], function (result) {
if (v.type == 'checkbox'){
v.checked = result[v.dataset.key];
}
if (v.type == 'text'){
v.value = result[v.dataset.key] || '';
}
})
v.addEventListener("change", function (e) {
if (v.type == 'checkbox'){
// console.log(e.target.dataset.key, e.target.checked)
if (e.target.dataset.key == 'config-hook-global' && e.target.checked){
chrome.browserAction.setBadgeText({text: 'v'});
}else{
chrome.browserAction.setBadgeText({text: ''});
}
chrome.storage.local.set({
[e.target.dataset.key]: e.target.checked
})
}
if (v.type == 'text'){
chrome.storage.local.set({
[e.target.dataset.key]: e.target.value
})
}
})
})
document.getElementById('showoptions').addEventListener('click', function(e){
function closePopup() {
window.close();
document.body.style.opacity = 0;
setTimeout(function() { history.go(0); }, 300);
}
closePopup()
chrome.tabs.create({
url: chrome.runtime.getURL('options.html')
});
})
document.getElementById('addlistener').addEventListener('click', function(e){
chrome.storage.local.get([ "config-hook-domobj", "config-hook-domobj-get", "config-hook-domobj-set", "config-hook-domobj-func" ], function (result) {
if (!(result["config-hook-domobj"] && result["config-hook-domobj-get"] && result["config-hook-domobj-set"] && result["config-hook-domobj-func"])){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {action: {type:'alerterror', info: `请在配置页面中将DOM挂钩功能全部选中。
以下四个必选:
是否启用挂钩 DOM 对象的原型的功能调试输出
hook-domobj-显示get输出
hook-domobj-显示set输出
hook-domobj-显示func输出
后面的选项,你也需要全选。`}}, function(response) {});
});
return
}
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {action: {type:'addlistener', info: 'addlistener'}}, function(response) {});
});
})
})
document.getElementById('logtoggle').addEventListener('click', function(e){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {action: {type:'logtoggle', info: 'logtoggle'}}, function(response) {});
});
})
const bg = chrome.extension.getBackgroundPage()
document.getElementById('clone_page').addEventListener('click', function(e){
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
var url = tabs[0].url
var html = bg.get_html(url)
if (html){
var url = URL.createObjectURL(new Blob(html.split(''), {type: 'text/html'}))
chrome.downloads.download({
url: url,
filename: 'clone_html.html'
});
}else{
alert('获取html结构失败,请右键需要拷贝的页面的空白处,选择“打开 v_jstools 动态调试”。刷新页面后,确保页面资源加载充足后再重新点击“拷贝当前页面”')
}
});
})