Skip to content

Instantly share code, notes, and snippets.

@Nadeeshyama
Last active Jan 24, 2021
Embed
What would you like to do?
[Set Debug Mode] Set the URL hash in the format '#debug-ddmmyyyy' to set a global variable __DEBUG__ #URL #Hash
/**
* Set the URL hash in the format '#debug-ddmmyyyy' to set a global
* variable __DEBUG__ so that it can be used across all scritps to
* do console outputs, legacy alerts, etc.
*/
var __DEBUG__ = (function() {
var pad = function (s) {return (s.length == 1 ? '0' + s : s)}, // to pad numbers with leading 0s
t = new Date(),
y = t.getFullYear().toString(),
m = pad((t.getMonth() + 1).toString()), // month is index returned in JS :)
d = pad(t.getDate().toString()),
hash = window.location.hash.replace('#', ''); // hash with cross browser compatibility
return ((d + m + y) === hash.replace('debug-', ''));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment