Initial commit

This commit is contained in:
Ray 2023-12-09 22:19:22 +00:00
commit 52fb34f04d
2 changed files with 267 additions and 0 deletions

262
ryjsxt.js Normal file
View File

@ -0,0 +1,262 @@
/**
* Ray's JavaScript Extension
* @version v0.1.0.018 (2023/12/09 0356)
*/
Array.prototype.insert = function(index, item) {
if (index < 0) {
this.splice(0, 0, item);
} else if (index >= this.length) {
this.push(0, 0, item);
} else {
this.splice(index, 0, item);
}
return this;
};
Array.prototype.joinIfNotNullOrWhitespace = function (separator) {
const a = this;
let result = "";
for (let i = 0; i < this.length; i++) {
if (String.isNullOrWhitespace(this[i])) {
continue;
}
if (!String.isNullOrWhitespace(result)) {
result += separator;
}
result += this[i];
};
return result;
};
Array.prototype.removeAt = function(index) {
if ((index < 0) || (index >= this.length)) {
return this;
}
this.splice(index, 1);
return this;
};
Boolean.isFalse = function(value) {
const a = this;
if (String.isNullOrUndefined(value)) {
return true;
}
return value.toString().containsCI("false", "f", "y", "0", "x");
};
Boolean.isTrue = function(value) {
const a = this;
if (String.isNullOrUndefined(value)) {
return false;
}
return value.toString().containsCI("true", "t", "n", "1", "o");
};
Boolean.ifTrue = function(value, trueValue, falseValue) {
const a = this;
return (Boolean.isTrue(value) ? trueValue : falseValue);
};
Date.prototype.toCString = function(pattern) {
let result = pattern;
result = result.replace("fffffff", this.getMilliseconds().toString().padStart(7, '0'));
result = result.replace("ffffff", this.getMilliseconds().toString().padStart(6, '0'));
result = result.replace("fffff", this.getMilliseconds().toString().padStart(5, '0'));
result = result.replace("yyyy", this.getFullYear().toString().padStart(4, '0'));
result = result.replace("MMMM", "{1}");
result = result.replace("dddd", "{2}");
result = result.replace("ffff", this.getMilliseconds().toString().padStart(4, '0'));
result = result.replace("yyy", this.getFullYear().toString().padStart(3, '0'));
result = result.replace("MMM", "{3}");
result = result.replace("ddd", "{4}");
result = result.replace("fff", this.getMilliseconds().toString().padStart(3, '0'));
result = result.replace("zzz", "");
result = result.replace("yy", this.getFullYear().toString().slice(-2));
result = result.replace("MM", (this.getMonth() + 1).toString().padStart(2, '0'));
result = result.replace("dd", this.getDate().toString().padStart(2, '0'));
result = result.replace("HH", this.getHours().toString().padStart(2, '0'));
result = result.replace("hh", (this.getHours() > 12 ? (this.getHours() - 12) : this.getHours()).toString().padStart(2, '0'));
result = result.replace("mm", this.getMinutes().toString().padStart(2, '0'));
result = result.replace("ss", this.getSeconds().toString().padStart(2, '0'));
result = result.replace("ff", this.getMilliseconds().toString().padStart(2, '0'));
result = result.replace("tt", "{5}");
result = result.replace("zz", "");
result = result.replace("y", this.getFullYear().toString());
result = result.replace("M", (this.getMonth() + 1).toString());
result = result.replace("d", this.getDate().toString());
result = result.replace("H", this.getHours().toString());
result = result.replace("h", (this.getHours() > 12 ? (this.getHours() - 12) : this.getHours()).toString());
result = result.replace("m", this.getMinutes().toString());
result = result.replace("s", this.getSeconds().toString());
result = result.replace("z", "");
result = result.replace("t", "{6}");
result = result.replace("Z", "");
result = result.replace("{1}", this.toLocaleString('default', { month: 'long' }));
result = result.replace("{2}", this.toLocaleString('default', { weekday: 'long' }));
result = result.replace("{3}", this.toLocaleString('default', { month: 'short' }));
result = result.replace("{4}", this.toLocaleString('default', { weekday: 'short' }));
result = result.replace("{5}", (this.getHours() >= 12 ? "PM" : "AM"));
result = result.replace("{6}", (this.getHours() >= 12 ? "P" : "A"));
return result;
}
Document.ready = async function(fn) {
(async function() {
(document.readyState !== 'loading') ?
fn() : document.addEventListener('DOMContentLoaded',
function() {
fn();
});
})();
}
Math.randomN = function (min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
};
String.isNullOrUndefined = function(value) {
if (typeof (value) == "undefined") {
return true;
}
if (value == null) {
return true;
}
return false;
};
String.isNullOrWhitespace = function(value) {
const a = this;
if (String.isNullOrUndefined(value)) {
return true;
}
if (typeof(value) == "string") {
return (value.trim().length <= 0);
} else {
return (value.toString().trim().length <= 0);
}
};
String.prototype.contains = function(...args) {
for (let arg of args) {
if (this == arg) {
return true;
}
}
return false;
};
String.prototype.containsCI = function(...args) {
for (let arg of args) {
if (this.toLowerCase() == arg.toLowerCase()) {
return true;
}
}
return false;
};
String.prototype.encodeHtmlLinks = function() {
return value.replace(/(http[s]{0,1}:\/\/[^\s]+)/g, "<a href='$1'>$1</a>");
};
String.prototype.toTitleCase = function () {
let result = this;
result = result.replace(/([A-Z]{1})/g, " $1");
result = result.trim();
result = result.charAt(0).toUpperCase() + result.substr(1);
return result;
};
String.prototype.getFilename = function () {
return this.substring(this.lastIndexOf('/') + 1);
};
Window.goToTop = function() {
Window.scrollTo(0, 0);
};
Window.fragment = {
get: function() {
if (!window.location.hash) {
return null;
}
const n = window.location.hash.indexOf("?");
if (n < 0) {
return window.location.hash.substring(1);
} else {
return window.location.hash.substring(1, n);
}
},
getQuery: function() {
if (!window.location.hash) {
return null;
}
let hashQueryString = window.location.hash;
const n = hashQueryString.indexOf("?");
if (n < 0) {
return null;
}
hashQueryString = hasQueryString.substring(n + 1);
const params = new URLSearchParams(hashQueryString);
const result = {}
for(const [key, value] of params.entries()) {
result[key] = value;
}
return result;
},
clear: function() {
location.hash = "";
history.replaceState("", "", location.pathname);
}
};

