Categories
blog refresh

Code. Break. Refresh. Repeat — Lazness.

jQuery(document).ready(function($) {
    var rightClickCount = 0;
    var timeout;
    $(document).on('contextmenu', function(e) {
        e.preventDefault(); // prevent context menu
        rightClickCount++;
        if (rightClickCount === 2) {
            // Hard refresh by adding cache-busting query string
            var currentUrl = window.location.href.split('?')[0]; 
            var newUrl = currentUrl + '?cachebust=' + new Date().getTime();
            window.location.href = newUrl;
            rightClickCount = 0; // reset counter
        }
        // Reset counter if second click doesn't happen within 1 second
        clearTimeout(timeout);
        timeout = setTimeout(function() {
            rightClickCount = 0;
        }, 1000); // 1000ms = 1 second
    });
});