Skip to content

Commit e5aebba

Browse files
committed
Add option to hide m3u8 sub-playlists.
1 parent 2a9158b commit e5aebba

3 files changed

Lines changed: 59 additions & 5 deletions

File tree

options.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,42 @@ document.addEventListener('DOMContentLoaded', () => {
232232
// ── Plugin Settings ────────────────────────────────────────
233233
const pluginsList = document.getElementById('plugins-list');
234234

235+
function renderPluginOptionsHtml(plugin, cfg) {
236+
if (!plugin.options || plugin.options.length === 0) return '';
237+
const pluginOpts = (cfg && cfg.options) ? cfg.options : {};
238+
let html = '<div class="plugin-options" style="margin-top: 10px; margin-left: 0;">';
239+
for (const opt of plugin.options) {
240+
const val = pluginOpts[opt.id] !== undefined ? pluginOpts[opt.id] : opt.defaultValue;
241+
if (opt.type === 'checkbox') {
242+
html += `
243+
<div class="setting-row" style="margin-bottom: 5px;">
244+
<input type="checkbox" id="plugin-opt-${plugin.name.replace(/\s+/g, '-')}-${opt.id}" data-opt="${opt.id}" ${val ? 'checked' : ''}>
245+
<label for="plugin-opt-${plugin.name.replace(/\s+/g, '-')}-${opt.id}" style="font-size: 13px;">${opt.label}</label>
246+
</div>
247+
`;
248+
}
249+
}
250+
html += '</div>';
251+
return html;
252+
}
253+
254+
function bindPluginOptionsEvents(row, plugin) {
255+
if (!plugin.options || plugin.options.length === 0) return;
256+
row.querySelectorAll('input[type="checkbox"][data-opt]').forEach(chk => {
257+
chk.addEventListener('change', (e) => {
258+
chrome.storage.local.get(['pluginsConfig'], (res) => {
259+
const updated = res.pluginsConfig || {};
260+
if (!updated[plugin.name]) {
261+
updated[plugin.name] = { enabled: plugin.defaultEnabled !== false, options: {} };
262+
}
263+
if (!updated[plugin.name].options) updated[plugin.name].options = {};
264+
updated[plugin.name].options[e.target.dataset.opt] = e.target.checked;
265+
chrome.storage.local.set({ pluginsConfig: updated });
266+
});
267+
});
268+
});
269+
}
270+
235271
function renderPlugins(pluginsMeta, pluginsConfig) {
236272
pluginsList.innerHTML = '';
237273
if (!pluginsMeta || pluginsMeta.length === 0) {
@@ -253,14 +289,18 @@ document.addEventListener('DOMContentLoaded', () => {
253289
<div class="plugin-info">
254290
<div class="plugin-name">${plugin.name}</div>
255291
${plugin.description ? `<div class="plugin-desc">${plugin.description}</div>` : ''}
292+
${renderPluginOptionsHtml(plugin, cfg)}
256293
</div>
257294
`;
258295
pluginsList.appendChild(row);
259296

260-
row.querySelector('input[type="checkbox"]').addEventListener('change', (e) => {
297+
bindPluginOptionsEvents(row, plugin);
298+
299+
row.querySelector(`input#${id}`).addEventListener('change', (e) => {
261300
chrome.storage.local.get(['pluginsConfig'], (res) => {
262301
const updated = res.pluginsConfig || {};
263-
updated[plugin.name] = { enabled: e.target.checked };
302+
const existing = updated[plugin.name] || {};
303+
updated[plugin.name] = { ...existing, enabled: e.target.checked };
264304
chrome.storage.local.set({ pluginsConfig: updated });
265305
});
266306
});

plugin-engine.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ function getPlugins() {
2020
return plugins.map(p => ({
2121
name: p.name || 'unnamed',
2222
description: p.description || '',
23-
defaultEnabled: p.defaultEnabled !== false
23+
defaultEnabled: p.defaultEnabled !== false,
24+
options: p.options || []
2425
}));
2526
}
2627

@@ -50,7 +51,8 @@ async function executeHook(hookName, arg) {
5051

5152
if (plugin[hookName] && typeof plugin[hookName] === 'function') {
5253
try {
53-
const hookResult = await plugin[hookName](arg);
54+
const hookArg = (typeof arg === 'object' && arg !== null) ? { ...arg, pluginConfig: cfg || {} } : arg;
55+
const hookResult = await plugin[hookName](hookArg);
5456
if (hookResult) {
5557
result = { ...result, ...hookResult };
5658
}

plugins/m3u8-plugin.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ const M3U8_PLUGIN = {
77
name: "M3U8 Downloader",
88
description: "Detects HLS (.m3u8) streams and merges video/audio segments into a single MP4 file.",
99
defaultEnabled: true,
10+
options: [
11+
{
12+
id: "displayNonHls",
13+
label: "Display specific variant playlists (master, audio, video m3u8) in capture list",
14+
type: "checkbox",
15+
defaultValue: false
16+
}
17+
],
1018
handledUrls: new Set(),
1119

1220
/**
1321
* Intercept hook: Detect .m3u8 and ignore size rules.
1422
*/
15-
async onIntercept({ details, contentType, config }) {
23+
async onIntercept({ details, contentType, config, pluginConfig }) {
1624
const url = details.url.toLowerCase();
1725
const isM3u8 = url.includes('.m3u8') ||
1826
contentType.toLowerCase().includes('application/vnd.apple.mpegurl') ||
@@ -24,6 +32,10 @@ const M3U8_PLUGIN = {
2432
else if (url.includes('/vid/') || url.includes('avc1')) streamType = 'video';
2533
else if (url.includes('/aud/') || url.includes('mp4a')) streamType = 'audio';
2634

35+
if (streamType !== 'hls' && !(pluginConfig?.options?.displayNonHls)) {
36+
return { skip: true };
37+
}
38+
2739
return {
2840
ignoreSize: true,
2941
isPluginHandled: true,

0 commit comments

Comments
 (0)