From cd9b9fd31fffaf6a27305b9cdb86f1bb98b38b89 Mon Sep 17 00:00:00 2001 From: dousha Date: Mon, 20 Sep 2021 14:05:00 +0800 Subject: [PATCH] Remember preferred programming language --- src/pages/oj/views/problem/Problem.vue | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/pages/oj/views/problem/Problem.vue b/src/pages/oj/views/problem/Problem.vue index 30a03d49e..6c87452d4 100644 --- a/src/pages/oj/views/problem/Problem.vue +++ b/src/pages/oj/views/problem/Problem.vue @@ -298,7 +298,18 @@ return } // try to load problem template - this.language = this.problem.languages[0] + if (window.localStorage) { + const preferredLanguage = window.localStorage.getItem('preferredLang') + if (preferredLanguage) { + if (this.problem.languages.indexOf(preferredLanguage) >= 0) { + this.language = preferredLanguage + } else { + this.language = this.problem.languages[0] + } + } + } else { + this.language = this.problem.languages[0] + } let template = this.problem.template if (template && template[this.language]) { this.code = template[this.language] @@ -353,6 +364,9 @@ } } this.language = newLang + if (window.localStorage) { + window.localStorage.setItem('preferredLang', newLang) + } }, onChangeTheme (newTheme) { this.theme = newTheme