Skip to content

Instantly share code, notes, and snippets.

@dreamyguy
Last active April 5, 2019 08:05
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 dreamyguy/e5faa4cb2a64ee9bff50675918fd9b88 to your computer and use it in GitHub Desktop.
Save dreamyguy/e5faa4cb2a64ee9bff50675918fd9b88 to your computer and use it in GitHub Desktop.
Visualising margins for UX Debugging [8 of 8]
function getUrlParam(param, url) {
let theUrl = url;
if (!url) {
theUrl = location.href;
}
const theParam = param.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
const regexLogic = `[\\?&]${theParam}=([^&#]*)`;
const regex = new RegExp(regexLogic);
const results = regex.exec(theUrl);
return results === null ? null : results[1];
}
function addWrapperClassIfUrlParam(wrapperClass, param) {
const b = document.querySelector('body');
// Only proceed if 'body' is found on the page
if (b !== null) {
if (getUrlParam(param)) {
b.classList.add(wrapperClass);
}
}
}
document.addEventListener('DOMContentLoaded', () => {
addWrapperClassIfUrlParam('show-helpers', 'helpers');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment