mirror of
https://github.com/horsicq/Detect-It-Easy.git
synced 2026-06-24 01:54:08 +00:00
167 lines
4.2 KiB
Text
167 lines
4.2 KiB
Text
includeScript("_debug");
|
|
|
|
var bDetected,
|
|
sType,
|
|
sName,
|
|
sVersion,
|
|
sOptions;
|
|
|
|
/**
|
|
* Initializes the detection process with the given parameters.
|
|
*
|
|
* @param {string} sType - The type of the item to detect. Defaults to "unknown".
|
|
* @param {string} sName - The name of the item to detect. Defaults to "unknown".
|
|
* @param {string} [sVersion] - The version of the item to detect. Optional.
|
|
* @param {string} [sOptions] - Additional options for detection. Optional.
|
|
*/
|
|
function define(sTypeInput, sNameInput) {
|
|
if (!sTypeInput) _error("No input type.");
|
|
|
|
sType = sTypeInput;
|
|
sName = sNameInput;
|
|
|
|
sVersion = arguments[2] ? arguments[2] : "";
|
|
sOptions = arguments[3] ? arguments[3] : "";
|
|
|
|
bDetected = false;
|
|
}
|
|
|
|
var init = define;
|
|
|
|
|
|
var visualDieOutputFix = false;
|
|
|
|
if (visualDieOutputFix) {
|
|
var _setResult_original = _setResult;
|
|
|
|
var _setResult_func = function (sType, sName, sVersion, sOptions) {
|
|
_setResult_original(sType, sName + (sVersion || sOptions) ? " " : "", sVersion, sOptions);
|
|
};
|
|
|
|
_setResult = _setResult_func;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Processes the detection result and resets the detection variables.
|
|
*
|
|
* If a detection has been made (bDetected is true), this function sets the result
|
|
* using the _setResult function with the provided type, name, version, and options.
|
|
* After setting the result, it resets the detection flag (bDetected) to false.
|
|
*
|
|
* Regardless of whether a detection was made, it resets the sName, sVersion, and sOptions
|
|
* variables to empty strings.
|
|
*/
|
|
function result() {
|
|
if (bDetected) {
|
|
_setResult(sType, sName, sVersion, sOptions);
|
|
|
|
bDetected = false;
|
|
}
|
|
|
|
sName = String();
|
|
sVersion = String();
|
|
sOptions = String();
|
|
|
|
var resultValue = bDetected;
|
|
|
|
bDetected = false;
|
|
|
|
return resultValue;
|
|
}
|
|
|
|
/**
|
|
* Gets the primitive value of the current object.
|
|
* @type {string}
|
|
*/
|
|
String.prototype.append = function () {
|
|
var s = this.valueOf(),
|
|
sep = ",";
|
|
|
|
if (arguments.length) {
|
|
if (s) s += sep;
|
|
s += Array.prototype.join.call(arguments, sep);
|
|
}
|
|
|
|
return s;
|
|
}
|
|
|
|
/**
|
|
* Append a string with a custom separator.
|
|
* @param {String} sString - String to append.
|
|
* @param {String} [sSep=","] - Separator string.
|
|
* @returns {String} The new string.
|
|
* @global
|
|
* @example
|
|
* sOptions=sOptions.appendS("debug","::");
|
|
*/
|
|
String.prototype.appendS = function (sString, sSep) {
|
|
var s = this.valueOf(),
|
|
sep = sSep || ",";
|
|
|
|
if (sString) {
|
|
if (s) s += sep;
|
|
s += sString;
|
|
}
|
|
|
|
return s;
|
|
}
|
|
|
|
String.prototype.addIfNone = function (substring) {
|
|
var s = this.valueOf();
|
|
|
|
if (substring && s.indexOf(substring) < 0)
|
|
s += substring;
|
|
|
|
return s;
|
|
}
|
|
|
|
/**
|
|
* Pad the start of a line with spaces or the character given.
|
|
* This reimplements missing functionality of the more modern ECMAScript.
|
|
* @param {String or Number} The width desired.
|
|
* @param {Number} [nPad=" "] The padding string. Loops.
|
|
* @returns {String} The new string.
|
|
* @global
|
|
* @example
|
|
* var a = 12; ...; if("aba12" === a.padStart(5,"ab")) ...
|
|
*/
|
|
String.prototype.padStart = function (targetLength, padString) {
|
|
var s = this.valueOf();
|
|
|
|
targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;
|
|
padString = String(padString || ' ');
|
|
|
|
if (s.length >= targetLength) {
|
|
return String(s);
|
|
}
|
|
|
|
targetLength = targetLength - s.length;
|
|
if (targetLength > padString.length) {
|
|
padString += padString.repeat(targetLength / padString.length); // append to original to ensure we are longer than needed
|
|
}
|
|
|
|
return padString.slice(0, targetLength) + String(s);
|
|
}
|
|
|
|
Number.prototype.padStart = function (targetLength, padString) {
|
|
var s = this.valueOf().toString();
|
|
|
|
targetLength = targetLength >> 0; // truncate if number or convert non-number to 0;
|
|
padString = String(padString || ' ');
|
|
|
|
if (s.length >= targetLength) {
|
|
return s;
|
|
}
|
|
|
|
targetLength = targetLength - s.length;
|
|
if (targetLength > padString.length) {
|
|
padString += padString.repeat(Math.ceil(targetLength / padString.length)); // append to original to ensure we are longer than needed
|
|
}
|
|
|
|
return padString.slice(0, targetLength) + s;
|
|
}
|
|
|
|
includeScript("language");
|
|
includeScript("_db_caching");
|