Files
2026-10-29 18:46:39 +08:00

1 line
3.5 KiB
JavaScript

"use strict";!function(){const e=new Set(["kern","user","mail","daemon","auth","syslog","lpr","news","uucp","cron","authpriv","ftp","ntp","security","console","local0","local1","local2","local3","local4","local5","local6","local7","unknown"]),n=new Set(["emerg","alert","crit","err","warn","notice","info","debug"]),t={emerg:"crit",alert:"crit",crit:"crit",err:"err",warn:"warn",notice:"notice",info:"info",debug:"debug"};function o(e){const n=e.match(/^([A-Za-z0-9_.\/-]+(?:\[\d+\])?):\s+([\s\S]*)$/);return n?{tag:n[1],msg:n[2]}:{tag:"",msg:e}}function l(t){let l=t.match(/^\[(.+?)\]\s+(\w+)\.(\w+):\s+([\s\S]*)$/);return l&&e.has(l[2])&&n.has(l[3])?{time:`[${l[1]}]`,fac:l[2],sev:l[3],sevTok:`${l[2]}.${l[3]}:`,...o(l[4])}:(l=t.match(/^(\w{3} \w{3} +\d{1,2} \d{2}:\d{2}:\d{2} \d{4}) (\w+)\.(\w+) ([\s\S]*)$/),l&&e.has(l[2])&&n.has(l[3])?{time:l[1],fac:l[2],sev:l[3],sevTok:`${l[2]}.${l[3]}`,...o(l[4])}:null)}function s(e){const n=e.match(/^(\[\s*\d+\.\d+\])\s?([\s\S]*)$/);return n?{time:n[1],fac:"",sev:"",sevTok:"",tag:"",msg:n[2]}:null}function c(e,n){const t=(e?e.split(/\n/):[]).map(e=>({line:e,parsed:n(e)})),o=t.reduce((e,n)=>e+(n.parsed?1:0),0);return{rows:t,ratio:t.length?o/t.length:1}}if("undefined"!=typeof module&&module.exports&&(module.exports={parseSyslogLine:l,parseDmesgLine:s,splitTag:o,evaluate:c,PARSE_GATE:.8}),"undefined"==typeof document)return;let a=l,d=null,r=null,i=null,u=null;function m(e,n,t){const o=document.createElement("span");return o.className=e,o.textContent=n,t&&(o.title=t),o}function g(e){const n=document.createElement("div");if(!e.parsed)return n.className="log-row",n.textContent=e.line,n;const o=e.parsed;return n.className="log-row"+(o.sev?` lv-${t[o.sev]}`:""),n.appendChild(m("log-time",o.time)),o.sevTok&&(n.appendChild(document.createTextNode(" ")),n.appendChild(m("log-sev",o.sevTok))),o.tag&&(n.appendChild(document.createTextNode(" ")),n.appendChild(m("log-tag",o.tag+":"))),n.appendChild(document.createTextNode(" ")),n.appendChild(m("log-msg",o.msg)),n}function f(e){i&&i.remove(),i=null,e.classList.remove("log-enhanced")}function p(){const e=document.getElementById("syslog"),n=document.getElementById("content_syslog");if(!e||!n)return;const t=e.value;if(t===u)return;if(i&&function(e){const n=window.getSelection&&window.getSelection();return!(!n||n.isCollapsed)&&(e.contains(n.anchorNode)||e.contains(n.focusNode))}(i))return;u=t;const{rows:o,ratio:l}=c(t,a);if(l>=.8){const t=i&&window.innerHeight+window.scrollY>=document.documentElement.scrollHeight-40;!function(e,n,t){i||(i=document.createElement("div"),i.className="syslog-view",i.tabIndex=0,i.addEventListener("keydown",function(e){if((e.ctrlKey||e.metaKey)&&"a"===e.key.toLowerCase()){e.preventDefault();const n=window.getSelection();n.removeAllRanges();const t=document.createRange();t.selectNodeContents(i),n.addRange(t)}}),e.insertAdjacentElement("afterend",i),n.classList.add("log-enhanced"));const o=document.createDocumentFragment();for(const e of t)o.appendChild(g(e));i.replaceChildren(o)}(e,n,o),t&&window.scrollTo(0,document.documentElement.scrollHeight)}else f(n)}function w(){if(d)return;const e=document.body?.dataset?.page||"";a=/(^|-)dmesg(-|$)/.test(e)?s:l,u=null,d=setInterval(p,1e3),document.getElementById("syslog")?p():(r=new MutationObserver(function(){document.getElementById("syslog")&&(r.disconnect(),r=null,p())}),r.observe(document.documentElement,{childList:!0,subtree:!0}))}(window.luciPatches??={})["admin-status-logs"]={mount:w,unmount:function(){clearInterval(d),d=null,r?.disconnect(),r=null;const e=document.getElementById("content_syslog");e&&f(e),i=null}},w()}();