-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground_old.js
91 lines (81 loc) · 3.1 KB
/
background_old.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
let match = false;
let current_url;
let websites =[];
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
chrome.storage.local.get("website", (result) => {
websites = result.website || [];
console.log(websites)
});
current_url = tab.url
let matchedWebsite = null; // Initialize a variable to store the matched website URL
let match = websites.some((website) => {
if (current_url.includes(website)) {
matchedWebsite = website; // Store the matched website URL
return true; // Return true to stop the iteration
}
return false;
});
console.log('Current URL:', current_url);
console.log('Matched Website:', matchedWebsite)
if (match && matchedWebsite) {
chrome.storage.local.set({ url: current_url}, () => {
console.log('Stored URL:', current_url);
// chrome.tabs.update({ url: chrome.runtime.getURL('new.html') });
});
chrome.storage.local.get(tabId.toString(), (result) => {
if (!result[tabId]){
console.log('Running countdown and redirection');
chrome.tabs.update({url: chrome.runtime.getURL('countdown.html')})
chrome.storage.local.set({[tabId.toString()]: true})
}
})
// chrome.tabs.get(tabId,(currentTab)=> {
// if ( !currentTab.state || !currentTab.state.extensionRan){
// chrome.tabs.update(tabId, {state: {extensionRan: true}}, () =>{
// console.log('Running countdown and redirection');
// chrome.tabs.update({url: chrome.runtime.getURL('new.html')})
// }
// )
// }
// })
}
})
// const match = websites.some((website, index) => current_url.includes(website));
// if (match) {
// console.log("hello")
// chrome.storage.local.set({url: websites[index]})
// chrome.tabs.update({url: chrome.runtime.getURL('new.html')})
// }
// chrome.tab.get((tabId,currentTab)=> {
// if ( !currentTab.state || !currentTab.state.extensionRan){
// chrome.tabs.update(tabId, {state: {extensionRan: true}}, () =>{
// console.log('Running countdown and redirection');
// }
// )
// }
// })
chrome.action.onClicked.addListener((tab) => {
chrome.tabs.create({ url: chrome.runtime.getURL('popup.html') });
});
// document.getElementById('addWebsiteBtn').addEventListener('click', console.log(websites));
// const redirectMap = {
// "example.com": "https://example.com/redirected-page",
// "anotherexample.com": "https://anotherexample.com/redirected-page"
// // Add more websites and redirect URLs as needed
// };
// chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
// if (websites.length === 0){
// return websites
// }
// websites.forEach(website => {
// console.log(website)
// if (changeInfo.status === "complete" && tab.url == website) {
// for (const [website, redirectUrl] of Object.entries(redirectMap)) {
// if (tab.url.includes(website)) {
// chrome.tabs.update(tabId, { url: redirectUrl });
// break;
// }
// }
// }
// })
// });