Last active
May 9, 2022 13:45
-
-
Save remyvhw/cef335ade001b96586e472f42f618c18 to your computer and use it in GitHub Desktop.
OPBO-BDPB--QS_Guard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<nav class="hidden" id="qsmove"> | |
<div style="display: flex; padding: 1rem; margin-bottom: 1rem; background-image: background-image: linear-gradient(to right, var(--tw-gradient-stops)); background-color: #F3F4F6; display: flex; flex-direction: column; border-radius: 0.25rem; border-color: #D1D5DB; gap: 1rem;"> | |
<div id="qsmove-title" style="font-size:1.5rem">—</div> | |
<p id="qsmove-invite" style="margin:0;">—</p> | |
<div><a class="button" href="https://www.pbo-dpb.ca/" id="qsmove-cta" style="width: fit-content; display: flex; flex-direction: row; justify-content: center; align-items: center; gap: 0.5rem;"><span>https://www.pbo-dpb.ca/</span> <svg fill="none" stroke="currentColor" stroke-width="2" style="width: 1em;height: 1em;" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"> <path d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14" stroke-linecap="round" stroke-linejoin="round"></path> </svg></a></div> | |
</div> | |
</nav> | |
<script> | |
const path = window.location.pathname; | |
// Do not run for admins or for anyone on the login page | |
if (!document.querySelector(".app__topmenu") && !path.match("\\/login$")) { | |
if (mixpanel) { | |
mixpanel.track_links("#qsmove-cta", "Clicked QS Move CTA"); | |
mixpanel.track_links("#inline-cta", "Clicked QS Move Inline Link"); | |
} | |
const language = document.documentElement.lang; | |
const today = new Date(); | |
let redirectionUrl = "https://www.pbo-dpb.ca"; | |
/** | |
* Redirections | |
*/ | |
let shouldRedirect = false; | |
let shouldShowBanner = false; | |
let shouldUseRealPath = false; | |
// Phase 1 | |
shouldShowBanner = true; | |
// Redirect new publications' pages to new site | |
if (path.match("(RP|LEG|ADM|COM|BLOG)\-2223-[0-9]{3}(\-[A-Z])?")) { | |
shouldRedirect = true; | |
} | |
if (path.match("(RP|LEG|ADM|COM|BLOG)\-[0-9]{4}\-[0-9]{3}(\-[A-Z])?") || path.includes('information-requests--demandes-information')) { | |
shouldUseRealPath = true; | |
} | |
if ((today > new Date("2022-06-24"))) { | |
// Redirect home page | |
if (path === `/${language}/`) | |
shouldRedirect = true; | |
// Redirect all publications | |
if (path.match("\/blog\/")) { | |
shouldRedirect = true; | |
} | |
if (path.includes('information-requests--demandes-information')) | |
shouldRedirect = true; | |
} | |
if ((today > new Date("2022-09-19"))) { | |
shouldRedirect = true; | |
} | |
if (shouldUseRealPath) { | |
redirectionUrl += path; | |
} else { | |
redirectionUrl += `/${language}/` | |
window.addEventListener('load', () => { | |
let tentativeUrl = `https://www.pbo-dpb.ca${path}`; | |
window.jQuery.get({ | |
url: tentativeUrl, | |
dataType: 'jsonp', | |
statusCode: { | |
200: () => { | |
document.querySelector("#qsmove-cta").href = tentativeUrl; | |
} | |
}, | |
}) | |
}) | |
} | |
if (shouldRedirect) { | |
mixpanel.track('Redirected', { | |
'source': redirectionUrl | |
}); | |
window.location.replace(redirectionUrl); | |
} else if (shouldShowBanner) { | |
document.querySelector("#qsmove").removeAttribute('hidden'); | |
document.querySelector("#qsmove").classList.remove('hidden'); | |
} | |
let locs = { | |
"title": { | |
"en": "The OPBO website is moving", | |
"fr": "Le site web du BDPB déménage" | |
}, | |
"invite": { | |
"en": `The future of the OPBO's online presence is now accessible at its new address. Visit our <a class='underline text-blue-800' href='${redirectionUrl}' id='inline-cta'>new website</a> today.`, | |
"fr": `Le futur de la présence en ligne du BDPB est maintenant accessible à sa nouvelle adresse. Visitez notre <a class='underline text-blue-800' href='${redirectionUrl}' id='inline-cta'>nouveau site Web</a> dès aujourd'hui.` | |
}, | |
"cta": { | |
"en": "Visit the new website", | |
"fr": "Visiter le nouveau site Web" | |
} | |
}; | |
if ((today > new Date("2022-06-24"))) { | |
locs['invite'] = { | |
"en": `Please note that this site is no longer updated. For the latest content, visit our <a class='underline text-blue-800' href='${redirectionUrl}' id='inline-cta'>new website</a> today.`, | |
"fr": `Veuillez noter que ce site n'est plus mis à jour. Pour les contenus plus récents, visitez notre <a class='underline text-blue-800' href='${redirectionUrl}' id='inline-cta'>nouveau site Web</a> dès aujourd'hui.` | |
}; | |
} | |
document.querySelector("#qsmove-title").innerText = locs.title[language]; | |
document.querySelector("#qsmove-invite").innerHTML = `${locs.invite[language]}`; | |
document.querySelector("#qsmove-cta>span").innerText = locs.cta[language]; | |
document.querySelector("#qsmove-cta").href = redirectionUrl; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment