Commit 33c09d7c authored by Максим Базекин's avatar Максим Базекин
Browse files

Initial commit

No related merge requests found
Showing with 178 additions and 0 deletions
+178 -0
.gitignore 0 → 100644
.idea/
// ==UserScript==
// @name ArmExperLogHack
// @author mbazekin
// @version 1.4
// @include https://*.atsaero.ru/calls*
// ==/UserScript==
(function (window, undefined) {
function addJQuery(callback) {
var script = document.createElement('script');
script.setAttribute('src', '//ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js');
script.addEventListener('load', function () {
var script = document.createElement('script');
script.textContent = 'window.jQ=jQuery.noConflict(true);(' + callback.toString() + ')();';
document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}
function main() {
window.onload = function () {
jQ('head').append('<style>\n' +
'.color-error {\n' +
' color: #DC143CFF;\n' +
' }\n' +
'.color-warning {\n' +
' color: #FF8C00FF;\n' +
' }\n' +
'.color-debug {\n' +
' color: #FDEBD3FF;\n' +
' }\n' +
'.color-info {\n' +
' color: #D8DEEAFF;\n' +
' }\n' +
'.color-notice {\n' +
' color: #4FA5FFFF\n' +
' }\n' +
'.color-undefined {\n' +
' color: #B0B0B0FF\n' +
' }\n' +
'.color-node-name {\n' +
' color: #7FFF00FF\n' +
' }\n' +
'.color-synth-text {\n' +
' color: #00FFBBFF\n' +
' }\n' +
'.color-recog-text {\n' +
' color: #1DD5FFFF\n' +
' }\n' +
'.color-appstatus-name {\n' +
' color: #CD49EFFF\n' +
' }\n' +
'.color-point-name {\n' +
' color: #FFC762FF\n' +
' }\n' +
'.line-num {\n' +
' color: #407E40FF;\n' +
' font-style: italic\n' +
' }\n' +
'.color-json {\n' +
' color: #75CCFFFF;\n' +
' font-family: "Lucida Console", "Courier New", monospace;\n' +
' }\n' +
'.pre-background {\n' +
' background-color: #111827;\n' +
' }\n' +
'.regexp-icon-right {\n' +
' position: absolute;\n' +
' top: 50%;\n' +
' right: 8px;\n' +
' -webkit-transform: translateY(-50%);\n' +
' transform: translateY(-50%);\n' +
' font-size: 16px;\n' +
' line-height: 1;\n' +
' color: rgba(0,0,0,.5);\n' +
' vertical-align: middle;\n' +
' }\n' +
'.regexp-icon-left {\n' +
' position: absolute;\n' +
' top: 50%;\n' +
' left: 8px;\n' +
' -webkit-transform: translateY(-50%);\n' +
' transform: translateY(-50%);\n' +
' font-size: 16px;\n' +
' line-height: 1;\n' +
' color: rgba(0,0,0,.5);\n' +
' vertical-align: middle;\n' +
' }\n' +
'</style>');
var isInit = false;
setInterval(function () {
if(jQ('pre').length && !isInit) {
if(!jQ('div.flex.items-center.space-x-2').length) {
jQ('body').prepend('<div class="space-y-2 md:space-y-0 md:space-x-2 md:flex items-center pb-2"><div class="flex items-center space-x-2" style="display: flex;"></div></div>');
}
var leftFilterBox = jQ('body').find('div.flex.items-center.space-x-2').not('.justify-end');
var preBox = jQ('pre');
preBox.addClass('pre-background').addClass('whitespace-pre-wrap').removeClass('whitespace-pre');
leftFilterBox.append('<select id="log-level" class="rounded"><option value="all">all</option><option value="debug">debug</option><option value="info">info</option><option value="notice">notice</option><option value="warning">warning</option><option value="error">error</option></select>');
leftFilterBox.append('<div class="mx-input-wrapper"><i class="regexp-icon-left">/</i><input id="input-regexp" type="text" class="w-full rounded" style="padding-left: 16px; padding-right: 30px;" placeholder="(regex)"><i class="regexp-icon-right">/ui</i></div>');
leftFilterBox.append('<button id="btn-regexp" class="rounded px-3 py-1.5 text-white bg-primary hover:opacity-90"><div>Поиск</div></button>');
var lines = preBox.text().split("\n");
preBox.empty();
jQ.each(lines, function( index, value ) {
if(value.length) {
var matchesLogLevel = value.match(/\[(DEBUG|INFO|WARNING|ERROR|NOTICE)\]/);
value = value.replace(/</g, "&lt;").replace(/>/g, "&gt;");
value = value.replace(/(::getNode \[")([a-z0-9._-]+)("\])/i, "$1<span class='color-node-name'>$2</span>$3");
value = value.replace(/(::calculateAppStatus \[")(App-status '[a-z0-9._-]+')( check result: "[,]?true\])/i, "$1<span class='color-appstatus-name'>$2</span>$3");
value = value.replace(/(\] )(\$synthText: '.*')( \[\])$/ui, "$1<span class='color-synth-text'>$2</span>$3");
value = value.replace(/(\] )(\$recogText: '.*')( \[\])$/ui, "$1<span class='color-recog-text'>$2</span>$3");
value = value.replace(/(::onPoints \["\$pointsNames: \[\\")([a-z0-9а-яё ._-]+)(\\"\]"\])/ui, "$1<span class='color-point-name'>$2</span>$3");
var matchesNluResult = value.match(/( NLU result: )(\{.*\})( \[\])$/ui);
if (null != matchesNluResult) {
value = matchesNluResult[1] + "\n<span class='color-json'>" + JSON.stringify(JSON.parse(matchesNluResult[2]),null,2) + "</span>\n" + matchesNluResult[3];
}
if (null != matchesLogLevel) {
var lineNum = index.toString().padStart(5, '0');
preBox.append('<p class="color-' + matchesLogLevel[1].toLowerCase() + '"><span class="line-num">' + lineNum + ':</span> ' + value + '</p>');
} else {
preBox.append('<p class="color-undefined"><span class="line-num">' + lineNum + ':</span> ' + value + '</p>');
}
}
});
leftFilterBox.find('#log-level').change(function() {
if (jQ(this).val() == 'all') {
preBox.find('p').show();
} else {
preBox.find('p').hide();
preBox.find('p.color-' + jQ(this).val()).show();
}
});
leftFilterBox.find('#btn-regexp').click(function() {
leftFilterBox.find('#log-level').val('all');
try {
var value = leftFilterBox.find('#input-regexp').val();
var regex = new RegExp(value, 'ui');
} catch(e) {
alert(e);
}
preBox.find('p').each(function(index, element) {
if(regex.test(jQ(this).text())) {
jQ(this).show();
} else {
jQ(this).hide();
}
});
});
leftFilterBox.find('#input-regexp').keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
leftFilterBox.find('#btn-regexp').click();
}
});
isInit = true;
}
}, 500);
};
}
addJQuery(main);
})(window);
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment