📄 suggest.js
字号:
} } var arrayMatchResult = (stringTarget == "" ? this.stringData : stringTarget).match(new RegExp(this.configuration[0].replace(new RegExp(this.configuration[1], "g"), stringKey), "igm")); if (arrayMatchResult == null) { return new Array(); } var arrayMatchResultNew=[], arrayMatchResultNewTemp=[]; for(var i = 0; i < arrayMatchResult.length; i++){ var temp = arrayMatchResult[i]; if (arrayMatchResultNewTemp[temp] != 1){ arrayMatchResultNew.push(temp); arrayMatchResultNewTemp[temp] = 1; } } arrayMatchResultNewTemp = null; arrayMatchResult = arrayMatchResultNew; arrayMatchResultNew = null; if (!booleanInPrepareKeys) { this.arrayPrepareKeys.push([stringKey, arrayMatchResult.join("")]); if (this.arrayPrepareKeys.length > this.intPrepareKeysMaxLength) { this.arrayPrepareKeys.sort( function (arrayA, arrayB) { return arrayA[0].length - arrayB[0].length; } ); this.arrayPrepareKeys.pop(); } } arrayMatchResult.length = arrayMatchResult.length > this.configuration[6] ? this.configuration[6] : arrayMatchResult.length; if (this.configuration[7] && stringKey.match(this.configuration[7][0]) != null) { var stringReg = this.configuration[7][1].replace(this.configuration[1], stringKey); var stringRegReplace = this.configuration[7][2]; } else { var stringReg = "^(" + stringKey + ")"; var stringRegReplace = '<span style="color:#F00;">$1</span>'; } for (var i = 0; i < arrayMatchResult.length; i++) { var arraySplitResult = arrayMatchResult[i].split(new RegExp(this.configuration[2])); var arrayUnblankResult = []; var stringTargetCode = ""; for (var j = 0; j < arraySplitResult.length; j++) { if (arraySplitResult[j] != "") { if (arraySplitResult[j].match(new RegExp(stringReg, "i")) && stringTargetCode == "") { stringTargetCode = arraySplitResult[j].replace(new RegExp(stringReg, "i"), stringRegReplace); } arrayUnblankResult.push(arraySplitResult[j]); } } var arrayTempResult = []; for (var j = 0; j < this.configuration[4].length; j++) { if (this.configuration[4][j] == -1) { arrayTempResult[j] = stringTargetCode; } else { arrayTempResult[j] = arrayUnblankResult[this.configuration[4][j]]; } } arrayMatchResult[i] = arrayTempResult; } return arrayMatchResult; }; this.scan = function () { var suggest = arguments.callee.suggest; if (suggest.booleanForceScan) { if (suggest.stringLastValue != suggest.elementTarget.value) { suggest.stringLastValue = suggest.elementTarget.value; suggest.resetSuggest(suggest.getResult(suggest.elementTarget.value.match(/[^,]*$/)[0])); } } }; this.scan.suggest = this; this.setLine = function (lineNew) { if (this.lineCurrent) { this.lineCurrent.style.color = ""; this.lineCurrent.style.backgroundColor = ""; } this.lineCurrent = null; if (lineNew) { this.lineCurrent = lineNew; this.lineCurrent.style.color = this.options[10]; this.lineCurrent.style.backgroundColor = this.options[11]; this.elementTarget.value = this.elementTarget.value.replace(/[^,]*$/, lineNew.data[this.configuration[5]].replace('<span style="color:#F00;">', "").replace('</span>', "")); } }; this.bind = function (target, url, key) { if (typeof target == "string") { var elementTargetElement = document.getElementById(target); } else { var elementTargetElement = target; } this.elementTarget = elementTargetElement; var arrayElement = this.createContainer(elementTargetElement); if (key == null) { this.stringData = url; } else { if (typeof url != "string") { for (var i = 0; i < url.length; i++) { this.load(url[i], key[i]); } } else { this.load(url, key); } } elementTargetElement.autocomplete = "off"; elementTargetElement.suggest = this; elementTargetElement.style.color = "#999999"; if (elementTargetElement.value != word) { elementTargetElement.value = word; } elementTargetElement.onfocus = function () { if (this.value == this.suggest.word) { this.value = ""; }; this.style.color = ""; this.suggest.stringLastValue = ""; this.suggest.booleanForceScan = true; this.suggest.intThread = setInterval(this.suggest.scan, 10); }; elementTargetElement.onblur = function () { if (this.value == "") { this.value = this.suggest.word; this.style.color = "#999999"; }; this.suggest.hide(); clearInterval(this.suggest.intThread); this.suggest.intThread = -1; }; elementTargetElement.onkeydown = function () { if (this.value == this.suggest.word) { this.value = ""; } var event = arguments[0] || window.event; var suggest = this.suggest; switch (event.keyCode) { case 38: //up this.suggest.booleanForceScan = false; if (!suggest.lineCurrent || suggest.lineCurrent.rowIndex == 1) { suggest.setLine(suggest.elementTable.rows[suggest.elementTable.rows.length - 1]); } else { suggest.setLine(suggest.elementTable.rows[suggest.lineCurrent.rowIndex - 1]); } return false; break; case 40: //down this.suggest.booleanForceScan = false; if (!suggest.lineCurrent || suggest.lineCurrent.rowIndex == suggest.elementTable.rows.length - 1) { suggest.setLine(suggest.elementTable.rows[1]); } else { suggest.setLine(suggest.elementTable.rows[suggest.lineCurrent.rowIndex + 1]); } return false; break; case 13: //Enter this.suggest.booleanForceScan = false; if (this.suggest.lineCurrent) { this.suggest.elementTarget.value = this.suggest.elementTarget.value.replace(/[^,]*$/, this.suggest.lineCurrent.data[this.suggest.configuration[5]]); } if (this.suggest.functionReturn) { if (this.suggest.lineCurrent) { var arrayReturn = []; for (var i = 0; i < this.suggest.lineCurrent.data.length; i++) { arrayReturn[i] = this.suggest.lineCurrent.data[i].replace('<span style="color:#F00;">', "").replace('</span>', ""); } this.suggest.functionReturn(this.suggest.elementTarget.value, arrayReturn); } else { this.suggest.functionReturn(this.suggest.elementTarget.value); } } this.suggest.hide(); break; default: this.suggest.booleanForceScan = true; this.suggest.scan(); break; } }; }; this.bind(target, url, key); this.getData = function (key) { var arrayResult = this.getResult(key); if (arrayResult.length == 1) { var arrayReturn = []; for (var i = 0; i < arrayResult[0].length; i++) { arrayReturn[i] = arrayResult[0][i].replace('<span style="color:#F00;">', "").replace('</span>', ""); } return arrayReturn; } else { return null; } };};var StockSuggestConfiguration = ["(~[^~`]*(`[^~`]*)*`@KEY@[^~`]*(`[^~`]*)*)|(~(s[hz])?@KEY@[^~`]*`[^~`]*`[^~`]*)", "@KEY@", "[~`]", ["选项", "代码", "名称"], [-1, 0, 1], 1, 10, [/^\d+/, "^(s[hz])(@KEY@)", '$1<span style="color:#F00;">$2</span>']];var FundSuggestConfiguration = ["(~@KEY@[^~`]*`[^~`]*`[^~`]*)|(~[^~`]*`@KEY@[^~`]*`[^~`]*)|(~[^~`]*`[^~`]*`@KEY@[^~`]*)", "@KEY@", "[~`]", ["选项", "代码", "名称"], [-1, 0, 1], 1, 10];var HKSuggestConfiguration = ["(~@KEY@[^~`]*`[^~`]*`[^~`]*)|(~[^~`]*`@KEY@[^~`]*`[^~`]*)|(~[^~`]*`[^~`]*`@KEY@[^~`]*)", "@KEY@", "[~`]", ["选项", "代码", "名称"], [-1, 0, 1], 1, 10];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -