Skip to content

Commit

Permalink
V1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadPackets committed Apr 29, 2018
1 parent 197a530 commit a3a8f13
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 12 deletions.
25 changes: 24 additions & 1 deletion content.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const tweaks = {
} else {
if (!items.hideAUSHeader) {
$('<iframe src="/top.htm" style="height: 85px; width: 100vw; position: relative; left: 50%; right: 50%; margin-left: -50vw; margin-right: -50vw;" name="topFrame" scrolling="NO" noresize=""></iframe>').prependTo('body');
if (items.blockAUSImages) {
setTimeout(() => {
let frame = $(document.getElementsByName('topFrame')[0].contentWindow.document);
$(frame).find('img').attr('src', 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
}, 350)
}
}
}
},
Expand Down Expand Up @@ -81,10 +87,27 @@ const tweaks = {
blockAUSImages: () => {
if (document.getElementsByName('mainFrame')[0] !== undefined) {
let frame = $(document.getElementsByName('mainFrame')[0].contentWindow.document);
$(frame).attr('src', 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
$(frame).find('img').attr('src', 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
} else {
$('img').attr('src', 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
}

if (document.getElementsByName('topFrame')[0] !== undefined) {
let frame = $(document.getElementsByName('topFrame')[0].contentWindow.document);
$(frame).find('img').attr('src', 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');
}
},
disableAutoRefresh: () => {
return true;
},
preventInactive: () => {
if (document.getElementsByName('mainFrame')[0] !== undefined) {
console.error('Prevent Inactive Login is not supported without Persistent Login enabled.');
} else {
setTimeout(() => {
location.reload();
}, 300000)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "BannerPlus",
"description": "Makes banner better.",
"version": "0.1",
"version": "1.2",
"icons": {
"128": "assets/icons/128.png"
},
Expand Down
16 changes: 15 additions & 1 deletion popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
height: 100%;
}

html {
overflow: auto;
}

.mainTitle {
padding: none;
font-size: 40px;
Expand Down Expand Up @@ -202,14 +206,18 @@
</head>

<body>
<h1 class="mainTitle">Banner+</h1>
<h1 class="mainTitle">Banner+<version style="font-size: 12px;"></version></h1>
<hr />
<div id="container" class="container justify-content-center">
<h3>Tweaks</h3>
<div class="optionDiv">
<span class="optionText">Persistent Login</span>
<input type="checkbox" name="persistentLogin" class="checkbox-switch" />
</div>
<div class="optionDiv">
<span class="optionText">Prevent Inactive Logout</span>
<input type="checkbox" name="preventInactive" class="checkbox-switch" />
</div>
<div class="optionDiv">
<span class="optionText">Big Titles</span>
<input type="checkbox" name="bigTitles" class="checkbox-switch" />
Expand Down Expand Up @@ -250,6 +258,12 @@ <h3>Auto Login</h3>
<span class="optionText">Password: </span>
<input class="autoInput" type="password" name="password" />
</div>
<hr />
<h3>Settings</h3>
<div class="optionDiv">
<span class="optionText">Disable Auto Refresh</span>
<input type="checkbox" name="disableAutoRefresh" class="checkbox-switch" />
</div>
<br />
</div>

Expand Down
54 changes: 47 additions & 7 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function checkAutoLogin(value, cb) {
}
}

function clickSwitch(name, currentValue) {
function clickSwitch(name, currentValue, tab) {

if (name == 'autoLogin') {
checkAutoLogin(currentValue, () => {
Expand All @@ -51,12 +51,22 @@ function clickSwitch(name, currentValue) {
let data = {};
data[name] = currentValue;
chrome.storage.local.set(data);

chrome.storage.local.get(['disableAutoRefresh'], (result) => {
if (result.disableAutoRefresh !== true) {
chrome.tabs.reload(tab.id, {
bypassCache: true
});
}
})

}
}

function initializeSwitches(tab) {
$('.checkbox-switch').each((i, item) => {
let name = $(item).attr('name');

if (name == 'autoLogin') {
chrome.storage.sync.get(['username', 'password'], (result) => {
$('[name="username"]').val(result.username);
Expand All @@ -70,15 +80,15 @@ function initializeSwitches(tab) {
size: 'default',
checked: true,
onChange: (value) => {
clickSwitch(name, value);
clickSwitch(name, value, tab);
}
});
} else {
new Switch(item, {
size: 'default',
checked: false,
onChange: (value) => {
clickSwitch(name, value);
clickSwitch(name, value, tab);
}
});
}
Expand All @@ -90,11 +100,16 @@ function checkForUpdates() {
fetch(chrome.extension.getURL('version.json'))
.then((response) => {
response.json().then((json) => {
//Set current version
$('version').text("(v" + json.version + ")");

fetch('https://raw.githubusercontent.com/DeadPackets/BannerPlus/master/version.json')
.then((responseGit) => {
responseGit.json().then((jsonGit) => {
if (parseFloat(jsonGit.version) > parseFloat(json.version)) {
let content = jsonGit.changelog.map((item) => {return (" - " + item);})
let content = jsonGit.changelog.map((item) => {
return (" - " + item);
})
content = content.join("\n");
swal({
title: `New Update! (v${jsonGit.version})`,
Expand All @@ -103,7 +118,7 @@ function checkForUpdates() {
}).then((value) => {
//If they picked to update
if (value) {
window.open('https://github.com/DeadPackets/BannerPlus/releases/latest');
window.open('https://github.com/DeadPackets/BannerPlus/releases/latest');
}
})
}
Expand All @@ -113,11 +128,36 @@ function checkForUpdates() {
});
}

function displayDisclaimer(cb) {
chrome.storage.local.get(['agreeToServeSatan'], (result) => {
if (result.agreeToServeSatan) {
cb();
} else {
swal({
title: `Disclaimer`,
text: `By using BannerPlus, you acknowledge that you are fully responsible for the usage of this extension and all actions that may entail using it.`,
type: 'warning',
buttons: ['No thanks', 'I understand']
}).then((value) => {
//If they picked to update
if (value) {
chrome.storage.local.set({agreeToServeSatan: true})
cb();
} else {
window.close();
}
})
}
})
}

document.addEventListener('DOMContentLoaded', () => {
getCurrentTabUrl((tab) => {
if (tab.url.indexOf('banner.aus.edu') > -1) {
initializeSwitches(tab);
checkForUpdates();
displayDisclaimer(() => {
initializeSwitches(tab);
checkForUpdates();
})
} else {
swal({
title: 'Sorry!',
Expand Down
4 changes: 2 additions & 2 deletions version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.0",
"changelog": ["Added an actual logo", "Fixed incorrect titles", "Huge improvement on blocking images (still in beta though)"]
"version": "1.2",
"changelog": ["Added auto refresh for tweaks", "Added a tweak to prevent auto logout from banner", "Fixed blocking tweaks not working properly on windows", "Added disclaimer note"]
}

0 comments on commit a3a8f13

Please sign in to comment.