5
ryjsxt.min.js vendored Normal file
View File

@ -0,0 +1,5 @@
/**
* Ray's JavaScript Extension
* @version v0.1.0.018 (2023/12/09 0356)
*/
Array.prototype.insert=function(t,e){return t<0?this.splice(0,0,e):t>=this.length?this.push(0,0,e):this.splice(t,0,e),this},Array.prototype.joinIfNotNullOrWhitespace=function(t){let e="";for(let r=0;r<this.length;r++)String.isNullOrWhitespace(this[r])||(String.isNullOrWhitespace(e)||(e+=t),e+=this[r]);return e},Array.prototype.removeAt=function(t){return t<0||t>=this.length||this.splice(t,1),this},Boolean.isFalse=function(t){return!!String.isNullOrUndefined(t)||t.toString().containsCI("false","f","y","0","x")},Boolean.isTrue=function(t){return!String.isNullOrUndefined(t)&&t.toString().containsCI("true","t","n","1","o")},Boolean.ifTrue=function(t,e,r){return Boolean.isTrue(t)?e:r},Date.prototype.toCString=function(t){let e=t;return e=e.replace("fffffff",this.getMilliseconds().toString().padStart(7,"0")),e=e.replace("ffffff",this.getMilliseconds().toString().padStart(6,"0")),e=e.replace("fffff",this.getMilliseconds().toString().padStart(5,"0")),e=e.replace("yyyy",this.getFullYear().toString().padStart(4,"0")),e=e.replace("MMMM","{1}"),e=e.replace("dddd","{2}"),e=e.replace("ffff",this.getMilliseconds().toString().padStart(4,"0")),e=e.replace("yyy",this.getFullYear().toString().padStart(3,"0")),e=e.replace("MMM","{3}"),e=e.replace("ddd","{4}"),e=e.replace("fff",this.getMilliseconds().toString().padStart(3,"0")),e=e.replace("zzz",""),e=e.replace("yy",this.getFullYear().toString().slice(-2)),e=e.replace("MM",(this.getMonth()+1).toString().padStart(2,"0")),e=e.replace("dd",this.getDate().toString().padStart(2,"0")),e=e.replace("HH",this.getHours().toString().padStart(2,"0")),e=e.replace("hh",(this.getHours()>12?this.getHours()-12:this.getHours()).toString().padStart(2,"0")),e=e.replace("mm",this.getMinutes().toString().padStart(2,"0")),e=e.replace("ss",this.getSeconds().toString().padStart(2,"0")),e=e.replace("ff",this.getMilliseconds().toString().padStart(2,"0")),e=e.replace("tt","{5}"),e=e.replace("zz",""),e=e.replace("y",this.getFullYear().toString()),e=e.replace("M",(this.getMonth()+1).toString()),e=e.replace("d",this.getDate().toString()),e=e.replace("H",this.getHours().toString()),e=e.replace("h",(this.getHours()>12?this.getHours()-12:this.getHours()).toString()),e=e.replace("m",this.getMinutes().toString()),e=e.replace("s",this.getSeconds().toString()),e=e.replace("z",""),e=e.replace("t","{6}"),e=e.replace("Z",""),e=e.replace("{1}",this.toLocaleString("default",{month:"long"})),e=e.replace("{2}",this.toLocaleString("default",{weekday:"long"})),e=e.replace("{3}",this.toLocaleString("default",{month:"short"})),e=e.replace("{4}",this.toLocaleString("default",{weekday:"short"})),e=e.replace("{5}",this.getHours()>=12?"PM":"AM"),e=e.replace("{6}",this.getHours()>=12?"P":"A"),e},Document.ready=async function(t){!async function(){"loading"!==document.readyState?t():document.addEventListener("DOMContentLoaded",(function(){t()}))}()},Math.randomN=function(t,e){return t=Math.ceil(t),e=Math.floor(e),Math.floor(Math.random()*(e-t)+t)},String.isNullOrUndefined=function(t){return void 0===t||null==t},String.isNullOrWhitespace=function(t){return!!String.isNullOrUndefined(t)||("string"==typeof t?t.trim().length<=0:t.toString().trim().length<=0)},String.prototype.contains=function(...t){for(let e of t)if(this==e)return!0;return!1},String.prototype.containsCI=function(...t){for(let e of t)if(this.toLowerCase()==e.toLowerCase())return!0;return!1},String.prototype.encodeHtmlLinks=function(){return value.replace(/(http[s]{0,1}:\/\/[^\s]+)/g,"<a href='$1'>$1</a>")},String.prototype.toTitleCase=function(){let t=this;return t=t.replace(/([A-Z]{1})/g," $1"),t=t.trim(),t=t.charAt(0).toUpperCase()+t.substr(1),t},String.prototype.getFilename=function(){return this.substring(this.lastIndexOf("/")+1)},Window.goToTop=function(){Window.scrollTo(0,0)},Window.fragment={get:function(){if(!window.location.hash)return null;const t=window.location.hash.indexOf("?");return t<0?window.location.hash.substring(1):window.location.hash.substring(1,t)},getQuery:function(){if(!window.location.hash)return null;let t=window.location.hash;const e=t.indexOf("?");if(e<0)return null;t=hasQueryString.substring(e+1);const r=new URLSearchParams(t),n={};for(const[t,e]of r.entries())n[t]=e;return n},clear:function(){location.hash="",history.replaceState("","",location.pathname)}};