-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground_script.js
More file actions
42 lines (42 loc) · 1.43 KB
/
background_script.js
File metadata and controls
42 lines (42 loc) · 1.43 KB
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
let scriptActivated = !1,
tabDetails,
status_updates = {};
function getMsg(t, e) {
return { msg: { type: t, data: e }, sender: 'popup', id: 'irctc' };
}
chrome.runtime.onMessage.addListener((t, e, s) => {
if ('irctc' !== t.id) {
s('Invalid Id');
return;
}
let a = t.msg.type,
i = t.msg.data;
'activate_script' === a
? (chrome.tabs.create(
{ url: 'https://www.irctc.co.in/nget/train-search' },
(t) => {
(tabDetails = t),
chrome.scripting.executeScript({
target: { tabId: t.id },
files: ['./content_script.js'],
});
}
),
s('Script activated'))
: 'status_update' === a
? (status_updates[e.id] || (status_updates[e.id] = []),
status_updates[e.id].push({ sender: e, data: i }))
: s('Something went wrong');
}),
chrome.tabs.onUpdated.addListener((t, e, s) => {
t === tabDetails?.id &&
e?.status === 'complete' &&
(s.url.includes('booking/train-list') &&
chrome.tabs.sendMessage(tabDetails.id, getMsg('selectJourney')),
s.url.includes('booking/psgninput') &&
chrome.tabs.sendMessage(tabDetails.id, getMsg('fillPassengerDetails')),
s.url.includes('booking/reviewBooking') &&
chrome.tabs.sendMessage(tabDetails.id, getMsg('reviewBooking')),
s.url.includes('payment/bkgPaymentOptions') &&
chrome.tabs.sendMessage(tabDetails.id, getMsg('bkgPaymentOptions')));
});