@@ -1,220 +0,0 @@
<!DOCTYPE html>
< html lang = "ru" >
< head >
< meta charset = "utf-8" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< title > Проверка документов< / title >
< style >
: root { --line : #d7d7d7 ; --bg : #f5f5f4 ; --panel : #fff ; }
* { box-sizing : border-box ; }
body { font : 13 px / 1.45 - apple-system , "Segoe UI" , Roboto , Arial , sans-serif ; color : #1c1c1c ; background : var ( - - bg ) ; margin : 0 ; padding : 24 px ; }
. wrap { max-width : 1000 px ; margin : 0 auto ; }
h1 { font-size : 18 px ; margin : 0 0 14 px ; font-weight : 600 ; }
. panel { background : var ( - - panel ) ; border : 1 px solid var ( - - line ) ; border-radius : 6 px ; padding : 14 px ; margin-bottom : 14 px ; }
. badge { display : inline-block ; padding : 1 px 8 px ; border-radius : 10 px ; font-size : 11 px ; color : #fff ; margin-right : 6 px ; }
. b-spell { background : #b3261e ; } . b-grammar { background : #c47f17 ; } . b-punct { background : #2455a4 ; } . b-llm { background : #6a3fa0 ; } . b-ok { background : #2e7d32 ; } . b-off { background : #9e9e9e ; }
. btn { background : #1a4d8f ; color : #fff ; border : 0 ; border-radius : 5 px ; padding : 8 px 18 px ; font-size : 14 px ; cursor : pointer ; }
. btn : disabled { background : #a3b7cc ; cursor : default ; }
# drop { border : 2 px dashed var ( - - line ) ; border-radius : 6 px ; padding : 26 px ; text-align : center ; color : #555 ; cursor : pointer ; margin-bottom : 12 px ; }
# drop . drag { border-color : #1a4d8f ; background : #eef3f9 ; }
# fileinfo { margin-top : 8 px ; font-size : 12 px ; color : #555 ; }
. prog { height : 8 px ; background : #e5e5e5 ; border-radius : 4 px ; overflow : hidden ; margin : 10 px 0 6 px ; }
. prog > div { height : 100 % ; background : #1a4d8f ; width : 0 % ; transition : width .4 s ; }
# stage { font-size : 12 px ; color : #555 ; }
. summary . chip { display : inline-block ; border : 1 px solid var ( - - line ) ; background : #fff ; border-radius : 14 px ; padding : 3 px 12 px ; margin : 2 px 6 px 2 px 0 ; cursor : pointer ; font-size : 12 px ; }
. summary . chip . active { background : #1a4d8f ; border-color : #1a4d8f ; color : #fff ; }
details . pgroup { border : 1 px solid var ( - - line ) ; border-radius : 5 px ; margin-bottom : 8 px ; background : #fff ; }
details . pgroup > summary { cursor : pointer ; padding : 8 px 12 px ; font-size : 13 px ; list-style : none ; display : flex ; justify-content : space-between ; align-items : center ; }
details . pgroup > summary :: -webkit-details-marker { display : none ; }
details . pgroup > summary : hover { background : #f6f8fa ; }
. ptext { padding : 8 px 12 px ; border-top : 1 px solid var ( - - line ) ; color : #444 ; font-size : 12 px ; }
. ptext mark . err { background : #ffd7d2 ; border-bottom : 2 px solid #b3261e ; padding : 0 2 px ; }
. finding { padding : 8 px 12 px ; border-top : 1 px solid var ( - - line ) ; font-size : 13 px ; }
. finding . ctx { font-family : "Segoe UI" , Arial , sans-serif ; }
. finding . ins { color : #b3261e ; font-weight : 600 ; border-bottom : 2 px solid #b3261e ; }
. finding . why { color : #555 ; font-size : 12 px ; font-style : italic ; }
. repl { display : inline-block ; border : 1 px solid #2e7d32 ; color : #2e7d32 ; border-radius : 4 px ; padding : 1 px 8 px ; margin : 3 px 6 px 0 0 ; cursor : pointer ; font-size : 12 px ; background : #f2f8f2 ; }
. repl : hover { background : #e2f0e2 ; }
# statusline { font-size : 12 px ; color : #555 ; margin-bottom : 10 px ; }
. errbox { background : #fdecea ; border : 1 px solid #f5c6c1 ; color : #8c1d18 ; border-radius : 5 px ; padding : 10 px 12 px ; }
< / style >
< / head >
< body >
< div class = "wrap" >
< h1 > Проверка документов — орфография и пунктуация< / h1 >
< div class = "panel" id = "drop" >
Перетащите файл сюда или нажмите — < b > .docx< / b > , < b > .xlsx< / b > , < b > .pptx< / b > или < b > .txt< / b > (старый .doc пересохраните в .docx)
< input type = "file" id = "file" accept = ".docx,.txt" style = "display:none" >
< div id = "fileinfo" > < / div >
< / div >
< div class = "panel" id = "controls" >
< label > < input type = "checkbox" id = "usellm" checked > проверка пунктуации (LLM)< / label >
< button class = "btn" id = "go" disabled > Проверить< / button >
< span id = "statusline" > < / span >
< div class = "prog" id = "prog" style = "display:none" > < div > < / div > < / div >
< div id = "stage" > < / div >
< / div >
< div id = "report" > < / div >
< / div >
< script >
const $ = ( id ) => document . getElementById ( id ) ;
const KIND _BADGE = ( k ) => {
const s = ( k || "" ) . toLowerCase ( ) ;
if ( s . startsWith ( "орф" ) ) return [ "b-spell" , k ] ;
if ( s . startsWith ( "грам" ) ) return [ "b-grammar" , k ] ;
if ( s . startsWith ( "пунк" ) ) return s . includes ( "llm" ) ? [ "b-llm" , "пунктуация (LLM)" ] : [ "b-punct" , k ] ;
return [ "b-off" , k || "прочее" ] ;
} ;
let file = null , jobId = null , timer = null , lastReport = null , activeFilter = "all" ;
// health
async function health ( ) {
try {
const r = await fetch ( "/api/health" ) ;
const h = await r . json ( ) ;
$ ( "statusline" ) . innerHTML =
'Сервис проверки: <span class="badge ' + ( h . lt . ok ? "b-ok" : "b-off" ) + '">' + ( h . lt . ok ? "работает" : "недоступен" ) + "</span>" +
' Пунктуация (LLM): <span class="badge ' + ( h . llm . available ? "b-llm" : "b-off" ) + '">' + ( h . llm . available ? "подключена" : "не подключена" ) + "</span>" ;
if ( ! h . llm . available ) $ ( "usellm" ) . disabled = true ;
} catch ( e ) { $ ( "statusline" ) . textContent = "Сервис недоступен" ; }
}
health ( ) ;
// file pick
const drop = $ ( "drop" ) ;
drop . onclick = ( ) => $ ( "file" ) . click ( ) ;
dragEvents ( ) ;
function dragEvents ( ) {
[ "dragover" , "dragleave" , "drop" ] . forEach ( ev => drop . addEventListener ( ev , e => {
e . preventDefault ( ) ;
drop . classList . toggle ( "drag" , ev === "dragover" ) ;
if ( ev === "drop" ) setFile ( e . dataTransfer . files [ 0 ] ) ;
} ) ) ;
}
$ ( "file" ) . onchange = ( e ) => setFile ( e . target . files [ 0 ] ) ;
function setFile ( f ) {
if ( ! f ) return ;
const ok = /\.(docx|txt)$/i . test ( f . name ) ;
file = ok ? f : null ;
$ ( "fileinfo" ) . textContent = ok ? f . name + " — " + ( f . size / 1024 / 1024 ) . toFixed ( 2 ) + " МБ"
: "Формат не поддержан: нужен .docx или .txt (.doc пересохраните)" ;
$ ( "go" ) . disabled = ! file ;
}
// run
$ ( "go" ) . onclick = ( ) => {
if ( ! file ) return ;
const fd = new FormData ( ) ;
fd . append ( "file" , file ) ;
fd . append ( "use_llm" , $ ( "usellm" ) . checked && ! $ ( "usellm" ) . disabled ? "true" : "false" ) ;
$ ( "go" ) . disabled = true ;
$ ( "report" ) . innerHTML = "" ;
$ ( "prog" ) . style . display = "block" ; $ ( "prog" ) . firstElementChild . style . width = "0%" ;
const xhr = new XMLHttpRequest ( ) ;
xhr . open ( "POST" , "/api/check" ) ;
xhr . upload . onprogress = ( e ) => { if ( e . lengthComputable ) $ ( "prog" ) . firstElementChild . style . width = ( e . loaded / e . total * 10 ) . toFixed ( 0 ) + "%" ; } ;
xhr . onload = ( ) => {
if ( xhr . status !== 200 ) { fail ( "Ошибка отправки: " + xhr . responseText ) ; return ; }
jobId = JSON . parse ( xhr . responseText ) . job _id ;
$ ( "stage" ) . textContent = "в очереди…" ;
timer = setInterval ( poll , 700 ) ;
} ;
xhr . onerror = ( ) => fail ( "Сеть: не удалось отправить файл" ) ;
xhr . send ( fd ) ;
} ;
function fail ( msg ) {
$ ( "prog" ) . style . display = "none" ;
$ ( "report" ) . innerHTML = '<div class="panel errbox">' + msg + "</div>" ;
$ ( "go" ) . disabled = false ;
}
async function poll ( ) {
let j ;
try { j = await ( await fetch ( "/api/job/" + jobId ) ) . json ( ) ; } catch ( e ) { return ; }
if ( j . status === "error" ) { clearInterval ( timer ) ; fail ( "Ошибка: " + ( j . error || "неизвестная" ) ) ; return ; }
$ ( "stage" ) . textContent = j . stage + ( j . total _paras ? " — абзацев в документе: " + j . total _paras : "" ) ;
$ ( "prog" ) . firstElementChild . style . width = Math . round ( ( j . progress || 0 ) * 95 ) + "%" ;
if ( j . status === "done" ) {
clearInterval ( timer ) ;
$ ( "prog" ) . firstElementChild . style . width = "100%" ;
try { lastReport = await ( await fetch ( "/api/report/" + jobId ) ) . json ( ) ; } catch ( e ) { lastReport = null ; }
render ( loadFallback ( j ) ) ;
}
}
async function loadFallback ( j ) { return j ; }
// report rendering
function render ( r ) {
if ( r . report ) lastReport = r . report ;
const rep = lastReport ;
if ( ! rep ) { fail ( "Отчёт недоступен" ) ; return ; }
const L = rep . llm || { } ;
const chips = [ '<span class="chip active" data-f="all">все: ' + rep . findings . length + "</span>" ] ;
const byKind = { } ;
rep . findings . forEach ( f => { const k = f . kind . split ( "(" ) [ 0 ] . trim ( ) ; byKind [ k ] = ( byKind [ k ] || 0 ) + 1 ; } ) ;
Object . entries ( byKind ) . forEach ( ( [ k , v ] ) => chips . push ( '<span class="chip" data-f="' + k + '">' + esc ( k ) + ": " + v + "</span>" ) ) ;
let info = '<div class="panel summary">' +
"<b>" + esc ( rep . file ) + "</b> — " + rep . paragraphs + " абзацев ≈ " + rep . pages _est + " стр. · " +
"орфография/грамматика " + rep . lt _seconds + " с " +
( L . enabled ? " · пунктуация (LLM) " + ( L . llm _seconds || 0 ) + " с " + ( L . llm _chunks _failed ? ", фрагментов не обработано: " + L . llm _chunks _failed : "" ) : " · LLM: " + esc ( L . note || "не использовалась" ) ) +
'<br>' + chips . join ( "" ) +
' <span style="float:right"><button class="btn" style="padding:4px 10px;font-size:12px" id="dl">Скачать отчёт</button></span></div>' ;
const groups = { } ;
rep . findings . forEach ( f => ( groups [ f . para ] = groups [ f . para ] || [ ] ) . push ( f ) ) ;
let body = Object . entries ( groups ) . sort ( ( a , b ) => a [ 0 ] - b [ 0 ] ) . map ( ( [ para , fs ] ) => {
const badges = fs . map ( f => { const [ cls , name ] = KIND _BADGE ( f . kind ) ; return '<span class="badge ' + cls + '">' + esc ( name ) + "</span>" ; } ) . join ( "" ) ;
const items = fs . map ( f => {
const [ b , c , a ] = f . context || [ "" , "" , ] ;
const repls = ( f . replacements || [ ] ) . map ( x => '<span class="repl" data-t="' + esc ( x ) + '">' + esc ( x ) + "</span>" ) . join ( "" ) ;
return '<div class="finding"><span class="badge ' + KIND _BADGE ( f . kind ) [ 0 ] + '">' + esc ( KIND _BADGE ( f . kind ) [ 1 ] ) + "</span> " +
'<span class="ctx">' + esc ( tail ( b , 50 ) ) + '<span class="ins">' + esc ( f . fragment ) + "</span>" + esc ( head ( a , 50 ) ) + "</span> " +
( f . message && ! f . message . includes ( f . fragment ) ? '<div class="why">' + esc ( f . message ) + "</div>" : "" ) +
( repls ? "<div>Варианты <span class='why'>(нажмите — копируется)</span>: " + repls + "</div>" : "" ) + "</div>" ;
} ) . join ( "" ) ;
return '<details class="pgroup" ' + ( Object . keys ( groups ) . length < 4 ? "open" : "" ) + "><summary><span>№ " + para + " " + ( rep . page _map ? "(≈ стр. " + rep . page _map [ para - 1 ] + ")" : "" ) + "</span><span>" + badges + "</span></summary>" +
( rep . texts ? '<div class="ptext">' + paraHtml ( rep . texts [ para - 1 ] , fs ) + "</div>" : "" ) + items + "</details>" ;
} ) . join ( "" ) ;
$ ( "report" ) . innerHTML = info + ( body || '<div class="panel">Замечаний не найдено.</div>' ) ;
document . querySelectorAll ( ".chip" ) . forEach ( ch => ch . onclick = ( ) => filter ( ch . dataset . f ) ) ;
document . querySelectorAll ( ".repl" ) . forEach ( b => b . onclick = ( ) => { navigator . clipboard . writeText ( b . dataset . t ) ; b . title = "скопировано" ; } ) ;
const dl = $ ( "dl" ) ; if ( dl ) dl . onclick = download ;
}
function filter ( f ) {
activeFilter = f ;
document . querySelectorAll ( ".chip" ) . forEach ( c => c . classList . toggle ( "active" , c . dataset . f === f ) ) ;
document . querySelectorAll ( "details.pgroup" ) . forEach ( d => {
const hit = d . querySelectorAll ( ".finding" ) . length === 0 ;
d . style . display = "none" ; // групповой фильтр упрощаем: скрываем группы без совпадений выбранного вида
let any = false ;
d . querySelectorAll ( ".finding .badge" ) . forEach ( b => { if ( f === "all" || b . textContent . startsWith ( f ) ) any = true ; } ) ;
d . style . display = any ? "" : "none" ;
} ) ;
}
function esc ( s ) { const d = document . createElement ( "i" ) ; d . textContent = s == null ? "" : String ( s ) ; return d . innerHTML ; }
function tail ( s , n ) { return s && s . length > n ? "…" + s . slice ( - n ) : ( s || "" ) ; }
function head ( s , n ) { return s && s . length > n ? s . slice ( 0 , n ) + "…" : ( s || "" ) ; }
function paraHtml ( text , fs ) {
let out = esc ( text ) ;
( fs || [ ] ) . slice ( ) . sort ( ( x , y ) => ( y . fragment || "" ) . length - ( x . fragment || "" ) . length ) . forEach ( f => {
if ( ! f . fragment ) return ;
const rx = new RegExp ( f . fragment . replace ( /[.*+?^${}()|[\]\\]/g , "\\$&" ) . replace ( /\s+/g , "\\s+" ) , "g" ) ;
out = out . replace ( rx , ( m ) => "<mark class='err'>" + m + "</mark>" ) ;
} ) ;
return out ;
}
function download ( ) {
const rep = lastReport ; if ( ! rep ) return ;
const html = "<html><meta charset='utf-8'><title>Отчёт " + esc ( rep . file ) + "</title><body style='font-family:Arial;width:900px'><h2>Отчёт: " + esc ( rep . file ) + "</h2><p>Всего замечаний: " + rep . findings . length + " · " + esc ( rep . finished ) + "</p>" +
rep . findings . map ( f => "<p><b>№" + f . para + "</b> [" + esc ( f . kind ) + "] " + esc ( f . message || "" ) + "<br>…<u>" + esc ( f . fragment ) + "</u>… " + ( ( f . replacements || [ ] ) . length ? " → <b>" + esc ( f . replacements [ 0 ] ) + "</b>" : "" ) + "</p>" ) . join ( "" ) + "</body></html>" ;
const a = document . createElement ( "a" ) ;
a . href = URL . createObjectURL ( new Blob ( [ html ] , { type : "text/html" } ) ) ;
a . download = "otchet_" + ( rep . file || "" ) . replace ( /\.[^.]+$/ , "" ) + ".html" ;
a . click ( ) ;
}
< / script >
< / body >
< / html >