Add files via upload

This commit is contained in:
NodeMixaholic 2023-03-03 08:30:52 -06:00 committed by GitHub
parent af141833ad
commit 3c1bfc75ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 13 deletions

View file

@ -33,4 +33,4 @@ function clickPress(keyEvent) {
if (keyEvent.keyCode == 13) { if (keyEvent.keyCode == 13) {
go() go()
} }
} }

58
main.js
View file

@ -1,8 +1,7 @@
// Modules to control application life and create native browser window // Modules to control application life and create native browser window
const {app, BrowserWindow} = require('electron') const {app, BrowserWindow, session} = require('electron')
const path = require('path') const path = require('path')
const fetchr = require("cross-fetch") const fetch = require("cross-fetch")
const { ElectronBlocker, fullLists, Requests } = require('@cliqz/adblocker-electron')
function createWindow () { function createWindow () {
@ -16,17 +15,56 @@ function createWindow () {
} }
}) })
ElectronBlocker.fromPrebuiltAdsAndTracking(fetchr).then((blocker) => {
blocker.enableBlockingInSession(mainWindow.webContents.defaultSession).catch(() => { const toBlock = [
console.log("Blocker reported an error while init.") "*://*.doubleclick.net/*",
}) "*://partner.googleadservices.com/*",
}); "*://*.googlesyndication.com/*",
"*://*.google-analytics.com/*",
"*://creative.ak.fbcdn.net/*",
"*://*.adbrite.com/*",
"*://*.exponential.com/*",
"*://*.quantserve.com/*",
"*://*.scorecardresearch.com/*",
"*://*.zedo.com/*",
"*://*.a-ads.com/*",
"*://*.777partner.com/*",
"*://*.77tracking.com/*",
"*://*.abc-ads.com/*",
"*://*.aaxads.com/*",
"*://*.adizio.com/*",
"*://*.adjix.com/*",
"*://*.adjug.com/*",
"*://*.adjuggler.com/*",
"*://*.trafficjunky.net/*",
"*://*.trafficleader.com/*",
"*://*.trafficrouter.io/*"
]
function containsAD(url) {
var i;
for (i = 0; i < toBlock.length; i++) {
regex = toBlock[i].replace(/\*/g, "[^ ]*");
if (url.match(regex)) {
return true;
}
}
return false;
}
session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
if(/api\/v\d\/science$/g.test(details.url) || containsAD(details.url)) {
return callback({cancel: true})
}
return callback({})
})
// and load the index.html of the app. // and load the index.html of the app.
mainWindow.loadFile('index.html') mainWindow.loadFile('index.html')
// Open the DevTools. // Open the DevTools.
// mainWindow.webContents.openDevTools() mainWindow.webContents.openDevTools()
} }
// This method will be called when Electron has finished // This method will be called when Electron has finished
@ -50,4 +88,4 @@ app.on('window-all-closed', function () {
}) })
// In this file you can include the rest of your app's specific main process // In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here. // code. You can also put them in separate files and require them here.

View file

@ -27,8 +27,6 @@
"electron": "^23.1.0" "electron": "^23.1.0"
}, },
"dependencies": { "dependencies": {
"@cliqz/adblocker": "^1.26.2",
"@cliqz/adblocker-electron": "^1.26.2",
"cross-fetch": "^3.1.5", "cross-fetch": "^3.1.5",
"electron-squirrel-startup": "^1.0.0", "electron-squirrel-startup": "^1.0.0",
"electron-tabs": "^1.0.1" "electron-tabs": "^1.0.1"