Skip to content

Commit 866c945

Browse files
zamgizamgi
authored andcommitted
chrome extension 2.5
1 parent b326fba commit 866c945

25 files changed

Lines changed: 1054 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[InternetShortcut]
2+
URL=https://www.google.com/search?q=how+to%3A+chrome+extension+%3A+exchange+data+between+service+worker+and+popup+extension+window%3F&newwindow=1&sca_esv=ebc9003c0e8ff0d8&sxsrf=ANbL-n4gQkhDJK4kDYLh60sqE_KMfcsk8g%3A1771199774077&udm=50&fbs=ADc_l-Zp0lk4TtbHg8O7cKPcxjGd8MFRgIC0ldWrtAGqEa8BZC6go8AzVdEKUtx4DM_KW0H5WSV9XyrY_EtQH2lIUf2g05EQqRyj3v_WvnzZ4naeHVpn_z9jvJ00aFiocv_5EY40leDGmnXLkUekEUQ9jFC_yoiULPw_X3z8OZuWxMD_GVfDsuX3-n2hX1ARCpNg_imiqvnlzQtlGgUF7HzGAiVNN1yFNmqzJ4zZhWDm-xIJb1XFaKHVLdOmCklDyX69xLg17RagGD86Wdcpxe8mlsK5nto4Zw&aep=1&ntc=1&sa=X&ved=2ahUKEwiPu_Cq2dySAxWCExAIHYx8DHQQ2J8OegQIExAE&biw=1868&bih=880&dpr=1&mstk=AUtExfDQaaR9swljZRcSAqiZvdxqbTRLsJLf6l0aGIKV9azA4-MqcdeuV8tfAfhgnsXR9M65JQS4xt_1e7N64H6qu1eImWhrl5lARfxQgWOa8ktG2X0LRWxt48XUmhnH3thJrmQ0PwS_yyseDKqmUn0efUNnDEzvd4gKyynFtOrxn6_nHF9VfbKFk4HHd5EM80yrO710p_6KsJ9ZJfBSmEVwi2KAAYiujmndGtdwFZkDrwDk3KYx5VmMqFoM_Q&csuir=1

