From 995962a497f0b975cea4577764b378d9ae11d52b Mon Sep 17 00:00:00 2001 From: Sneed Group Holder Date: Thu, 21 Nov 2024 14:57:11 -0600 Subject: [PATCH] finish up the rewrite --- libbrowz.js | 6 +- main.js | 36 +++++++++++- package-lock.json | 137 +++++++++++++--------------------------------- package.json | 3 +- renderer.js | 2 + 5 files changed, 76 insertions(+), 108 deletions(-) diff --git a/libbrowz.js b/libbrowz.js index b1acddd..9aea89b 100644 --- a/libbrowz.js +++ b/libbrowz.js @@ -6,9 +6,7 @@ const userAgents = [ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edg/98.0.0.0", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36", - "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0", - "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36", - "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Firefox/128.0" + "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0" ]; function getRandomUserAgent() { @@ -60,7 +58,7 @@ function go() { url = searchPattern.replaceAll("!!!QUERY!!!", query) } else if (url.includes("https://news.google.com")) { url = url.replaceAll("https://news.google.com", "http://68k.news") - } else if (url.includes("google.com") && !url.includes("maps") && !url.includes("news") && !url.includes("webstore") && !url.includes("drive") && !url.includes("docs") && !url.includes("sheets") && !url.includes("slides") && !url.includes("mail")) { + } else if (url.includes("google.com/search")) { url = url.replaceAll("google.com", "search.sparksammy.com") } document.getElementById("txtUrl").value = "" diff --git a/main.js b/main.js index fee658e..96075f2 100644 --- a/main.js +++ b/main.js @@ -5,7 +5,24 @@ const fetch = require("cross-fetch") const { ElectronChromeExtensions } = require('electron-chrome-extensions') const { ElectronBlocker } = require('@ghostery/adblocker-electron'); const http = require('http'); +const fs = require('fs'); const { createProxy } = require('proxy'); +const buildChromeContextMenu = require('electron-chrome-context-menu').default +var extensions +app.on('web-contents-created', (event, webContents) => { + webContents.on('context-menu', (e, params) => { + const menu = buildChromeContextMenu({ + params, + webContents, + openLink: (url, disposition) => { + webContents.loadURL(url) + } + }) + + menu.popup() + }) +}) + ipcMain.on('windowmaker', (event, arg) => { createWindow(); @@ -15,7 +32,6 @@ const proxy = createProxy(http.createServer()); proxy.listen(3129) //Function to enable AD Blocking... let blocker = undefined -let extensions = undefined async function enableGoodies(s) { blocker = await ElectronBlocker.fromLists(fetch, [ 'https://easylist.to/easylist/easylist.txt', @@ -38,7 +54,6 @@ function isLocal(url) { return locals.some(local => url.includes(local)); } - function createWindow () { const mainWindow = new BrowserWindow({ width: 1100, @@ -49,12 +64,27 @@ function createWindow () { preload: path.join(__dirname, 'preload.js'), webviewTag: true, devTools: false, - nodeIntegration: true, + nodeIntegration: false, sandbox: true, contextIsolation: true } }) + const userDataPath = app.getPath('userData'); + const extensionsDir = path.join(userDataPath, 'SneedExtensions'); + + if (!fs.existsSync(extensionsDir)) { + fs.mkdirSync(extensionsDir, { recursive: true }); + } + + const extensionFolders = fs.readdirSync(extensionsDir, { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => path.join(extensionsDir, dirent.name)); + + for (const extensionPath of extensionFolders) { + extensions.loadExtension(extensionPath); + } + extensions.addTab(mainWindow.webContents, mainWindow) mainWindow.setMinimumSize(1000, 300) diff --git a/package-lock.json b/package-lock.json index 14031e0..a6bd1a6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,9 +9,10 @@ "version": "1.0.0", "license": "SPL-R5", "dependencies": { - "@cliqz/adblocker-electron": "^1.31.3", "@ghostery/adblocker": "^2.1.1", + "@ghostery/adblocker-electron": "^2.1.1", "cross-fetch": "^3.1.5", + "electron-chrome-context-menu": "^1.1.0", "electron-chrome-extensions": "^3.10.0", "electron-squirrel-startup": "^1.0.1", "electron-tabs": "^1.0.1", @@ -29,68 +30,6 @@ "electron-packager": "^17.1.2" } }, - "node_modules/@cliqz/adblocker": { - "version": "1.34.0", - "resolved": "https://registry.npmjs.org/@cliqz/adblocker/-/adblocker-1.34.0.tgz", - "integrity": "sha512-d7TeUl5t+TOMJe7/CRYtf+x6hbd8N25DtH7guQTIjjr3AFVortxiAIgNejGvVqy0by4eNByw+oVil15oqxz2Eg==", - "deprecated": "This project has been renamed to @ghostery/adblocker. Install using @ghostery/adblocker instead", - "license": "MPL-2.0", - "dependencies": { - "@cliqz/adblocker-content": "^1.34.0", - "@cliqz/adblocker-extended-selectors": "^1.34.0", - "@remusao/guess-url-type": "^1.3.0", - "@remusao/small": "^1.2.1", - "@remusao/smaz": "^1.9.1", - "@types/chrome": "^0.0.278", - "@types/firefox-webext-browser": "^120.0.0", - "tldts-experimental": "^6.0.14" - } - }, - "node_modules/@cliqz/adblocker-content": { - "version": "1.34.0", - "resolved": "https://registry.npmjs.org/@cliqz/adblocker-content/-/adblocker-content-1.34.0.tgz", - "integrity": "sha512-5LcV8UZv49RWwtpom9ve4TxJIFKd+bjT59tS/2Z2c22Qxx5CW1ncO/T+ybzk31z422XplQfd0ZE6gMGGKs3EMg==", - "deprecated": "This project has been renamed to @ghostery/adblocker-content. Install using @ghostery/adblocker-content instead", - "license": "MPL-2.0", - "dependencies": { - "@cliqz/adblocker-extended-selectors": "^1.34.0" - } - }, - "node_modules/@cliqz/adblocker-electron": { - "version": "1.34.0", - "resolved": "https://registry.npmjs.org/@cliqz/adblocker-electron/-/adblocker-electron-1.34.0.tgz", - "integrity": "sha512-hwCFmHg6eqWAL1jG1JWFWfI7kzKuJ99oq+fjmnZPv6rwnd4RGQUDClhhZQMZHOz+Lj/tCQwmkvtaYMh2g+LZpA==", - "deprecated": "This project has been renamed to @ghostery/adblocker-electron. Install using @ghostery/adblocker-electron instead", - "license": "MPL-2.0", - "dependencies": { - "@cliqz/adblocker": "^1.34.0", - "@cliqz/adblocker-electron-preload": "^1.34.0", - "tldts-experimental": "^6.0.14" - }, - "peerDependencies": { - "electron": ">11" - } - }, - "node_modules/@cliqz/adblocker-electron-preload": { - "version": "1.34.0", - "resolved": "https://registry.npmjs.org/@cliqz/adblocker-electron-preload/-/adblocker-electron-preload-1.34.0.tgz", - "integrity": "sha512-wi4FBGwlpJv8VQDTyiQJ2qLqdhtxzAEdEzBkOt9crrPP0meO1RUlhTMeZFFxNTogXFiK3W8VujTBixoGNEKscQ==", - "deprecated": "This project has been renamed to @ghostery/adblocker-electron-preload. Install using @ghostery/adblocker-electron-preload instead", - "license": "MPL-2.0", - "dependencies": { - "@cliqz/adblocker-content": "^1.34.0" - }, - "peerDependencies": { - "electron": ">11" - } - }, - "node_modules/@cliqz/adblocker-extended-selectors": { - "version": "1.34.0", - "resolved": "https://registry.npmjs.org/@cliqz/adblocker-extended-selectors/-/adblocker-extended-selectors-1.34.0.tgz", - "integrity": "sha512-lNrgdUPpsBWHjrwXy2+Z5nX/Gy5YAvNwFMLqkeMdjzrybwPIalJJN2e+YtkS1I6mVmOMNppF5cv692OAVoI74g==", - "deprecated": "This project has been renamed to @ghostery/adblocker-extended-selectors. Install using @ghostery/adblocker-extended-selectors instead", - "license": "MPL-2.0" - }, "node_modules/@develar/schema-utils": { "version": "2.6.5", "resolved": "https://registry.npmjs.org/@develar/schema-utils/-/schema-utils-2.6.5.tgz", @@ -848,6 +787,32 @@ "@ghostery/adblocker-extended-selectors": "^2.1.1" } }, + "node_modules/@ghostery/adblocker-electron": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@ghostery/adblocker-electron/-/adblocker-electron-2.1.1.tgz", + "integrity": "sha512-UxniR5WD1VR+op0SRiqayJGX1gl4+ZPxuTaUj/2hPnvT4mJ0jY7DOq1YWEgLzSYqDbPRyEu1Bic+uZPhP7Je4g==", + "license": "MPL-2.0", + "dependencies": { + "@ghostery/adblocker": "^2.1.1", + "@ghostery/adblocker-electron-preload": "^2.1.1", + "tldts-experimental": "^6.0.14" + }, + "peerDependencies": { + "electron": ">11" + } + }, + "node_modules/@ghostery/adblocker-electron-preload": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@ghostery/adblocker-electron-preload/-/adblocker-electron-preload-2.1.1.tgz", + "integrity": "sha512-HYqTNZ+usX5uPzjnycxr6P5y+M8yUXXIRSHKBASkzIXASn1M+GXo0CnTOfCHWkhDuiTa9Alo/zCN+d0rtH0BjA==", + "license": "MPL-2.0", + "dependencies": { + "@ghostery/adblocker-content": "^2.1.1" + }, + "peerDependencies": { + "electron": ">11" + } + }, "node_modules/@ghostery/adblocker-extended-selectors": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/@ghostery/adblocker-extended-selectors/-/adblocker-extended-selectors-2.1.1.tgz", @@ -1249,16 +1214,6 @@ "@types/responselike": "^1.0.0" } }, - "node_modules/@types/chrome": { - "version": "0.0.278", - "resolved": "https://registry.npmjs.org/@types/chrome/-/chrome-0.0.278.tgz", - "integrity": "sha512-PDIJodOu7o54PpSOYLybPW/MDZBCjM1TKgf31I3Q/qaEbNpIH09rOM3tSEH3N7Q+FAqb1933LhF8ksUPYeQLNg==", - "license": "MIT", - "dependencies": { - "@types/filesystem": "*", - "@types/har-format": "*" - } - }, "node_modules/@types/debug": { "version": "4.1.12", "resolved": "https://registry.npmjs.org/@types/debug/-/debug-4.1.12.tgz", @@ -1269,27 +1224,6 @@ "@types/ms": "*" } }, - "node_modules/@types/filesystem": { - "version": "0.0.36", - "resolved": "https://registry.npmjs.org/@types/filesystem/-/filesystem-0.0.36.tgz", - "integrity": "sha512-vPDXOZuannb9FZdxgHnqSwAG/jvdGM8Wq+6N4D/d80z+D4HWH+bItqsZaVRQykAn6WEVeEkLm2oQigyHtgb0RA==", - "license": "MIT", - "dependencies": { - "@types/filewriter": "*" - } - }, - "node_modules/@types/filewriter": { - "version": "0.0.33", - "resolved": "https://registry.npmjs.org/@types/filewriter/-/filewriter-0.0.33.tgz", - "integrity": "sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g==", - "license": "MIT" - }, - "node_modules/@types/firefox-webext-browser": { - "version": "120.0.4", - "resolved": "https://registry.npmjs.org/@types/firefox-webext-browser/-/firefox-webext-browser-120.0.4.tgz", - "integrity": "sha512-lBrpf08xhiZBigrtdQfUaqX1UauwZ+skbFiL8u2Tdra/rklkKadYmIzTwkNZSWtuZ7OKpFqbE2HHfDoFqvZf6w==", - "license": "MIT" - }, "node_modules/@types/fs-extra": { "version": "9.0.13", "resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz", @@ -1312,12 +1246,6 @@ "@types/node": "*" } }, - "node_modules/@types/har-format": { - "version": "1.2.16", - "resolved": "https://registry.npmjs.org/@types/har-format/-/har-format-1.2.16.tgz", - "integrity": "sha512-fluxdy7ryD3MV6h8pTfTYpy/xQzCFC7m89nOH9y94cNqJ1mDIDPut7MnRHI3F6qRmh/cT2fUjG1MLdCNb4hE9A==", - "license": "MIT" - }, "node_modules/@types/http-cache-semantics": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", @@ -2932,6 +2860,15 @@ "fs-extra": "^10.1.0" } }, + "node_modules/electron-chrome-context-menu": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/electron-chrome-context-menu/-/electron-chrome-context-menu-1.1.0.tgz", + "integrity": "sha512-Q2sITVT+xkZ3ru/ZGjb0+tZiAXfZ46KNae0nVZdxI/RGqlM+xRcSgpkP3TmUK/Y205Q7Z5d0f4yWzjgsPWIF/Q==", + "license": "MIT", + "peerDependencies": { + "electron": ">=9.0.0" + } + }, "node_modules/electron-chrome-extensions": { "version": "3.10.1", "resolved": "https://registry.npmjs.org/electron-chrome-extensions/-/electron-chrome-extensions-3.10.1.tgz", diff --git a/package.json b/package.json index 27e4b9e..625d442 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,10 @@ "electron-packager": "^17.1.2" }, "dependencies": { - "@cliqz/adblocker-electron": "^1.31.3", "@ghostery/adblocker": "^2.1.1", + "@ghostery/adblocker-electron": "^2.1.1", "cross-fetch": "^3.1.5", + "electron-chrome-context-menu": "^1.1.0", "electron-chrome-extensions": "^3.10.0", "electron-squirrel-startup": "^1.0.1", "electron-tabs": "^1.0.1", diff --git a/renderer.js b/renderer.js index 1e70849..945fac1 100644 --- a/renderer.js +++ b/renderer.js @@ -5,3 +5,5 @@ * `contextIsolation` is turned on. Use the contextBridge API in `preload.js` * to expose Node.js functionality from the main process. */ + +require('electron-chrome-extension/preload'); \ No newline at end of file