-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
27 lines (26 loc) · 1.08 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
document.addEventListener('DOMContentLoaded', () => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {action: 'getMaterials'}, (response) => {
const materialList = document.getElementById('materialList');
response.forEach(material => {
const div = document.createElement('div');
div.textContent = `${material.name}: ${material.url}`;
materialList.appendChild(div);
});
});
});
document.getElementById('downloadBtn').addEventListener('click', () => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {action: 'getMaterials'}, (response) => {
const jsonContent = JSON.stringify(response, null, 2);
const blob = new Blob([jsonContent], {type: 'application/json'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = '微信公众号素材信息.json';
a.click();
URL.revokeObjectURL(url);
});
});
});
});