CLICK'N'DRAG TO MOVE

Whatever it takes to testbed!

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.
LOCAL STORAGE COUNTER
//Injecting data into div with id="counter"  

// Start counting from 1
const INITIAL_COUNT = 1;

// Get current count from localStorage or initialize it
let count = localStorage.getItem('hitCount');

if (count === null) {
  // First visit
  count = INITIAL_COUNT;
} else {
  // Parse and increment
  count = parseInt(count, 10) + 1;
}

// Save updated count back to localStorage
localStorage.setItem('hitCount', count);

// Display the count
document.getElementById('counter').textContent = count.toLocaleString();

WEBPAGE REDIRECTS IF SCREEN WIDTH IS LESS THAN
document.addEventListener('DOMContentLoaded', () => {
    if (isNoMobilePage()) return; 
    checkScreenSize();
    window.addEventListener('resize', checkScreenSize);
});

function isNoMobilePage() {
    return window.location.pathname === '/no-mobile.html'; 
}

function checkScreenSize() {
    if (window.innerWidth < 1680 && !isNoMobilePage()) {
        window.location.href = '/no-mobile.html';
    }
}
BLOCKS ANY ZOOM ATTEMPTS COMING FROM TOUCH INTERFACE
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">

document.addEventListener("touchmove", function(event){
    event.preventDefault();
}, { passive: false });


window.addEventListener('gesturestart', function(e) {
    e.preventDefault(); 
});

window.addEventListener('gesturechange', function(e) {
    e.preventDefault(); 
});

window.addEventListener('contextmenu', function(e) {
    e.preventDefault(); 
});

INJECT REPEATED MARKUP BLOCKS VIA JAVASCRIPT


document.addEventListener('DOMContentLoaded', function() {
    fetch('./includes/footer.html')
        .then(response => response.text())
        .then(data => {
            document.querySelector('.').innerHTML = data;
        });
});
RESTRICT INPUT TO NUMERIC KEYS ONLY
<input class="selection__items-input selection__items-input--connect" type="tel" name="phone" id="phone" placeholder="8 (980) 980-60-94" required oninput="validateNumericInput(this)" pattern="[0-9]*" inputmode="numeric" maxlength="11">


function validateNumericInput(input) {
    input.value = input.value.replace(/[^0-9]/g, '');
}
RESET REFOX & SUPERMIUM CACHES
@echo off
taskkill /IM chrome.exe /F >nul 2>&1 || echo Chrome is not running
taskkill /IM r3dfox.exe /F >nul 2>&1 || echo Firefox is not running
timeout /t 2 /nobreak >nul
rmdir /s /q "C:\Users\user\AppData\Local\Supermium\User Data\Default\Code Cache"
rmdir /s /q "C:\Users\user\AppData\Local\Supermium\User Data\Default\Cache"
start "" "C:\Program Files\Supermium\chrome.exe"

rmdir /s /q "C:\Users\user\AppData\Local\Eclipse Community\r3dfox\Profiles\na8ow4wf.default-default-1\cache2"
start "" "%ProgramFiles%\Eclipse Community\r3dfox\r3dfox.exe"
RESTARTS APACHE & POSTGRES SERVICES
net stop "Apache2.4"
ping -n 2 localhost > nul
net stop "PostgreSQL 14"
ping -n 2 localhost > nul
net start "Apache2.4"
ping -n 2 localhost > nul
net start "PostgreSQL 14"
KILL VIRTUALBOX LEFTOVERS
taskkill /im VirtualBox.exeVM /t /f
taskkill /im VirtualBox.exe /t /f
taskkill /im VBoxSDS.exe /t /f
taskkill /im VBoxSVC.exe /t /f
MORE SNIPPETS TO COME!
HOLD YER HORSERS WEB SURFER, MORE SNIPPETS TO COME IN A WHILE!