fix viewer backend for convenitnt test and do some frontend work
This commit is contained in:
220
SuperScriptViewer/static/js/converter.js
Normal file
220
SuperScriptViewer/static/js/converter.js
Normal file
@ -0,0 +1,220 @@
|
||||
// ============================= conv 1
|
||||
|
||||
function doConv1_I2O() {
|
||||
var textSp = $("#conv1Input").val().split("\n");
|
||||
var result = new Array();
|
||||
|
||||
for (var index = 0; index < textSp.length; index++) {
|
||||
var lines = textSp[index];
|
||||
var successful = true;
|
||||
var resultCache = new Array();
|
||||
|
||||
lineSp = lines.split(',');
|
||||
var innerIndex = lineSp.length - 1;
|
||||
for (var forwardIndex = 0; forwardIndex < lineSp.length; forwardIndex++) {
|
||||
var words = lineSp[forwardIndex];
|
||||
words = words.trim().toLowerCase();
|
||||
if (!checkByteUnit(words)) {
|
||||
resultCache.length = 0;
|
||||
successful = false;
|
||||
break;
|
||||
} else
|
||||
resultCache[innerIndex] = words;
|
||||
innerIndex--;
|
||||
}
|
||||
|
||||
if (successful)
|
||||
result[index] = resultCache.join(", ");
|
||||
else
|
||||
result[index] = "";
|
||||
|
||||
}
|
||||
|
||||
$("#conv1Output").val(result.join("\n"));
|
||||
}
|
||||
|
||||
// ============================= conv 2
|
||||
|
||||
function doConv2_I2O() {
|
||||
var textSp = $("#conv2Input").val().split("\n");
|
||||
var result = new Array();
|
||||
|
||||
for (var index = 0; index < textSp.length; index++) {
|
||||
var lines = textSp[index];
|
||||
var successful = true;
|
||||
var resultCache = "";
|
||||
|
||||
lineSp = lines.split(',');
|
||||
var innerIndex = lineSp.length - 1;
|
||||
for (var forwardIndex = 0; forwardIndex < lineSp.length; forwardIndex++) {
|
||||
var words = lineSp[forwardIndex];
|
||||
words = words.trim().toLowerCase();
|
||||
if (!checkByteUnit(words)) {
|
||||
resultCache.length = 0;
|
||||
successful = false;
|
||||
break;
|
||||
} else
|
||||
resultCache = words.substr(2, 2) + resultCache;
|
||||
innerIndex--;
|
||||
}
|
||||
|
||||
if (successful)
|
||||
result[index] = resultCache;
|
||||
else
|
||||
result[index] = "";
|
||||
|
||||
}
|
||||
|
||||
$("#conv2Output").val(result.join("\n"));
|
||||
}
|
||||
|
||||
function doConv2_O2I() {
|
||||
var textSp = $("#conv2Output").val().split("\n");
|
||||
var result = new Array();
|
||||
|
||||
for (var index = 0; index < textSp.length; index++) {
|
||||
var lines = textSp[index].toLowerCase();
|
||||
var resultCache = new Array();
|
||||
|
||||
if (!checkHexInput(lines)) {
|
||||
result[index] = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
var sectorCount = parseInt(lines.length / 2);
|
||||
var remainCount = lines.length % 2;
|
||||
|
||||
for (var innerIndex = 0; innerIndex < sectorCount; innerIndex++) {
|
||||
if (innerIndex == 0)
|
||||
resultCache[innerIndex] = "0x" + lines.slice(-(innerIndex + 1) * 2);
|
||||
else
|
||||
resultCache[innerIndex] = "0x" + lines.slice(-(innerIndex + 1) * 2, -innerIndex * 2);
|
||||
}
|
||||
if (remainCount != 0)
|
||||
resultCache[sectorCount] = "0x0" + lines[0];
|
||||
|
||||
for (var addedIndex = resultCache.length; addedIndex < 4; addedIndex++) {
|
||||
resultCache[addedIndex] = "0x00";
|
||||
}
|
||||
|
||||
result[index] = resultCache.join(", ");
|
||||
}
|
||||
|
||||
$("#conv2Input").val(result.join("\n"));
|
||||
}
|
||||
|
||||
// ============================= conv 3
|
||||
|
||||
function doConv3_I2O() {
|
||||
var textSp = $("#conv3Input").val().split("\n");
|
||||
var result = new Array();
|
||||
|
||||
for (var index = 0; index < textSp.length; index++) {
|
||||
var lines = textSp[index];
|
||||
var successful = true;
|
||||
var resultCache = "";
|
||||
|
||||
lineSp = lines.split(',');
|
||||
var innerIndex = lineSp.length - 1;
|
||||
for (var forwardIndex = 0; forwardIndex < lineSp.length; forwardIndex++) {
|
||||
var words = lineSp[forwardIndex];
|
||||
words = words.trim().toLowerCase();
|
||||
if (!checkByteUnit(words)) {
|
||||
resultCache.length = 0;
|
||||
successful = false;
|
||||
break;
|
||||
} else
|
||||
resultCache = words.substr(2, 2) + resultCache;
|
||||
innerIndex--;
|
||||
}
|
||||
|
||||
if (successful) {
|
||||
var bigInt = BigInt("0x" + resultCache);
|
||||
result[index] = bigInt.toString(10);
|
||||
}
|
||||
else
|
||||
result[index] = "";
|
||||
|
||||
}
|
||||
|
||||
$("#conv3Output").val(result.join("\n"));
|
||||
}
|
||||
|
||||
function doConv3_O2I() {
|
||||
var textSp = $("#conv3Output").val().split("\n");
|
||||
var result = new Array();
|
||||
|
||||
for (var index = 0; index < textSp.length; index++) {
|
||||
var declines = textSp[index];
|
||||
var resultCache = new Array();
|
||||
|
||||
if (!checkDecInput(declines)) {
|
||||
result[index] = "";
|
||||
continue;
|
||||
}
|
||||
|
||||
var bigInt = BigInt(declines);
|
||||
var lines = bigInt.toString(16).toLowerCase();
|
||||
|
||||
var sectorCount = parseInt(lines.length / 2);
|
||||
var remainCount = lines.length % 2;
|
||||
|
||||
for (var innerIndex = 0; innerIndex < sectorCount; innerIndex++) {
|
||||
if (innerIndex == 0)
|
||||
resultCache[innerIndex] = "0x" + lines.slice(-(innerIndex + 1) * 2);
|
||||
else
|
||||
resultCache[innerIndex] = "0x" + lines.slice(-(innerIndex + 1) * 2, -innerIndex * 2);
|
||||
}
|
||||
if (remainCount != 0)
|
||||
resultCache[sectorCount] = "0x0" + lines[0];
|
||||
|
||||
for (var addedIndex = resultCache.length; addedIndex < 4; addedIndex++) {
|
||||
resultCache[addedIndex] = "0x00";
|
||||
}
|
||||
|
||||
result[index] = resultCache.join(", ");
|
||||
}
|
||||
|
||||
$("#conv3Input").val(result.join("\n"));
|
||||
}
|
||||
|
||||
// ============================= conv 4
|
||||
|
||||
function doConv4_I2O() {
|
||||
$("#conv4Output").val($("#conv4Input").val().toUpperCase());
|
||||
}
|
||||
|
||||
function doConv4_O2I() {
|
||||
$("#conv4Input").val($("#conv4Output").val().toLowerCase());
|
||||
}
|
||||
|
||||
// ============================= utils
|
||||
|
||||
function checkDecInput(s) {
|
||||
var legalWords = "0123456789";
|
||||
if (s.length == 0) return false;
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
if (legalWords.indexOf(s[i]) == -1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkHexInput(s) {
|
||||
var legalWords = "0123456789abcdef";
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
if (legalWords.indexOf(s[i]) == -1)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function checkByteUnit(s) {
|
||||
var legalWords = "0123456789abcdefABCDEF";
|
||||
if (s.length != 4) return false;
|
||||
if (s[0] != '0') return false;
|
||||
if (s[1] != 'x') return false;
|
||||
if (legalWords.indexOf(s[2]) == -1) return false;
|
||||
if (legalWords.indexOf(s[3]) == -1) return false;
|
||||
return true;
|
||||
}
|
45
SuperScriptViewer/static/js/env.js
Normal file
45
SuperScriptViewer/static/js/env.js
Normal file
@ -0,0 +1,45 @@
|
||||
function doQuery(fieldIndex, queryTag) {
|
||||
// collect data
|
||||
var readyData = {};
|
||||
$("#queryTable_" + fieldIndex + " tr:not(:first-child)").each(function() {
|
||||
var isEnabled = $(this).find(":nth-child(1) input").prop("checked");
|
||||
if (!isEnabled) return;
|
||||
|
||||
var fieldName = $(this).find(":nth-child(2)").attr("queryName");
|
||||
var fieldValue = $(this).find(":nth-child(3) input").val();
|
||||
|
||||
readyData[fieldName] = fieldValue;
|
||||
});
|
||||
|
||||
var jsonData = JSON.stringify(readyData);
|
||||
|
||||
// raise post
|
||||
$.post(window.location,
|
||||
{
|
||||
tag: queryTag,
|
||||
data: jsonData
|
||||
},
|
||||
function (data, status) {
|
||||
// remove data
|
||||
$("#resultTable_" + fieldIndex + " tr:not(:first-child)").remove();
|
||||
|
||||
// check
|
||||
if (!data['status']) {
|
||||
alert("Fail to query!");
|
||||
return;
|
||||
}
|
||||
|
||||
// check overflow
|
||||
if (data['overflow']) $("#resultTableOverflow_" + fieldIndex).show();
|
||||
else $("#resultTableOverflow_" + fieldIndex).hide();
|
||||
|
||||
// insert data
|
||||
for(var i = 0; i < data['data'].length; i++) {
|
||||
$("#resultTable_" + fieldIndex).append("<tr></tr>");
|
||||
for(var j = 0; j < data['data'][i].length; j++) {
|
||||
$("#resultTable_" + fieldIndex + " tr:last").append("<td></td>");
|
||||
$("#resultTable_" + fieldIndex + " tr:last td:last").text(data['data'][i][j]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
12
SuperScriptViewer/static/js/global.js
Normal file
12
SuperScriptViewer/static/js/global.js
Normal file
@ -0,0 +1,12 @@
|
||||
// tab switcher
|
||||
$(document).ready(function() {
|
||||
// References
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Tab_Role
|
||||
$('[role="tab"]').click(function() {
|
||||
$('[aria-selected="true"]').attr('aria-selected', false);
|
||||
$(this).attr('aria-selected', true);
|
||||
$('[role="tabpanel"]').attr('hidden', true);
|
||||
$(`#${$(this).attr('aria-controls')}`).removeAttr('hidden');
|
||||
});
|
||||
});
|
||||
|
13
SuperScriptViewer/static/js/tabcontrol.js
Normal file
13
SuperScriptViewer/static/js/tabcontrol.js
Normal file
@ -0,0 +1,13 @@
|
||||
function tabControlSwitcher(tabcontrolIndex, neededIndex) {
|
||||
//disable all
|
||||
$(".tabnavigation_" + tabcontrolIndex).each(function () {
|
||||
$(this).removeClass("tabitem-activated").addClass("tabitem-deactivated");
|
||||
});
|
||||
$(".tabpanel_" + tabcontrolIndex).each(function () {
|
||||
$(this).hide();
|
||||
});
|
||||
|
||||
// set current
|
||||
$("#tabnavigation_" + tabcontrolIndex + "_" + neededIndex).removeClass("tabitem-deactivated").addClass("tabitem-activated");
|
||||
$("#tabpanel_" + tabcontrolIndex + "_" + neededIndex).show();
|
||||
}
|
158
SuperScriptViewer/static/js/viewer.js
Normal file
158
SuperScriptViewer/static/js/viewer.js
Normal file
@ -0,0 +1,158 @@
|
||||
//=======================================settings
|
||||
currentSettings = {
|
||||
"plink": true,
|
||||
"properties": true,
|
||||
"highlight": true,
|
||||
"move": true
|
||||
};
|
||||
$(document).ready(function () {
|
||||
//read settings and apply it
|
||||
for (var key in currentSettings) {
|
||||
currentSettings[key] = localstorageAssist_Get("ssm-settings-" + key, "true") == "true";
|
||||
if (currentSettings[key]) $("#sidepanel-display-" + key).prop("checked", true);
|
||||
else $("#sidepanel-display-" + key).removeProp("checked");
|
||||
}
|
||||
//additional settings
|
||||
if (!currentSettings["plink"]) {
|
||||
$(".link-elink").hide();
|
||||
$(".link-plink").hide();
|
||||
}
|
||||
|
||||
// read sidepanel display property
|
||||
var sidepanelDisplay = localstorageAssist_Get("ssm-settings-sidepanelDisplay", "true") == "true";
|
||||
if (sidepanelDisplay){
|
||||
$("#sidepanelContainer").show();
|
||||
$("#sidepanelToggle").text(">>>");
|
||||
} else {
|
||||
$("#sidepanelContainer").hide();
|
||||
$("#sidepanelToggle").text("<<<");
|
||||
}
|
||||
|
||||
});
|
||||
function settingChange(target) {
|
||||
newValue = $("#sidepanel-display-" + target).prop("checked");
|
||||
currentSettings[target] = newValue;
|
||||
localstorageAssist_Set("ssm-settings-" + target, newValue);
|
||||
|
||||
if (target == "plink") {
|
||||
if (currentSettings["plink"]) {
|
||||
$(".link-elink").show();
|
||||
$(".link-plink").show();
|
||||
} else {
|
||||
$(".link-elink").hide();
|
||||
$(".link-plink").hide();
|
||||
}
|
||||
}
|
||||
}
|
||||
function sidepanelDisplayChange() {
|
||||
$("#sidepanelContainer").toggle();
|
||||
if ($("#sidepanelContainer").is(":hidden")) {
|
||||
$("#sidepanelToggle").text("<<<");
|
||||
localstorageAssist_Set("ssm-settings-sidepanelDisplay", false)
|
||||
} else {
|
||||
$("#sidepanelToggle").text(">>>");
|
||||
localstorageAssist_Set("ssm-settings-sidepanelDisplay", true)
|
||||
}
|
||||
}
|
||||
function localstorageAssist_Get(index, defaultValue) {
|
||||
var cache = localStorage.getItem(index);
|
||||
if (cache == null) {
|
||||
localstorageAssist_Set(index, defaultValue);
|
||||
return defaultValue;
|
||||
} else return cache;
|
||||
}
|
||||
function localstorageAssist_Set(index, value) {
|
||||
localStorage.setItem(index, value);
|
||||
}
|
||||
|
||||
|
||||
//=======================================internal event
|
||||
previousHighlight = "";
|
||||
function highlightLink(target) {
|
||||
realTarget = ".target" + target;
|
||||
|
||||
if (previousHighlight != "") {
|
||||
//need restore
|
||||
$(previousHighlight).each(function () {
|
||||
if ($(this).hasClass("link-blink")) {
|
||||
$(this).attr("stroke", "black");
|
||||
}
|
||||
if ($(this).hasClass("link-blinkDelay")) {
|
||||
$(this).attr("fill", "black");
|
||||
}
|
||||
if ($(this).hasClass("link-plink")) {
|
||||
$(this).attr("stroke", "blue");
|
||||
}
|
||||
if ($(this).hasClass("link-elink")) {
|
||||
$(this).attr("stroke", "cyan");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// double one-click, only cancel highlight and don't apply any hightlight
|
||||
// or user disable hightlight
|
||||
if ((realTarget == previousHighlight) || !currentSettings["highlight"]) {
|
||||
previousHighlight = "";
|
||||
} else {
|
||||
//apply new highlight
|
||||
$(realTarget).each(function () {
|
||||
if ($(this).hasClass("link-blink")) {
|
||||
$(this).attr("stroke", "yellow");
|
||||
}
|
||||
if ($(this).hasClass("link-blinkDelay")) {
|
||||
$(this).attr("fill", "yellow");
|
||||
}
|
||||
if ($(this).hasClass("link-plink")) {
|
||||
$(this).attr("stroke", "orange");
|
||||
}
|
||||
if ($(this).hasClass("link-elink")) {
|
||||
$(this).attr("stroke", "orangered");
|
||||
}
|
||||
});
|
||||
|
||||
previousHighlight = realTarget;
|
||||
}
|
||||
|
||||
//cancel event seperate
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
// type = 0: call from cell
|
||||
// type = 1: call from bb
|
||||
function queryInfo(type, obj) {
|
||||
// confirm user enable this function
|
||||
if (!currentSettings["properties"])
|
||||
return;
|
||||
|
||||
$.post(window.location,
|
||||
{
|
||||
operation: "info",
|
||||
tag: type,
|
||||
target: obj
|
||||
},
|
||||
function (data, status) {
|
||||
//set target
|
||||
$("#sidepanel-properties-target b").text(obj);
|
||||
|
||||
//set data
|
||||
$("#sidepanel-properties-container").empty();
|
||||
for (var key in data) {
|
||||
$("#sidepanel-properties-container").append("<div class=\"propertyItem\"></div>");
|
||||
|
||||
var box = $("#sidepanel-properties-container div:last");
|
||||
if (data[key]["is_setting"])
|
||||
$(box).append("<p><code class=\"propertyItem\">S</code><b></b><i></i></p>");
|
||||
else
|
||||
$(box).append("<p><b></b><i></i></p>");
|
||||
|
||||
$(box).find("p b").text(data[key]["name"]);
|
||||
$(box).find("p i").text("(" + key + ")");
|
||||
|
||||
for (var i = 0; i < data[key]['data'].length; i++) {
|
||||
$(box).append("<p></p><pre class=\"propertyItem\"></pre>");
|
||||
$(box).find("p:last").text(data[key]['data'][i][0]);
|
||||
$(box).find("pre:last").text(data[key]['data'][i][1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user