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
; });
18 id: localStorage
["myuid"] || 0,
19 name: localStorage
["myname"] || "", //"anonymous"
20 sid: localStorage
["mysid"] || getRandString(),
22 this.state
.conn
= new WebSocket(params
.socketUrl
+ "/?sid=" + this.state
.user
.sid
);
23 // Settings initialized with values from localStorage
24 this.state
.settings
= {
25 bcolor: localStorage
["bcolor"] || "lichess",
26 sound: parseInt(localStorage
["sound"]) || 2,
27 hints: parseInt(localStorage
["hints"]) || 1,
28 coords: !!eval(localStorage
["coords"]),
29 highlight: !!eval(localStorage
["highlight"]),
30 sqSize: parseInt(localStorage
["sqSize"]),
32 const socketCloseListener
= () => {
33 this.state
.conn
= new WebSocket(params
.socketUrl
+ "/?sid=" + mysid
);
35 this.state
.conn
.onclose
= socketCloseListener
;
36 const supportedLangs
= ["en","es","fr"];
37 this.state
.lang
= localStorage
["lang"] ||
38 supportedLangs
.includes(navigator
.language
)
41 this.setTranslations();
43 setTranslations: async
function() {
44 // Import translations from "./translations/$lang.js"
45 const tModule
= await
import("@/translations/" + this.state
.lang
+ ".js");
46 this.state
.tr
= tModule
.translations
;
49 this.state
.lang
= lang
;
50 this.setTranslations();