Skip to content

Commit e9309b1

Browse files
committed
local counter
1 parent 87f48ff commit e9309b1

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

dist/web-snippets.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,29 @@
455455
soundPhone.volume = 0.1;
456456
document.getElementById('popup-container-img').addEventListener('click', function() {
457457
soundPhone.play();
458-
});</script></body><body class="chamelion"><div class="menu-side-overall-wrapper"><div class="menu-side-wrapper"><img class="side-pix" src="./media/img/code.gif"></div><div class="menu-side-projects-wrapper"><ul>CURRENT PROJECTS<li><a href="https://trackerninja.codeberg.page" target="_blank">RETRO PORTAL</a></li><li><a href="https://behance.net/retrowave88" target="_blank">COMPUTER GRAPHICS</a></li><li><a href="https://www.tiktok.com/@trackerninja808" target="_blank">TRACKER MUSIC</a></li><li><a href="https://stock.adobe.com/contributor/204789995/spacedrone808" target="_blank">ADOBE STOCK</a></li><li><a href="https://freepik.com/author/spacedrone808" target="_blank">FREEPIK STOCK</a></li></ul></div></div><div class="page-wrapper wrapper"><div class="tools-intro">Here you will find various snippets I use in web development. In almost all cases it is HTML/PUG/Javascript/PHP. Quite young section, so not so much stuff going on here, but will be updated in upcoming future for sure.</div><div class="batch-title">WEBPAGE REDIRECTS IF SCREEN WIDTH IS LESS THAN</div><div class="crt-container"><pre class="crt-text">document.addEventListener('DOMContentLoaded', () => {
458+
});</script></body><body class="chamelion"><div class="menu-side-overall-wrapper"><div class="menu-side-wrapper"><img class="side-pix" src="./media/img/code.gif"></div><div class="menu-side-projects-wrapper"><ul>CURRENT PROJECTS<li><a href="https://trackerninja.codeberg.page" target="_blank">RETRO PORTAL</a></li><li><a href="https://behance.net/retrowave88" target="_blank">COMPUTER GRAPHICS</a></li><li><a href="https://www.tiktok.com/@trackerninja808" target="_blank">TRACKER MUSIC</a></li><li><a href="https://stock.adobe.com/contributor/204789995/spacedrone808" target="_blank">ADOBE STOCK</a></li><li><a href="https://freepik.com/author/spacedrone808" target="_blank">FREEPIK STOCK</a></li></ul></div></div><div class="page-wrapper wrapper"><div class="tools-intro">Here you will find various snippets I use in web development. In almost all cases it is HTML/PUG/Javascript/PHP. Quite young section, so not so much stuff going on here, but will be updated in upcoming future for sure.</div><div class="batch-title">LOCAL STORAGE COUNTER</div><div class="crt-container"><pre class="crt-text">//Injecting data into div with id="counter"
459+
460+
// Start counting from 1
461+
const INITIAL_COUNT = 1;
462+
463+
// Get current count from localStorage or initialize it
464+
let count = localStorage.getItem('hitCount');
465+
466+
if (count === null) {
467+
// First visit
468+
count = INITIAL_COUNT;
469+
} else {
470+
// Parse and increment
471+
count = parseInt(count, 10) + 1;
472+
}
473+
474+
// Save updated count back to localStorage
475+
localStorage.setItem('hitCount', count);
476+
477+
// Display the count
478+
document.getElementById('counter').textContent = count.toLocaleString();
479+
480+
</pre><button class="copy-button" aria-label="Copy code to clipboard">Copy</button></div><div class="batch-title">WEBPAGE REDIRECTS IF SCREEN WIDTH IS LESS THAN</div><div class="crt-container"><pre class="crt-text">document.addEventListener('DOMContentLoaded', () => {
459481
if (isNoMobilePage()) return;
460482
checkScreenSize();
461483
window.addEventListener('resize', checkScreenSize);

src/web-snippets.pug

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ block main
88
.page-wrapper.wrapper
99
.tools-intro Here you will find various snippets I use in web development. In almost all cases it is HTML/PUG/Javascript/PHP. Quite young section, so not so much stuff going on here, but will be updated in upcoming future for sure.
1010

11+
.batch-title LOCAL STORAGE COUNTER
12+
.crt-container
13+
pre.crt-text.
14+
15+
//Injecting data into div with id="counter"
16+
17+
// Start counting from 1
18+
const INITIAL_COUNT = 1;
19+
20+
// Get current count from localStorage or initialize it
21+
let count = localStorage.getItem('hitCount');
22+
23+
if (count === null) {
24+
// First visit
25+
count = INITIAL_COUNT;
26+
} else {
27+
// Parse and increment
28+
count = parseInt(count, 10) + 1;
29+
}
30+
31+
// Save updated count back to localStorage
32+
localStorage.setItem('hitCount', count);
33+
34+
// Display the count
35+
document.getElementById('counter').textContent = count.toLocaleString();
36+
37+
38+
button.copy-button(aria-label="Copy code to clipboard") Copy
39+
1140
.batch-title WEBPAGE REDIRECTS IF SCREEN WIDTH IS LESS THAN
1241
.crt-container
1342
pre.crt-text.

0 commit comments

Comments
 (0)