-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
138 lines (121 loc) · 3.51 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
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
import store from './store.js';
import { rmQuery, updateQuery, showTips, updateQueryByStr } from './utils.js';
import { reloadPage } from './chrUtils.js';
const tbody = document.querySelector('#tbody');
const template = document.querySelector('#productrow');
const noData = document.querySelector('#nodata');
const currentUrlNode = document.querySelector('#current-url');
// ald
const configName = document.querySelector('#first-config-name');
const subConfigName = document.querySelector('#subconfig-name');
const resId = document.querySelector('#resId-input');
const openPegasusPanel = document.querySelector('#open-pegasus-panel-btn');
const warnText = document.querySelector('.warn-text');
//#region quick query
const tagSection = document.querySelector('#tag-section');
tagSection.onclick = (e) => {
const query = e.target.textContent;
updateQueryByStr(query);
};
//#endregion
/**
* 创建行
* @param {String} v1 key的值
* @param {String} v2 value的值
*/
function createTr(v1 = '', v2 = '') {
let oldKey = v1;
const clone = template.content.cloneNode(true);
const tr = clone.querySelector('tr');
// const checkbox = clone.querySelector(".checkbox");
const addBtn = clone.querySelector('#add-btn');
const removeBtn = clone.querySelector('#remove-btn');
const keyInput = clone.querySelector('#key-input');
const valueInput = clone.querySelector('#value-input');
keyInput.value = v1;
valueInput.value = v2;
// function toggleCheckbox() {
// console.log("click");
// if (checkbox.checked && v1 !== "") {
// store.url = addQuery({ [v1]: v2 });
// } else {
// store.url = rmQuery(v1);
// }
// }
// 创建行
addBtn.addEventListener('click', () => {
createTr();
});
// 移除行
removeBtn.addEventListener('click', () => {
console.log('click');
removeTr(tr);
store.url = rmQuery(oldKey);
});
keyInput.onchange = () => {
updateQuery({ [keyInput.value]: valueInput.value });
oldKey = keyInput.value;
};
valueInput.onchange = () => {
updateQuery({ [keyInput.value]: valueInput.value });
};
// checkbox.addEventListener("change", throttle(toggleCheckbox));
tbody.appendChild(clone);
}
function removeTr(node) {
tbody.removeChild(node);
}
function genQRCode(url) {
new QRCode(document.querySelector('#qr-code-image'), {
text: url,
width: 180, //default 128
height: 180,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
});
}
chrome.runtime.sendMessage(
{
type: 'getUrl',
},
(url) => {
// init url
store.pageUrl = url;
genQRCode(url);
store.url = url;
currentUrlNode.textContent = store.url;
const index = url.indexOf('?');
const query = index > -1 ? url.slice(index) : '';
if (query === '') {
// const clone = noData.content.cloneNode(true);
// tbody.append(clone);
createTr('url参数为空');
} else {
const qs = new URLSearchParams(query);
for (const q of qs) {
createTr(q[0], q[1]);
}
}
}
);
warnText.onclick = () => {
reloadPage(store.url);
showTips(false);
};
// open first ald
openPegasusPanel.onclick = () => {
// 21046331
//
if (resId.value !== '') {
const newUrl = updateQuery({
activeResourceId: resId.value,
activeResourcePitId: resId.value,
aladdin: true,
tagInfo: subConfigName.value
? `${configName.value}[hash=${resId.value}]/${subConfigName.value}`
: configName.value,
});
reloadPage(newUrl);
}
};