Updated UI and fixed YT

This commit is contained in:
2026-08-14 13:01:44 -04:00
parent b7ddb55da3
commit b8863ebc89
10 changed files with 552 additions and 345 deletions

59
main.js
View File

@@ -1,15 +1,20 @@
const { app, BrowserWindow, session } = require('electron');
const { app, BrowserWindow, session, ipcMain } = require('electron');
const path = require('node:path');
// Use require for consistency
const { ElectronBlocker } = require('@ghostery/adblocker-electron');
const fetch = require('cross-fetch');
const androidUA = 'Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.6167.164 Mobile Safari/537.36';
async function setupBlocker() {
const blocker = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch);
blocker.enableBlockingInSession(session.defaultSession);
console.log('Adblocker enabled');
let historyWindow = null;
async function setupBlocker(sess) {
try {
const blocker = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch);
blocker.enableBlockingInSession(sess);
console.log('Adblocker enabled');
} catch (err) {
console.error('Failed to load adblocker:', err);
}
}
const createWindow = () => {
@@ -20,23 +25,51 @@ const createWindow = () => {
preload: path.join(__dirname, 'preload.js'),
contextIsolation: false,
nodeIntegration: true,
nodeIntegrationInSubFrames: true,
webSecurity: false,
sandbox: false,
webviewTag: true,
}
});
win.webContents.session.setUserAgent(androidUA);
win.maximize();
win.loadFile('src/index.html');
};
function createHistoryWindow() {
// Focus if already opened
if (historyWindow) {
historyWindow.focus();
return;
}
historyWindow = new BrowserWindow({
width: 500,
height: 650,
title: 'Browsing History',
autoHideMenuBar: true,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
}
});
historyWindow.loadFile('src/history.html');
historyWindow.on('closed', () => {
historyWindow = null;
});
}
app.whenReady().then(async () => {
await setupBlocker();
// IPC Listener to handle popup creation
ipcMain.on('open-history-window', () => {
createHistoryWindow();
});
app.whenReady().then(async () => {
const sess = session.defaultSession;
sess.setUserAgent(androidUA);
await setupBlocker(sess);
sess.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders['User-Agent'] = androidUA;
details.requestHeaders['Sec-CH-UA-Mobile'] = '?1';
@@ -46,8 +79,8 @@ app.whenReady().then(async () => {
sess.webRequest.onHeadersReceived((details, callback) => {
const responseHeaders = { ...details.responseHeaders };
const keys = Object.keys(responseHeaders);
keys.forEach(key => {
Object.keys(responseHeaders).forEach((key) => {
if (['x-frame-options', 'content-security-policy'].includes(key.toLowerCase())) {
delete responseHeaders[key];
}