-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
54 lines (44 loc) · 1.57 KB
/
background.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
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.create({
id: "updateList",
title: "Update",
contexts: ["action"]
});
updateList();
});
chrome.contextMenus.onClicked.addListener((info) => {
if (info.menuItemId === "updateList") {
updateList();
}
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'updateList') {
updateList()
.then(count => sendResponse({ count }))
.catch(err => sendResponse({ error: err.message }));
return true;
}
});
function updateList() {
const proxyUrl = 'https://cors-anywhere.herokuapp.com/';
const targetUrl = 'https://epgshare01.online/epgshare01/epg_ripper_ALL_SOURCES1.txt';
return fetch(proxyUrl + targetUrl)
.then(response => response.text())
.then(text => {
const validList = text.split('\n')
.map(line => line.trim())
.filter(line => line && !line.startsWith('--'));
console.log('Processed validList:', validList);
chrome.storage.local.set({ validList });
chrome.notifications.create({
type: 'basic',
iconUrl: 'icon.png',
title: 'List Updated',
message: `Extension has added ${validList.length} channels from EPGSHARE01, confirmed channels will appear as teal!`
});
return validList.length;
})
.catch(error => {
console.error('Error fetching the list:', error);
});
}