forked from flyduino/kissfc-chrome-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
executable file
·151 lines (126 loc) · 4.25 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
'use strict';
const MIN_CONFIG_VERSION = 126;
const MAX_CONFIG_VERSION = 130;
function isNative() {
if (typeof(nw) !== 'undefined') {
return true;
} else {
return false;
}
}
function getProxyURL(url) {
if (isNative()) {
return url;
} else {
return "proxy.php?url=" + encodeURIComponent(url);
}
}
function scrollTop() {
$("#content").scrollTop(60);
}
function setLanguage(lang) {
if (window.localStorage) {
window.localStorage.setItem('language', lang);
} else {
chrome.storage.local.set({'language': lang});
}
}
function getLanguage(callback) {
if (window.localStorage) {
var result = window.localStorage.getItem('language');
if ((result != null)) {
callback(result);
} else {
callback('en');
}
} else {
chrome.storage.local.get('language', function (result) {
if ((result !== undefined) && (result.language !== undefined)) {
callback(result.language);
} else {
callback('en');
}
});
}
}
function changeLanguage() {
getLanguage(function (lang) {
console.log("Switching to " + lang);
$.i18n({
locale: lang
});
$.i18n.locale = lang;
$.i18n().load('./i18n/' + lang + '.json', lang).done(
function () {
$("*").i18n();
});
});
}
function showUpdateModal() {
$(".modal-body").html("<p class='header'>This GUI version is outdated.</p>Click download button to update to the new version.");
$(".modal-footer").html("<a class='update-download u-button' href='https://github.com/KissUltra/gui/releases' target='_blank'>Download</a>");
$(".modal,.modal-overlay").show();
}
function hideModal() {
$(".modal,.modal-overlay").hide();
}
function checkGithubRelease(currVersion) {
console.log("Looking for version newer then " + currVersion);
$.get('https://api.github.com/repos/KissUltra/gui/releases', function (releaseData) {
console.log(releaseData);
if (releaseData.length > 0) {
console.log('Latest release found: ' + releaseData[0].tag_name, ' parameter: ' + currVersion);
if (semver.gt(releaseData[0].tag_name, currVersion)) {
console.log('New version ' + releaseData[0].tag_name + ' available!');
showUpdateModal();
} else {
hideModal();
console.log('Latest version!');
}
}
});
};
$(document).ready(function () {
$.i18n.debug = true;
changeLanguage();
if (isNative()) {
checkGithubRelease(chrome.runtime.getManifest().version);
} else {
if ((navigator.serial === undefined) || ((navigator.userAgent.match(/Opera|OPR\//) ? true : false))) {
$(".modal-body").html("<p class='header'>WRONG BROWSER!</p>Kiss Ultra Web GUI works only in the browsers with Web Serial support.<br><br>" +
"Please install latest version of Google Chrome or Microsoft Edge.<br><br>" +
"If you are unable to use one of those browsers, feel free to install native GUI from github.");
$(".modal-footer").html("<a class='u-button' href='https://github.com/KissUltra/gui/releases/latest'>Download Native GUI</a>");
$(".modal-overlay").show();
$(".modal").css({'top':'100px'}).show();
$(".modal-overlay").off('click');
}
}
PortHandler.initialize();
CONTENT.welcome.initialize();
$(".navigation-menu-button").removeClass('unlocked');
$(".navigation-menu-button").on("click", function () {
var self = this;
var content = $(self).attr('data-name');
function content_ready() {
GUI.contentSwitchInProgress = false;
}
if ($(self).hasClass('unlocked') && GUI.activeContent != content) {
$("#navigation button").removeClass("active-menu");
$(self).addClass("active-menu");
GUI.contentSwitchInProgress = true;
GUI.contentSwitchCleanup(function () {
CONTENT[content].initialize();
});
}
});
$(".update-close").on("click", function() {
hideModal();
});
$(".update-download").on("click", function() {
hideModal();
});
});
Number.prototype.clamp = function (min, max) {
return Math.min(Math.max(this, min), max);
};