1 import { ajax
} from "./utils/ajax";
2 import { getRandString
} from "./utils/alea";
3 import params
from "./parameters"; //for socket connection
16 ajax("/variants", "GET", res
=> { this.state
.variants
= res
.variantArray
; });
19 name: "", //"anonymous"
20 email: "", //unknown yet
21 notify: false, //email notifications
22 sid: localStorage
["mysid"] || getRandString(),
24 ajax("/whoami", "GET", res
=> {
27 this.state
.user
.id
= res
.id
;
28 this.state
.user
.name
= res
.name
;
29 this.state
.user
.email
= res
.email
;
30 this.state
.user
.notify
= res
.notify
;
33 this.state
.conn
= new WebSocket(params
.socketUrl
+ "/?sid=" + this.state
.user
.sid
);
34 // Settings initialized with values from localStorage
35 this.state
.settings
= {
36 bcolor: localStorage
["bcolor"] || "lichess",
37 sound: parseInt(localStorage
["sound"]) || 2,
38 hints: parseInt(localStorage
["hints"]) || 1,
39 coords: !!eval(localStorage
["coords"]),
40 highlight: !!eval(localStorage
["highlight"]),
41 sqSize: parseInt(localStorage
["sqSize"]),
43 const socketCloseListener
= () => {
44 this.state
.conn
= new WebSocket(params
.socketUrl
+ "/?sid=" + mysid
);
46 this.state
.conn
.onclose
= socketCloseListener
;
47 const supportedLangs
= ["en","es","fr"];
48 this.state
.lang
= localStorage
["lang"] ||
49 supportedLangs
.includes(navigator
.language
)
52 this.setTranslations();
54 setTranslations: async
function() {
55 // Import translations from "./translations/$lang.js"
56 const tModule
= await
import("@/translations/" + this.state
.lang
+ ".js");
57 this.state
.tr
= tModule
.translations
;
60 this.state
.lang
= lang
;
61 this.setTranslations();