-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
78 lines (70 loc) · 2.49 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
//Under developing from Van-Dung NGO (email: [email protected])
//Original release to github in July of 2023.
const ScrpB = document.getElementById("ScrpB")
var ScrpLst = document.getElementById("scrapinglist")
let DowB;
const Set_B = document.getElementById("_setIcon")
const Set_panel = document.getElementById("setting");
const SnLstDiv = document.getElementById("setting");
const LoaderLine = document.getElementById("loader_line");
Set_B.addEventListener("click", function () {
if(Set_panel.style.display == 'none') {
Set_panel.style.display = "block";
}
else
{
Set_panel.style.display = "none";
SnLstDiv.style.height = "fit-content";
}
})
ScrpB.addEventListener("click", async function () {
const [tab] = await chrome.tabs.query({active: true, lastFocusedWindow: true});
// have to find a better query scheme - problem is the lastFocusedWindow can be shifted to the extension itself
// upon click on the popup.html
const SendOrder = await chrome.tabs.sendMessage(tab.id,
{
sender: 'popup',
target: 'content',
pipelineID: '1',
string: 'TCB',
});
LoaderLine.style.display = "block";
});
chrome.runtime.onMessage.addListener(OnReceive)
async function OnReceive(message) {
// Return early if this message isn't meant for the background script
var _Line2Dis="";
if(message.target !== 'popup') return;
const DataArray = message.string;
// with header i = 0 || without header i = 1;
for(let i=1; i< DataArray.length; i++){
let WrtLine ='';
for (let n=0;n<DataArray[i].length;n++){
WrtLine += `${DataArray[i][n]}|`;
}
WrtLine += '\r\n';
_Line2Dis +=WrtLine;
}
addDownLoad(message._addInfo,_Line2Dis);
}
async function addDownLoad(info,message){
ScrpLst.innerHTML += `<div><h1 class="w3-small" style="font-weight: bold;">${info}</h1></div>`;
DowB = document.createElement('a');
DowB.textContent = `download`;
DowB.href = "#";
DowB.classList.add("w3-small")
DowB.addEventListener('click', function Click(){
downloadURI('data:text/csv;charset=utf-8,' + (message),info);
});
ScrpLst.appendChild(DowB);
LoaderLine.style.display = "none";
}
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}