-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
81 lines (76 loc) · 4.12 KB
/
Copy pathbackground.js
File metadata and controls
81 lines (76 loc) · 4.12 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
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
'use strict';
// Listener for `content.js` to get a list of other installed extensions.
// This allows the player's chat iframe to load support for BetterTTV and FrankerFaceZ.
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.сЗапрос === 'ВставитьСторонниеРасширения') {
// if (message.sRequest === 'InsertThirdPartyExtensions') {
// This must return true to indicate that sendResponse will be called asynchronously.
chrome.management.getAll().then(extensions => {
const response = { сСторонниеРасширения: '' };
// const response = { sThirdPartyExtensions: '' };
for (const ext of extensions) {
if (ext.enabled) {
switch (ext.id) {
// BetterTTV IDs
case 'ajopnjidmegmdimjlfnijceegpefgped': // Chrome
case 'deofbbdfofnmppcjbhjibgodpcdchjii': // Opera
case 'icllegkipkooaicfmdfaloehobmglglb': // Edge
response.сСторонниеРасширения += 'BTTV ';
// response.sThirdPartyExtensions += 'BTTV ';
break;
// FrankerFaceZ IDs
case 'fadndhdgpmmaapbmfcknlfgcflmmmieb': // Chrome
case 'djkpepcignmpfblhbfpmlhoindhndkdj': // Opera
response.сСторонниеРасширения += 'FFZ ';
// response.sThirdPartyExtensions += 'FFZ ';
break;
}
}
}
try {
sendResponse(response);
} catch (e) {
// This can happen if the original tab was closed. Ignore the error.
console.log("Could not send response for 'ВставитьСторонниеРасширения', tab may have closed.", e);
// console.log("Could not send response for 'InsertThirdPartyExtensions', tab may have closed.", e);
}
});
return true;
}
});
// Listener for `player.js` to check if the same channel is already open.
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.сЗапрос === 'ЭтотКаналУжеОткрыт') {
// if (message.sRequest === 'IsThisChannelAlreadyOpen') {
// Query all tabs for one that matches the extension's player URL and channel.
const playerUrl = `chrome-extension://${chrome.runtime.id}/player.html`;
chrome.tabs.query({ url: `${playerUrl}?*` }).then(tabs => {
// Find a tab that is not the sender and has the same channel.
const duplicate = tabs.find(tab =>
tab.id !== sender.tab.id &&
new URL(tab.url).searchParams.get('channel') === message.сКанал
// new URL(tab.url).searchParams.get('channel') === message.sChannel
);
if (duplicate) {
// If a duplicate is found, send `true` back.
try {
sendResponse(true);
} catch (e) {
console.log("Could not send response for 'ЭтотКаналУжеОткрыт', tab may have closed.", e);
// console.log("Could not send response for 'IsThisChannelAlreadyOpen', tab may have closed.", e);
}
} else {
// Otherwise, the original logic doesn't explicitly send `false`,
// but we can do that for clarity. The original code relies on an empty response.
try {
sendResponse(false);
} catch(e) {
console.log("Could not send response for 'ЭтотКаналУжеОткрыт', tab may have closed.", e);
// console.log("Could not send response for 'IsThisChannelAlreadyOpen', tab may have closed.", e);
}
}
});
// Indicate that the response is asynchronous.
return true;
}
});