m3u8-browser-extensions/m3u8-chrome-extension/v3_next/js/popup.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
window.addEventListener('load', async function () {
2-
const getActiveTabId = async () => {
3-
// Query for the active tab in the current window
4-
const tabs = await root.tabs.query({ active: true, currentWindow: true });
5-
return (tabs?.length ? tabs[ 0 ].id : undefined);
6-
}
7-
1+
window.addEventListener('load', async function () {
82
try {
3+
//---var resp = await root.runtime.sendMessage({ action: 'getData' }); console.log('Ответ от SW:', resp);
4+
//root.runtime.sendMessage({ action: 'getData' }, resp => { console.log('Ответ от SW:', resp); });
5+
96
// get m3u8 urls for current active tab
107
const activeTabId = await getActiveTabId();
118

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
self.importScripts('workInfoType.js');
1+
self.importScripts('workInfoType.js');
22

33
//urls-list will be saved between reloads.
44
(async () => {
@@ -10,10 +10,14 @@ self.importScripts('workInfoType.js');
1010
}
1111
})();
1212

13+
const is_match_url = url => {
14+
const ext = (url.split('?')[ 0 ].split('.').pop() || '').toLowerCase();
15+
return (ext === 'm3u8');
16+
};
17+
1318
const requestHeaders_by_url = {};
1419
root.webRequest.onCompleted.addListener(async d => {
15-
const ext = (d.url.split('?')[ 0 ].split('.').pop() || '').toLowerCase();
16-
if (ext === 'm3u8') {
20+
if (is_match_url(d.url)) {
1721
const requestHeaders = requestHeaders_by_url[d.url];
1822
if (requestHeaders) delete requestHeaders_by_url[d.url];
1923

@@ -25,8 +29,7 @@ root.webRequest.onCompleted.addListener(async d => {
2529
{ urls: ['<all_urls>'] });
2630

2731
root.webRequest.onBeforeSendHeaders.addListener(d => {
28-
const ext = (d.url.split('?')[ 0 ].split('.').pop() || '').toLowerCase();
29-
if (ext === 'm3u8') {
32+
if (is_match_url(d.url)) {
3033
requestHeaders_by_url[d.url] = JSON.stringify(d.requestHeaders);
3134
}
3235
},
@@ -36,7 +39,6 @@ root.tabs.onActivated.addListener(async d => await (await load_workInfo()).activ
3639

3740
root.tabs.onRemoved.addListener(async tabId => await (await load_workInfo()).deleteTab(tabId));
3841

39-
// set handler to tabs
4042
root.tabs.onUpdated.addListener(async (tabId, info, tab) => {
4143
if (!info?.status || (info.status.toLowerCase() !== 'complete')) return;
4244

@@ -58,26 +60,9 @@ root.tabs.onUpdated.addListener(async (tabId, info, tab) => {
5860
}
5961
});
6062

61-
/*
62-
// set handler to tabs
63-
root.tabs.onActivated.addListener(async (info) => await (await load_workInfo()).onActivateTab(info.tabId));
64-
65-
root.tabs.onRemoved.addListener(async (tabId) => await (await load_workInfo()).onRemoveTab(tabId));
66-
67-
// set handler to tabs
68-
root.tabs.onUpdated.addListener(async function (tabId, info, tab) {
69-
// if tab not-load
70-
if (!info?.status || (info.status.toLowerCase() !== 'complete')) return;
71-
72-
// if user open empty tab or ftp protocol and etc.
73-
if (!tab?.url || ((tab.url.indexOf('http:') === -1) && (tab.url.indexOf('https:') === -1))) {
74-
await (await load_workInfo()).deleteTab(tabId);
75-
}
76-
else {
77-
const opt = await root.storage.local.get();
78-
if (!opt.saveUrlListBetweenTabReload) {
79-
await conv_2_workInfo(opt.workInfo).deleteTabUrls(tabId);
80-
}
81-
}
82-
});
83-
*/
63+
//root.runtime.onMessage.addListener(async (message, sender, sendResponse) => {
64+
// if (message.action === 'getData') {
65+
// sendResponse({ data: 'Привет из Service Worker!' });
66+
// }
67+
// return (true); // Важно для асинхронного ответа
68+
//});

m3u8-browser-extensions/m3u8-chrome-extension/v3_next/js/workInfoType.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const root = chrome;
1+
const root = chrome;
22
root.browserAction = root.browserAction || root.action;
33

44
const conv_2_workInfo = saved_wi => new workInfoType(saved_wi);
@@ -14,6 +14,12 @@ const workInfoType = function (saved_wi) {
1414
}
1515
};
1616

17+
const getActiveTabId = async () => {
18+
// Query for the active tab in the current window
19+
const tabs = await root.tabs.query({ active: true, currentWindow: true });
20+
return (tabs?.length ? tabs[ 0 ].id : undefined);
21+
};
22+
1723
workInfoType.prototype = {
1824
tabs: {},
1925
activeTabId: null,
@@ -51,16 +57,18 @@ workInfoType.prototype = {
5157
}
5258

5359
await this.save2Storage();
54-
}
60+
}
5561

56-
await this.setUrlsCountText(tabId);
62+
await this.setUrlsCountText(tabId);
5763
},
5864
deleteTab: async function (tabId) {
5965
const has = !!this.tabs[tabId];
6066
if (has) {
6167
delete this.tabs[tabId];
6268
await this.save2Storage();
63-
await this.setUrlsCountText(tabId);
69+
70+
const activeTabId = await getActiveTabId();
71+
await this.setUrlsCountText(activeTabId);
6472
}
6573
},
6674
deleteAllUrlsFromTab: async function (tabId) { await this.deleteTab(tabId); },
@@ -97,7 +105,7 @@ workInfoType.prototype = {
97105
}
98106

99107
if (cnt) await root.browserAction.enable(tabId);
100-
else await root.browserAction.disable(tabId)
108+
else try { await root.browserAction.disable(tabId); } catch (ex) { ; }
101109
}
102110
}
103111
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/alter-view/*
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
html { overflow: hidden; max-width: 800px; }
2+
.body { /*font-family: verdana;*/font-family: monospace; font-size: 1em; overflow: hidden; margin: 3px 3px 0 3px; }
3+
.body_2 { margin-bottom: 10px }
4+
.right { text-align: right; }
5+
6+
div.content {
7+
overflow: auto;
8+
min-width: 200px;
9+
min-height: 50px;
10+
white-space: nowrap;
11+
/*max-width: 800px;*/
12+
/*direction: rtl;*/
13+
}
14+
table.header { border-spacing: 0; border: 1px dotted gray; margin-top: 2px; }
15+
table.header.no-border { border-color: transparent; }
16+
table.header td { padding: 0 0 0 3px; }
17+
table.header input[type="checkbox"] {
18+
appearance: none;
19+
width: 16px;
20+
height: 16px;
21+
border: 1px solid #ccc;
22+
border-radius: 3px;
23+
background-color: #fff;
24+
position: relative;
25+
margin: 1px 1px 0 1px;
26+
}
27+
table.header input[type="checkbox"]:checked {
28+
background-color: #b8e3fd; /*rgb(113, 188, 29)*/ /* Цвет фона (вместо accent-color) */
29+
}
30+
table.header input[type="checkbox"]:checked::after {
31+
content: '\2714'/*'✔'*/;
32+
color: dodgerblue; /* ТОТ САМЫЙ ЦВЕТ ГАЛОЧКИ */
33+
position: absolute;
34+
top: 50%;
35+
left: 50%;
36+
transform: translate(-50%, -50%);
37+
}
38+
39+
table.content { /*font-size: 10px;*/font-size: 0.85em; border-spacing: 0; }
40+
td.separator { border-left: 1px dotted gray; }
41+
42+
h5.found { text-align: left; color: forestgreen; vertical-align: middle; margin: 0/*3px 0 3px 7px*/; }
43+
h5.found a.download_all { color: forestgreen; }
44+
h5.not-found { color: maroon; white-space: nowrap; margin-left: 10px; margin-right: 10px; }
45+
46+
input[type="checkbox"], label[for] { cursor: pointer; }
47+
48+
a { outline: none; text-decoration: none; color: dimgrey; }
49+
a:hover { text-decoration: underline; color: black; }
50+
a > img { border: 1px solid transparent; border-radius: 2px; height: 16px; }
51+
a > img:hover { border-color: silver; }
52+
a.auto_start_download_all { margin-left: 5px; }
53+
#refreshButton { height: 16px; width: 16px; margin-right: 5px; }
54+
55+
div.options_1 { background-color: whitesmoke; text-align: right; white-space: nowrap;
56+
display: flex; flex-wrap: nowrap; justify-content: flex-end; }
57+
div.options_1 > div { display: flex; flex-wrap: nowrap; align-items: center; margin-left: 5px; }
58+
div.options_1 input, div.options_1 label { color: silver; font-size: small; }
59+
div.options_1 input[checked="checked"], div.options_1 input[type="checkbox"]:checked + label { color: #a4a4a4; }
60+
61+
div.content_2 { font-size: 0.6em; font-weight: normal; padding: 0 0 5px 15px; }
62+
div.options_root { padding: 0 0 20px 15px; }
63+
div.options_2 { background-color: whitesmoke; margin-right: 15px; }
64+
div.options_2:nth-child(1) {padding-top: 5px;}
65+
div.options_2:nth-last-child(1) {padding-bottom: 5px;}
66+
67+
span.sign { padding: 0 0 15px 15px }
68+
span.sign_2 { padding: 0 0 15px 5px }
69+
70+
.is_group_by_audio_video { color: dodgerblue; }
71+
.is_group_by_audio_video:hover { color: #0081ff; }
72+
.vis_hidden { visibility: hidden; }
73+
.ord_num { color: silver; padding-left: 2px; }
1.81 KB
Loading
1.99 KB
Loading
410 Bytes
Loading
1.41 KB
Loading

0 commit comments

Comments
 (0)