mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
e77e7b165a
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>
32 lines
876 B
JavaScript
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()
|
|
})
|