mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-01 18:41:54 +08:00
js cleanup
This commit is contained in:
@@ -106,7 +106,7 @@ export function Atx(__recorder) {
|
||||
|
||||
if ($("atx-ask-switch").checked) {
|
||||
wm.confirm(`
|
||||
Are you sure you want to press the <b>${button}</b> button?<br>
|
||||
Are you sure you want to press the <b>${tools.escape(button)}</b> button?<br>
|
||||
Warning! This could cause data loss on the server.
|
||||
`).then(function(ok) {
|
||||
if (ok) {
|
||||
|
||||
@@ -135,30 +135,36 @@ export function Gpio(__recorder) {
|
||||
var __createItem = function(item) {
|
||||
if (item.type === "label") {
|
||||
return item.text;
|
||||
|
||||
} else if (item.type === "input") {
|
||||
let e_ch_class = tools.escape(`__gpio-led-${item.channel}`);
|
||||
let e_icon = tools.escape(`${ROOT_PREFIX}share/svg/led-circle.svg`);
|
||||
return `
|
||||
<img
|
||||
class="__gpio-led __gpio-led-${item.channel} inline-lamp-big led-gray"
|
||||
src="${ROOT_PREFIX}share/svg/led-circle.svg"
|
||||
data-color="${item.color}"
|
||||
class="__gpio-led ${e_ch_class} inline-lamp-big led-gray"
|
||||
src="${e_icon}"
|
||||
data-color="${tools.escape(item.color)}"
|
||||
/>
|
||||
`;
|
||||
|
||||
} else if (item.type === "output") {
|
||||
let controls = [];
|
||||
let confirm = (item.confirm ? "Are you sure you want to perform this action?" : "");
|
||||
let e_ch = tools.escape(item.channel);
|
||||
let e_confirm = (item.confirm ? tools.escape("Are you sure you want to perform this action?") : "");
|
||||
if (item.scheme["switch"]) {
|
||||
let id = tools.makeId();
|
||||
let e_id = tools.escape(`__gpio-switch-${tools.makeRandomId()}`);
|
||||
let e_ch_class = tools.escape(`__gpio-switch-${item.channel}`);
|
||||
controls.push(`
|
||||
<td><div class="switch-box">
|
||||
<input
|
||||
disabled
|
||||
type="checkbox"
|
||||
id="__gpio-switch-${id}"
|
||||
class="__gpio-switch __gpio-switch-${item.channel}"
|
||||
data-channel="${item.channel}"
|
||||
data-confirm="${confirm}"
|
||||
id="${e_id}"
|
||||
class="__gpio-switch ${e_ch_class}"
|
||||
data-channel="${e_ch}"
|
||||
data-confirm="${e_confirm}"
|
||||
/>
|
||||
<label for="__gpio-switch-${id}">
|
||||
<label for="${e_id}">
|
||||
<span class="switch-inner"></span>
|
||||
<span class="switch"></span>
|
||||
</label>
|
||||
@@ -166,22 +172,23 @@ export function Gpio(__recorder) {
|
||||
`);
|
||||
}
|
||||
if (item.scheme.pulse.delay) {
|
||||
let e_ch_class = tools.escape(`__gpio-button-${item.channel}`);
|
||||
controls.push(`
|
||||
<td><button
|
||||
disabled
|
||||
class="__gpio-button __gpio-button-${item.channel}"
|
||||
class="__gpio-button ${e_ch_class}"
|
||||
${item.hide ? "data-force-hide-menu" : ""}
|
||||
data-channel="${item.channel}"
|
||||
data-confirm="${confirm}"
|
||||
data-channel="${e_ch}"
|
||||
data-confirm="${e_confirm}"
|
||||
>
|
||||
${(item.hide ? "• " : "") + item.text}
|
||||
${(item.hide ? "• " : "") + tools.escape(item.text)}
|
||||
</button></td>
|
||||
`);
|
||||
}
|
||||
return `<table><tr>${controls.join("<td> </td>")}</tr></table>`;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
return "";
|
||||
};
|
||||
|
||||
var __setLedState = function(el, on) {
|
||||
|
||||
@@ -112,7 +112,7 @@ export function Mouse(__getGeometry, __recordWsEvent) {
|
||||
};
|
||||
|
||||
var __updateRate = function(value) {
|
||||
$("hid-mouse-rate-value").innerHTML = value + " ms";
|
||||
$("hid-mouse-rate-value").innerText = value + " ms";
|
||||
tools.storage.set("hid.mouse.rate", value);
|
||||
if (__timer) {
|
||||
clearInterval(__timer);
|
||||
@@ -121,13 +121,13 @@ export function Mouse(__getGeometry, __recordWsEvent) {
|
||||
};
|
||||
|
||||
var __updateScrollRate = function(value) {
|
||||
$("hid-mouse-scroll-value").innerHTML = value;
|
||||
$("hid-mouse-scroll-value").innerText = value;
|
||||
tools.storage.set("hid.mouse.scroll_rate", value);
|
||||
__scroll_rate = value;
|
||||
};
|
||||
|
||||
var __updateRelativeSens = function(value) {
|
||||
$("hid-mouse-sens-value").innerHTML = value.toFixed(1);
|
||||
$("hid-mouse-sens-value").innerText = value.toFixed(1);
|
||||
tools.storage.set("hid.mouse.sens", value);
|
||||
__relative_sens = value;
|
||||
};
|
||||
|
||||
@@ -208,7 +208,7 @@ export function Msd() {
|
||||
if (el.__names_json !== names_json) {
|
||||
el.innerHTML = names.map(name => `
|
||||
<div class="text">
|
||||
<div id="__msd-storage-${tools.makeIdByText(name)}-progress" class="progress">
|
||||
<div id="__msd-storage-${tools.makeTextId(name)}-progress" class="progress">
|
||||
<span class="progress-value"></span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -223,7 +223,7 @@ export function Msd() {
|
||||
? `${names.length === 1 ? "Storage: %s" : "Internal storage: %s"}` // eslint-disable-line
|
||||
: `Storage [${name}${part.writable ? "]" : ", read-only]"}: %s` // eslint-disable-line
|
||||
);
|
||||
let id = `__msd-storage-${tools.makeIdByText(name)}-progress`;
|
||||
let id = `__msd-storage-${tools.makeTextId(name)}-progress`;
|
||||
tools.progress.setSizeOf($(id), title, part.size, part.free);
|
||||
}
|
||||
};
|
||||
@@ -270,8 +270,8 @@ export function Msd() {
|
||||
};
|
||||
|
||||
var __clickDownloadButton = function() {
|
||||
let image = encodeURIComponent($("msd-image-selector").value);
|
||||
tools.windowOpen(`api/msd/read?image=${image}`);
|
||||
let e_image = encodeURIComponent($("msd-image-selector").value);
|
||||
tools.windowOpen(`api/msd/read?image=${e_image}`);
|
||||
};
|
||||
|
||||
var __clickRemoveButton = function() {
|
||||
@@ -299,13 +299,13 @@ export function Msd() {
|
||||
var __clickUploadNewButton = function() {
|
||||
let file = tools.input.getFile($("msd-new-file"));
|
||||
__http = new XMLHttpRequest();
|
||||
let prefix = encodeURIComponent($("msd-new-part-selector").value);
|
||||
let e_prefix = encodeURIComponent($("msd-new-part-selector").value);
|
||||
if (file) {
|
||||
let image = encodeURIComponent(file.name);
|
||||
__http.open("POST", `${ROOT_PREFIX}api/msd/write?prefix=${prefix}&image=${image}&remove_incomplete=1`, true);
|
||||
let e_image = encodeURIComponent(file.name);
|
||||
__http.open("POST", `${ROOT_PREFIX}api/msd/write?prefix=${e_prefix}&image=${e_image}&remove_incomplete=1`, true);
|
||||
} else {
|
||||
let url = encodeURIComponent($("msd-new-url").value);
|
||||
__http.open("POST", `${ROOT_PREFIX}api/msd/write_remote?prefix=${prefix}&url=${url}&remove_incomplete=1`, true);
|
||||
let e_url = encodeURIComponent($("msd-new-url").value);
|
||||
__http.open("POST", `${ROOT_PREFIX}api/msd/write_remote?prefix=${e_prefix}&url=${e_url}&remove_incomplete=1`, true);
|
||||
}
|
||||
__http.upload.timeout = 7 * 24 * 3600;
|
||||
__http.onreadystatechange = __uploadStateChange;
|
||||
@@ -402,7 +402,8 @@ export function Msd() {
|
||||
if (__state && __state.storage && __state.storage.parts) {
|
||||
let part = __state.storage.parts[$("msd-new-part-selector").value];
|
||||
if (part && (file.size > part.size)) {
|
||||
wm.error(`The new image is too big for the Mass Storage partition.<br>Maximum: ${tools.formatSize(part.size)}`);
|
||||
let e_size = tools.escape(tools.formatSize(part.size));
|
||||
wm.error(`The new image is too big for the Mass Storage partition.<br>Maximum: ${e_size}`);
|
||||
el.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +220,8 @@ export function MediaStreamer(__setActive, __setInactive, __setInfo, __orient) {
|
||||
let width = frame.displayWidth;
|
||||
let height = frame.displayHeight;
|
||||
switch (__orient) {
|
||||
case 90: case 270:
|
||||
case 90:
|
||||
case 270:
|
||||
width = frame.displayHeight;
|
||||
height = frame.displayWidth;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export function MjpegStreamer(__setActive, __setInactive, __setInfo) {
|
||||
|
||||
/************************************************************************/
|
||||
|
||||
var __key = tools.makeId();
|
||||
var __key = tools.makeRandomId();
|
||||
var __id = "";
|
||||
var __fps = -1;
|
||||
var __state = null;
|
||||
@@ -91,7 +91,7 @@ export function MjpegStreamer(__setActive, __setInactive, __setInfo) {
|
||||
|
||||
var __setStreamInactive = function() {
|
||||
let old_fps = __fps;
|
||||
__key = tools.makeId();
|
||||
__key = tools.makeRandomId();
|
||||
__id = "";
|
||||
__fps = -1;
|
||||
__state = null;
|
||||
@@ -139,7 +139,7 @@ export function MjpegStreamer(__setActive, __setInactive, __setInfo) {
|
||||
__setStreamInactive();
|
||||
__stopChecking();
|
||||
|
||||
let path = `${ROOT_PREFIX}streamer/stream?key=${__key}`;
|
||||
let path = `${ROOT_PREFIX}streamer/stream?key=${encodeURIComponent(__key)}`;
|
||||
if (tools.browser.is_safari || tools.browser.is_ios) {
|
||||
// uStreamer fix for WebKit
|
||||
__logInfo("Using dual_final_frames=1 to fix WebKit bugs");
|
||||
|
||||
@@ -178,8 +178,8 @@ export function Switch() {
|
||||
};
|
||||
|
||||
var __clickAddEdidButton = function() {
|
||||
let create_content = function(el_parent, el_ok_button) {
|
||||
tools.el.setEnabled(el_ok_button, false);
|
||||
let create_content = function(el_parent, el_ok_bt) {
|
||||
tools.el.setEnabled(el_ok_bt, false);
|
||||
el_parent.innerHTML = `
|
||||
<table>
|
||||
<tr>
|
||||
@@ -203,7 +203,7 @@ export function Switch() {
|
||||
el_name.oninput = el_data.oninput = function() {
|
||||
let name = el_name.value.replace(/\s+/g, "");
|
||||
let data = el_data.value.replace(/\s+/g, "");
|
||||
tools.el.setEnabled(el_ok_button, ((name.length > 0) && /[0-9a-fA-F]{512}/.test(data)));
|
||||
tools.el.setEnabled(el_ok_bt, ((name.length > 0) && /[0-9a-fA-F]{512}/.test(data)));
|
||||
};
|
||||
};
|
||||
|
||||
@@ -584,7 +584,7 @@ export function Switch() {
|
||||
};
|
||||
if ($("switch-atx-ask-switch").checked) {
|
||||
wm.confirm(`
|
||||
Are you sure you want to press the <b>${button}</b> button?<br>
|
||||
Are you sure you want to press the <b>${tools.escape(button)}</b> button?<br>
|
||||
Warning! This could cause data loss on the server.
|
||||
`).then(function(ok) {
|
||||
if (ok) {
|
||||
|
||||
Reference in New Issue
Block a user