Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Settings #3

Merged
merged 2 commits into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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