Skip to content

Commit

Permalink
Merge pull request #3 from MsMaciek123/master
Browse files Browse the repository at this point in the history
Fixed Settings
  • Loading branch information
raluvy95 committed Oct 11, 2020
2 parents 6a76379 + 5a29b2f commit b759a0d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 26 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
package-lock.json
.gitignore
1 change: 1 addition & 0 deletions runfornonglobalelectron.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node node_modules/electron/cli.js .
8 changes: 1 addition & 7 deletions settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
{
"adblock": {
"enable": true,
"ignoreWeb": ["https://www.google.com"]
},
"darkmode": true
}
{"adblock":{"enable":false,"ignoreWeb":["https://www.google.com"]},"darkmode":true}
33 changes: 24 additions & 9 deletions views/script/settings.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
const settings = require("./../settings.json")
const fs = require("fs")
const path = require("path")

/* load */
function load()
{
document.getElementById("aden").checked = settings.adblock.enable;
refreshIgnoreWeb();
}

window.addEventListener('load', load())

function refreshIgnoreWeb()
{
if(settings.adblock.ignoreWeb.length > 0)
document.getElementById("adig").setAttribute("value", settings.adblock.ignoreWeb.join(", "))
else
document.getElementById("adig").setAttribute("value", '')
}

function clear() {
const {remote} = require("electron")
const cleaning = remote.getCurrentWebContents().session
Expand All @@ -14,21 +33,17 @@ document.getElementById("close").addEventListener("click", () => {
win.close()
})
document.getElementById("aden").addEventListener("click", () => {
settings.adblock.enable = false
fs.writeFileSync(__dirname + "/../../settings.json", settings)
settings.adblock.enable = document.getElementById("aden").checked
fs.writeFileSync(path.join(__dirname, "/../settings.json"), JSON.stringify(settings))
refreshIgnoreWeb()
})
if(settings.adblock.enable) {
document.getElementById("aden").setAttribute("checked", '')
if(settings.adblock.ignoreWeb.length > 0) {
document.getElementById("adig").setAttribute("value", settings.adblock.ignoreWeb.join(", "))
}
}

document.getElementsByTagName("body")[0].addEventListener("unload", () => {
const modify = document.getElementById("adig").getAttribute("value")
if(!modify) return
else {
settings.adblock.ignoreWeb = modify.split(", ")
fs.writeFileSync(__dirname + "/../../settings.json", settings)
fs.writeFileSync(path.join(__dirname, "/../settings.json"), JSON.stringify(settings))
}
})

2 changes: 1 addition & 1 deletion views/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ <h1>AdBlock</h1>
<button id="close">OK</button>
<script src="./script/settings.js"></script>
</body>
</html>
</html>
20 changes: 11 additions & 9 deletions windows/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ const createWindow = async (child) => {
win.maximize()
win.loadURL('file://' + __dirname + '/../views/index.html')
let blocker
if(settings.adblock.enable) {
blocker = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch)
}
//if(settings.adblock.enable) {
blocker = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch)
//}
win.on('app-command', (e, cmd, query) => {
if (cmd === 'browser-backward' && win.webContents.canGoBack()) {
win.webContents.goBack()
Expand All @@ -89,11 +89,13 @@ const createWindow = async (child) => {
win.webContents.on('did-finish-load', async () => {
const url = win.webContents.getURL()
const title = win.webContents.getTitle()
if(settings.adblock.ignoreWeb.find(m => m.includes(url))) {
blocker.disableBlockingInSession(session.defaultSession)
} else {
blocker.enableBlockingInSession(session.defaultSession);
}
if(settings.adblock.enable) {
if(settings.adblock.ignoreWeb.find(m => m.includes(url))) {
blocker.disableBlockingInSession(session.defaultSession)
} else {
blocker.enableBlockingInSession(session.defaultSession);
}
}
if(title == "Felida Browser") {
win.setTitle("Felida Browser")
} else {
Expand Down Expand Up @@ -217,4 +219,4 @@ const createWindow = async (child) => {
})
}

module.exports = createWindow
module.exports = createWindow

0 comments on commit b759a0d

Please sign in to comment.