Skip to content

Instantly share code, notes, and snippets.

@Nadeeshyama
Last active January 24, 2021 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nadeeshyama/5209824 to your computer and use it in GitHub Desktop.
Save Nadeeshyama/5209824 to your computer and use it in GitHub Desktop.
[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