Skip to content

Instantly share code, notes, and snippets.

@t-laird
Created February 20, 2018 01:05
Show Gist options
  • Save t-laird/d4d1860f7eece8b04bfb4cc610bb4303 to your computer and use it in GitHub Desktop.
Save t-laird/d4d1860f7eece8b04bfb4cc610bb4303 to your computer and use it in GitHub Desktop.
var segmentCount = 0;
var l = window.location;
const nonHomeUrls = ['/snap-ninja', '/Headcount', '/comp-3', '/Centipede'];
for (let i = 0; i < nonHomeUrls.length; i++) {
const urlRegex = new RegExp(nonHomeUrls[i], 'i');
const verifyUrl = urlRegex.test(l.pathname);
if (!verifyUrl) {
l.replace(
l.protocol + '//' + l.hostname + (l.port ? ':' + l.port : '') +
l.pathname.split('/').slice(0, 1 + segmentCount).join('/') + '/?p=/' +
l.pathname.slice(1).split('/').slice(segmentCount).join('/').replace(/&/g, '~and~') +
(l.search ? '&q=' + l.search.slice(1).replace(/&/g, '~and~') : '') +
l.hash
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment