Skip to content

Commit

Permalink
updated to version 13, fixed some security issues
Browse files Browse the repository at this point in the history
  • Loading branch information
samolukadjo committed Jan 11, 2024
1 parent 2b9f574 commit e543fd3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 50 deletions.
57 changes: 29 additions & 28 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<meta name="theme-color" content="#004A77" />
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="manifest" href="/manifest.json?ver=11" />
<link rel="stylesheet" href="style.css?ver=11">
<link rel="manifest" href="/manifest.json?ver=13" />
<link rel="stylesheet" href="style.css?ver=13">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
<style>
@font-face {
Expand All @@ -18,10 +18,11 @@
}
</style>
<title>Calculator</title>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-7L6QCG2RPD"></script>
<script>

<!-- Google tag (gtag.js) -->
<script async
src="https://www.googletagmanager.com/gtag/js?id=G-7L6QCG2RPD"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
Expand All @@ -33,29 +34,29 @@
<div class="container">
<div class="display" id="display">0</div>
<div class="buttons">
<div class="button clear" onclick="clearDisplay()">C</div>
<div class="button" onclick="appendDisplay('(')">(</div>
<div class="button" onclick="appendDisplay(')')">)</div>
<div class="button" onclick="appendDisplay('/')">÷</div>
<div class="button" onclick="appendDisplay('7')">7</div>
<div class="button" onclick="appendDisplay('8')">8</div>
<div class="button" onclick="appendDisplay('9')">9</div>
<div class="button" onclick="appendDisplay('*')">×</div>
<div class="button" onclick="appendDisplay('4')">4</div>
<div class="button" onclick="appendDisplay('5')">5</div>
<div class="button" onclick="appendDisplay('6')">6</div>
<div class="button" onclick="appendDisplay('-')">-</div>
<div class="button" onclick="appendDisplay('1')">1</div>
<div class="button" onclick="appendDisplay('2')">2</div>
<div class="button" onclick="appendDisplay('3')">3</div>
<div class="button" onclick="appendDisplay('+')">+</div>
<div class="button clear" onclick="appendDisplay('Del')">
<img class="symbol" src="back.svg"></div>
<div class="button zero" onclick="appendDisplay('0')">0</div>
<div class="button" onclick="appendDisplay('.')">.</div>
<div class="button equal" onclick="evaluateDisplay(); errorSetting()">=</div>
<div id="button-clear" class="button clear">C</div>
<div class="button append" data-purpose="(">(</div>
<div class="button append" data-purpose=")">)</div>
<div class="button append" data-purpose="/">÷</div>
<div class="button append" data-purpose="7">7</div>
<div class="button append" data-purpose="8">8</div>
<div class="button append" data-purpose="9">9</div>
<div class="button append" data-purpose="*">×</div>
<div class="button append" data-purpose="4">4</div>
<div class="button append" data-purpose="5">5</div>
<div class="button append" data-purpose="6">6</div>
<div class="button append" data-purpose="-">-</div>
<div class="button append" data-purpose="1">1</div>
<div class="button append" data-purpose="2">2</div>
<div class="button append" data-purpose="3">3</div>
<div class="button append" data-purpose="+">+</div>
<div class="button clear" data-purpose="Del">
<img class="symbol" src="back.svg"></div>
<div class="button zero append" data-purpose="0">0</div>
<div class="button append" data-purpose=".">.</div>
<div id="button-equal" class="button equal">=</div>
</div>
</div>
<script src="/script.js?ver=11"></script>
<script src="/script.js?ver=13"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"short_name": "Calculator",
"display_override": ["window-controls-overlay"],
"display": "standalone",
"version": "11.0",
"version_name": "11 realese",
"version": "13.0",
"version_name": "13 realese",
"categories": ["productivity", "utilities"],
"description": "A simple and modern calculator PWA web app.",
"start_url": "/index.html?ver=10",
"start_url": "/index.html?ver=13",
"theme_color": "#004A77",
"background_color": "#000",
"scope": "/",
Expand Down
54 changes: 37 additions & 17 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
navigator.serviceWorker && navigator.serviceWorker.register('/sw.js?ver=11').then(function (registration) {
navigator.serviceWorker && navigator.serviceWorker.register('/sw.js?ver=13').then(function (registration) {
console.log('Excellent, registered with scope: ', registration.scope);
});

let display = document.getElementById("display");
var errSetting = 0;
const display = document.getElementById("display");
const buttons = document.querySelectorAll(".append");
const buttonClear = document.getElementById("button-clear");
const buttonEqual = document.getElementById("button-equal");
let errSetting = 0;
let counter = 0;
const version = 11;
const version = 13;

buttons.forEach(item => {
let val = item.dataset.purpose;
console.log("Loading: " + val);
item.addEventListener('click', function(){
appendDisplay(val)
})
})

buttonClear.addEventListener('click', function(){
clearDisplay()
})

buttonEqual.addEventListener('click', function(){
evaluateDisplay();
errorSetting();
})

function errorSetting() {
counter++;
Expand Down Expand Up @@ -54,19 +74,19 @@ function checkForUpdates() {
console.log("Checking for updates 1/2");
if ('serviceWorker' in navigator) {
console.log("Checking for updates 2/2");
navigator.serviceWorker.register('/sw.js?ver=11').then((registration) => {
const storedVersion = localStorage.getItem('sw-version');
if (storedVersion !== version) {
console.log("Installing updates.");
registration.update();
localStorage.setItem('sw-version', version);
console.log("Updates installed.");
} else {
console.log("No updates found.");
}
}).catch((error) => {
console.error('Error installing update, Error registering service worker:', error);
});
navigator.serviceWorker.register('/sw.js?ver=13').then((registration) => {
const storedVersion = localStorage.getItem('sw-version');
if (storedVersion !== version) {
console.log("Installing updates.");
registration.update();
localStorage.setItem('sw-version', version);
console.log("Updates installed.");
} else {
console.log("No updates found.");
}
}).catch((error) => {
console.error('Error installing update, Error registering service worker:', error);
});
}
}

Expand Down
4 changes: 2 additions & 2 deletions sw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Choose a cache name
const cacheName = 'cache-v10';
const version = 11;
const cacheName = 'cache-v13';
const version = 13;
// List the files to precache
const precacheResources = [
'/',
Expand Down

0 comments on commit e543fd3

Please sign in to comment.