Last active
February 14, 2025 14:53
-
-
Save NickDeckerDevs/187203a001d256beaac2e8b789fa5b06 to your computer and use it in GitHub Desktop.
HubSpot Community Script to force langage to your preferred language, has options for language, number of years before expiration, and a debug mode if you want to log stuff to the console. When someone sends you a link and it is forced language from a url param (or you happen to click on one) this will remove that from the url, and automatically…
This file contains 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
// This can be added as a boost in Arc Browsers for the community by adding this JS | |
// Non Arc Users can use a chrome extension TamperMonkey | |
// I have not ussed this, I only see it show up on stack overflow as solution | |
// https://chromewebstore.google.com/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo | |
// this could also be turned into a chrome extension, but my account is not verfied and I don't know how | |
// to get it to work, so lol if you find this useful and you know how to get a extension account | |
// figured out, let me know! | |
(function() { | |
// set your language code here | |
// en, es, pt-br, fr, de, ja | |
let preferredLanguage = "en" | |
let numberOfYearsBeforeExpiration = 1 | |
let debugMode = false | |
function debugLog(...args) { | |
if (debugMode) { | |
console.log(...args) | |
} | |
} | |
function getCookie(name) { | |
return document.cookie.split('; ').find(row => row.startsWith(name + '='))?.split('=')[1] | |
} | |
let currentLanguage = getCookie('lia.anon.profile.language') | |
debugLog('Current language:', currentLanguage) | |
if (currentLanguage === preferredLanguage) { | |
debugLog('Language already set to preferred value:', preferredLanguage) | |
return | |
} | |
let date = new Date() | |
date.setFullYear(date.getFullYear() + numberOfYearsBeforeExpiration) | |
document.cookie = `lia.anon.profile.language=${preferredLanguage}; path=/; expires=${date.toUTCString()}; Secure; SameSite=None` | |
debugLog('Cookie updated to:', preferredLanguage) | |
let url = new URL(window.location) | |
if (url.searchParams.has('profile.language')) { | |
url.searchParams.delete('profile.language') | |
window.location.replace(url.toString()) | |
} else { | |
location.reload() | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment