hedgedoc/public/js/locale.js
David Mehren e77e7b165a
Set all cookies with sameSite: strict
Modern browsers do not support (or will stop supporting) sameSite: none (or no sameSite attribute) without the Secure flag. As we don't want everyone to be able to make requests with our cookies anyway, this commit sets sameSite to strict. See https://developer.mozilla.org/de/docs/Web/HTTP/Headers/Set-Cookie/SameSite

Signed-off-by: David Mehren <dmehren1@gmail.com>
2020-06-08 15:27:31 +02:00

32 lines
876 B
JavaScript

/* eslint-env browser, jquery */
/* global Cookies */
var lang = 'en'
var userLang = navigator.language || navigator.userLanguage
var userLangCode = userLang.split('-')[0]
var locale = $('.ui-locale')
var supportLangs = []
$('.ui-locale option').each(function () {
supportLangs.push($(this).val())
})
if (Cookies.get('locale')) {
lang = Cookies.get('locale')
if (lang === 'zh') {
lang = 'zh-TW'
}
} else if (supportLangs.indexOf(userLang) !== -1) {
lang = supportLangs[supportLangs.indexOf(userLang)]
} else if (supportLangs.indexOf(userLangCode) !== -1) {
lang = supportLangs[supportLangs.indexOf(userLangCode)]
}
locale.val(lang)
$('select.ui-locale option[value="' + lang + '"]').attr('selected', 'selected')
locale.change(function () {
Cookies.set('locale', $(this).val(), {
expires: 365,
sameSite: 'strict'
})
window.location.reload()
})