1
0
Files
coconut-leaf/src/static/js/utils.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-01-23 18:37:12 +08:00
/*
2021-01-20 22:57:41 +08:00
function ComputPasswordWithSalt(password, salt) {
return ComputeSHA256(ComputeSHA256(password) + salt.toString());
}
function ComputeSHA256(strl) {
var tempstr = new TextEncoder().encode(strl);
var hashedStrl = undefined
var shitpromise = crypto.subtle.digest('SHA-256', tempstr);
Promise.all(shitpromise).then(function(result) {
hashedStrl = result;
});
var hashArray = Array.from(new Uint8Array(hashedStrl));
var hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
return hashHex.toLowerCase();
}
2021-01-23 18:37:12 +08:00
*/
2021-01-20 22:57:41 +08:00
function IsResponseOK(data) {
2021-02-09 17:10:05 +08:00
if (typeof (data) == 'undefined') {
2021-01-20 22:57:41 +08:00
console.log("Fail to execute an api!");
return false;
}
if (!data['success']) {
console.log("Fail to execute an api! Reason:");
console.log(data['error']);
return false;
}
return true;
}
function GetApiToken() {
return ccn_localstorageAssist_Get('ccn-token', '');
}
function SetApiToken(value) {
ccn_localstorageAssist_Set('ccn-token', value);
}
2021-01-24 14:38:08 +08:00
function LineBreaker2Br(strl) {
2021-02-09 17:10:05 +08:00
return $('<div>').text(strl).html().replace(/\n/g, '<br />');
2021-02-07 21:12:56 +08:00
}
function IsUndefinedOrEmpty(data) {
2021-02-09 17:10:05 +08:00
return (typeof (data) == 'undefined' || data == "");
2021-02-08 22:30:01 +08:00
}
function SmarterShowHide(boolean, element) {
2021-02-09 17:10:05 +08:00
if (typeof (element) == 'undefined') return;
2021-02-08 22:30:01 +08:00
if (boolean) element.show();
else element.hide();
2021-02-09 17:10:05 +08:00
}
2021-02-10 16:51:11 +08:00
function GCD(a, b) {
if (b == 0) return a;
return GCD(b, a % b);
}
function LCM(a, b) {
return a / GCD(a, b) * b;
}
2021-02-09 17:10:05 +08:00
String.prototype.format = function() {
var e = arguments;
return !!this && this.replace(
/\{(\d+)\}/g,
function (t, n) {
return e[n].toString() ? e[n].toString() : t;
}
);
};
Date.prototype.getWeekday = function() {
var temp = this.getDay();
if (temp == 0) return 6;
else return temp - 1;
};