mycpen-blog 0.0.0-fyupepumck → 0.0.0-fyvdazuhhw

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1,210 @@
1
- class LocalSearch{constructor({path:e="",unescape:t=!1,top_n_per_article:n=1}){this.path=e,this.unescape=t,this.top_n_per_article=n,this.isfetched=!1,this.datas=null}getIndexByWord(e,t,n=!1){const s=[],o=new Set;return n||(t=t.toLowerCase()),e.forEach((e=>{if(this.unescape){const t=document.createElement("div");t.innerText=e,e=t.innerHTML}const i=e.length;if(0===i)return;let r=0,a=-1;for(n||(e=e.toLowerCase());(a=t.indexOf(e,r))>-1;)s.push({position:a,word:e}),o.add(e),r=a+i})),s.sort(((e,t)=>e.position!==t.position?e.position-t.position:t.word.length-e.word.length)),[s,o]}mergeIntoSlice(e,t,n){let s=n[0],{position:o,word:i}=s;const r=[],a=new Set;for(;o+i.length<=t&&0!==n.length;){a.add(i),r.push({position:o,length:i.length});const e=o+i.length;for(n.shift();0!==n.length&&(s=n[0],o=s.position,i=s.word,e>o);)n.shift()}return{hits:r,start:e,end:t,count:a.size}}highlightKeyword(e,t){let n="",s=t.start;for(const{position:o,length:i}of t.hits)n+=e.substring(s,o),s=o+i,n+=`<mark class="search-keyword">${e.substr(o,i)}</mark>`;return n+=e.substring(s,t.end),n}getResultItems(e){const t=[];return this.datas.forEach((({title:n,content:s,url:o})=>{const[i,r]=this.getIndexByWord(e,n),[a,c]=this.getIndexByWord(e,s),l=new Set([...r,...c]).size,h=i.length+a.length;if(0===h)return;const d=[];0!==i.length&&d.push(this.mergeIntoSlice(0,n.length,i));let u=[];for(;0!==a.length;){const e=a[0],{position:t}=e,n=Math.max(0,t-20),o=Math.min(s.length,t+100);u.push(this.mergeIntoSlice(n,o,a))}u.sort(((e,t)=>e.count!==t.count?t.count-e.count:e.hits.length!==t.hits.length?t.hits.length-e.hits.length:e.start-t.start));const g=parseInt(this.top_n_per_article,10);g>=0&&(u=u.slice(0,g));let p="";(o=new URL(o,location.origin)).searchParams.append("highlight",e.join(" ")),0!==d.length?p+=`<div class="local-search-hit-item"><a href="${o.href}"><span class="search-result-title">${this.highlightKeyword(n,d[0])}</span>`:p+=`<div class="local-search-hit-item"><a href="${o.href}"><span class="search-result-title">${n}</span>`,u.forEach((e=>{p+=`<p class="search-result">${this.highlightKeyword(s,e)}...</p></a>`})),p+="</div>",t.push({item:p,id:t.length,hitCount:h,includedCount:l})})),t}fetchData(){const e=!this.path.endsWith("json");fetch(this.path).then((e=>e.text())).then((t=>{this.isfetched=!0,this.datas=e?[...(new DOMParser).parseFromString(t,"text/xml").querySelectorAll("entry")].map((e=>({title:e.querySelector("title").textContent,content:e.querySelector("content").textContent,url:e.querySelector("url").textContent}))):JSON.parse(t),this.datas=this.datas.filter((e=>e.title)).map((e=>(e.title=e.title.trim(),e.content=e.content?e.content.trim().replace(/<[^>]+>/g,""):"",e.url=decodeURIComponent(e.url).replace(/\/{2,}/g,"/"),e))),window.dispatchEvent(new Event("search:loaded"))}))}highlightText(e,t,n){const s=e.nodeValue;let o=t.start;const i=[];for(const{position:e,length:r}of t.hits){const t=document.createTextNode(s.substring(o,e));o=e+r;const a=document.createElement("mark");a.className=n,a.appendChild(document.createTextNode(s.substr(e,r))),i.push(t,a)}e.nodeValue=s.substring(o,t.end),i.forEach((t=>{e.parentNode.insertBefore(t,e)}))}highlightSearchWords(e){const t=new URL(location.href).searchParams.get("highlight"),n=t?t.split(" "):[];if(!n.length||!e)return;const s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),o=[];for(;s.nextNode();)s.currentNode.parentNode.matches("button, select, textarea, .mermaid")||o.push(s.currentNode);o.forEach((e=>{const[t]=this.getIndexByWord(n,e.nodeValue);if(!t.length)return;const s=this.mergeIntoSlice(0,e.nodeValue.length,t);this.highlightText(e,s,"search-keyword")}))}}window.addEventListener("load",(()=>{const{path:e,top_n_per_article:t,unescape:n,languages:s}=GLOBAL_CONFIG.localSearch,o=new LocalSearch({path:e,top_n_per_article:t,unescape:n}),i=document.querySelector("#local-search-input input"),r=document.getElementById("local-search-stats-wrap"),a=document.getElementById("loading-status"),c=!e.endsWith("json"),l=()=>{if(!o.isfetched)return;let e=i.value.trim().toLowerCase();c&&(e=e.replace(/</g,"&lt;").replace(/>/g,"&gt;")),""!==e&&(a.innerHTML='<i class="fas fa-spinner fa-pulse"></i>');const t=e.split(/[-\s]+/),n=document.getElementById("local-search-results");let l=[];if(e.length>0&&(l=o.getResultItems(t)),1===t.length&&""===t[0])n.textContent="",r.textContent="";else if(0===l.length){n.textContent="";const t=document.createElement("div");t.className="search-result-stats",t.textContent=s.hits_empty.replace(/\$\{query}/,e),r.innerHTML=t.outerHTML}else{l.sort(((e,t)=>e.includedCount!==t.includedCount?t.includedCount-e.includedCount:e.hitCount!==t.hitCount?t.hitCount-e.hitCount:t.id-e.id));const e=s.hits_stats.replace(/\$\{hits}/,l.length);n.innerHTML=`<div class="search-result-list">${l.map((e=>e.item)).join("")}</div>`,r.innerHTML=`<hr><div class="search-result-stats">${e}</div>`,window.pjax&&window.pjax.refresh(n)}a.textContent=""};let h=!1;const d=document.getElementById("search-mask"),u=document.querySelector("#local-search .search-dialog"),g=()=>{window.innerWidth<768&&u.style.setProperty("--search-height",window.innerHeight+"px")},p=()=>{const e=document.body.style;e.width="100%",e.overflow="hidden",btf.animateIn(d,"to_show 0.5s"),btf.animateIn(u,"titleScale 0.5s"),setTimeout((()=>{i.focus()}),300),h||(!o.isfetched&&o.fetchData(),i.addEventListener("input",l),h=!0),document.addEventListener("keydown",(function e(t){"Escape"===t.code&&(m(),document.removeEventListener("keydown",e))})),g(),window.addEventListener("resize",g)},m=()=>{const e=document.body.style;e.width="",e.overflow="",btf.animateOut(u,"search_close .5s"),btf.animateOut(d,"to_hide 0.5s"),window.removeEventListener("resize",g)},f=()=>{btf.addEventListenerPjax(document.querySelector("#search-button > .search"),"click",p)};window.addEventListener("search:loaded",(()=>{const e=document.getElementById("loading-database");e.nextElementSibling.style.display="block",e.remove()})),f(),document.querySelector("#local-search .search-close-button").addEventListener("click",m),d.addEventListener("click",m),GLOBAL_CONFIG.localSearch.preload&&o.fetchData(),o.highlightSearchWords(document.getElementById("article-container")),window.addEventListener("pjax:complete",(()=>{!btf.isHidden(d)&&m(),o.highlightSearchWords(document.getElementById("article-container")),f()}))}));
1
+ class LocalSearch{constructor({path:e="",unescape:t=!1,top_n_per_article:n=1}){this.path=e,this.unescape=t,this.top_n_per_article=n,this.isfetched=!1,this.datas=null}getIndexByWord(e,t,n=!1){const s=[],o=new Set;return n||(t=t.toLowerCase()),e.forEach((e=>{if(this.unescape){const t=document.createElement("div");t.innerText=e,e=t.innerHTML}const i=e.length;if(0===i)return;let r=0,a=-1;for(n||(e=e.toLowerCase());(a=t.indexOf(e,r))>-1;)s.push({position:a,word:e}),o.add(e),r=a+i})),s.sort(((e,t)=>e.position!==t.position?e.position-t.position:t.word.length-e.word.length)),[s,o]}mergeIntoSlice(e,t,n){let s=n[0],{position:o,word:i}=s;const r=[],a=new Set;for(;o+i.length<=t&&0!==n.length;){a.add(i),r.push({position:o,length:i.length});const e=o+i.length;for(n.shift();0!==n.length&&(s=n[0],o=s.position,i=s.word,e>o);)n.shift()}return{hits:r,start:e,end:t,count:a.size}}highlightKeyword(e,t){let n="",s=t.start;for(const{position:o,length:i}of t.hits)n+=e.substring(s,o),s=o+i,n+=`<mark class="search-keyword">${e.substr(o,i)}</mark>`;return n+=e.substring(s,t.end),n}getResultItems(e){const t=[];return this.datas.forEach((({title:n,content:s,url:o})=>{const[i,r]=this.getIndexByWord(e,n),[a,c]=this.getIndexByWord(e,s),l=new Set([...r,...c]).size,h=i.length+a.length;if(0===h)return;const d=[];0!==i.length&&d.push(this.mergeIntoSlice(0,n.length,i));let u=[];for(;0!==a.length;){const e=a[0],{position:t}=e,n=Math.max(0,t-20),o=Math.min(s.length,t+100);u.push(this.mergeIntoSlice(n,o,a))}u.sort(((e,t)=>e.count!==t.count?t.count-e.count:e.hits.length!==t.hits.length?t.hits.length-e.hits.length:e.start-t.start));const g=parseInt(this.top_n_per_article,10);g>=0&&(u=u.slice(0,g));let p="";(o=new URL(o,location.origin)).searchParams.append("highlight",e.join(" ")),0!==d.length?p+=`<div class="local-search-hit-item"><a href="${o.href}"><span class="search-result-title">${this.highlightKeyword(n,d[0])}</span>`:p+=`<div class="local-search-hit-item"><a href="${o.href}"><span class="search-result-title">${n}</span>`,u.forEach((e=>{p+=`<p class="search-result">${this.highlightKeyword(s,e)}...</p></a>`})),p+="</div>",t.push({item:p,id:t.length,hitCount:h,includedCount:l})})),t}fetchData(){const e=!this.path.endsWith("json");fetch(this.path).then((e=>e.text())).then((t=>{this.isfetched=!0,this.datas=e?[...(new DOMParser).parseFromString(t,"text/xml").querySelectorAll("entry")].map((e=>({title:e.querySelector("title").textContent,content:e.querySelector("content").textContent,url:e.querySelector("url").textContent}))):JSON.parse(t),this.datas=this.datas.filter((e=>e.title)).map((e=>(e.title=e.title.trim(),e.content=e.content?e.content.trim().replace(/<[^>]+>/g,""):"",e.url=decodeURIComponent(e.url).replace(/\/{2,}/g,"/"),e))),window.dispatchEvent(new Event("search:loaded"))}))}highlightText(e,t,n){const s=e.nodeValue;let o=t.start;const i=[];for(const{position:e,length:r}of t.hits){const t=document.createTextNode(s.substring(o,e));o=e+r;const a=document.createElement("mark");a.className=n,a.appendChild(document.createTextNode(s.substr(e,r))),i.push(t,a)}e.nodeValue=s.substring(o,t.end),i.forEach((t=>{e.parentNode.insertBefore(t,e)}))}highlightSearchWords(e){const t=new URL(location.href).searchParams.get("highlight"),n=t?t.split(" "):[];if(!n.length||!e)return;const s=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null),o=[];for(;s.nextNode();)s.currentNode.parentNode.matches("button, select, textarea, .mermaid")||o.push(s.currentNode);o.forEach((e=>{const[t]=this.getIndexByWord(n,e.nodeValue);if(!t.length)return;const s=this.mergeIntoSlice(0,e.nodeValue.length,t);this.highlightText(e,s,"search-keyword")}))}}window.addEventListener("load",(()=>{const{path:e,top_n_per_article:t,unescape:n,languages:s}=GLOBAL_CONFIG.localSearch,o=new LocalSearch({path:e,top_n_per_article:t,unescape:n}),i=document.querySelector("#local-search-input input"),r=document.getElementById("local-search-stats-wrap"),a=document.getElementById("loading-status"),c=!e.endsWith("json"),l=()=>{if(!o.isfetched)return;let e=i.value.trim().toLowerCase();c&&(e=e.replace(/</g,"&lt;").replace(/>/g,"&gt;")),""!==e&&(a.innerHTML='<i class="fas fa-spinner fa-pulse"></i>');const t=e.split(/[-\s]+/),n=document.getElementById("local-search-results");let l=[];if(e.length>0&&(l=o.getResultItems(t)),1===t.length&&""===t[0])n.textContent="",r.textContent="";else if(0===l.length){n.textContent="";const t=document.createElement("div");t.className="search-result-stats",t.textContent=s.hits_empty.replace(/\$\{query}/,e),r.innerHTML=t.outerHTML}else{l.sort(((e,t)=>e.includedCount!==t.includedCount?t.includedCount-e.includedCount:e.hitCount!==t.hitCount?t.hitCount-e.hitCount:t.id-e.id));const e=s.hits_stats.replace(/\$\{hits}/,l.length);n.innerHTML=`<div class="search-result-list">${l.map((e=>e.item)).join("")}</div>`,r.innerHTML=`<hr><div class="search-result-stats">${e}</div>`,window.pjax&&window.pjax.refresh(n)}a.textContent=""};let h=!1;const d=document.getElementById("search-mask"),u=document.querySelector("#local-search .search-dialog"),g=()=>{window.innerWidth<768&&u.style.setProperty("--search-height",window.innerHeight+"px")},p=()=>{const e=document.body.style;e.width="100%",e.overflow="hidden",btf.animateIn(d,"to_show 0.5s"),btf.animateIn(u,"titleScale 0.5s"),setTimeout((()=>{i.focus()}),300),h||(!o.isfetched&&o.fetchData(),i.addEventListener("input",l),h=!0),document.addEventListener("keydown",(function e(t){"Escape"===t.code&&(m(),document.removeEventListener("keydown",e))})),g(),window.addEventListener("resize",g)},m=()=>{const e=document.body.style;e.width="",e.overflow="",btf.animateOut(u,"search_close .5s"),btf.animateOut(d,"to_hide 0.5s"),window.removeEventListener("resize",g)},f=()=>{btf.addEventListenerPjax(document.querySelector("#search-button > .search"),"click",p)};window.addEventListener("search:loaded",(()=>{const e=document.getElementById("loading-database");e.nextElementSibling.style.display="block",e.remove()})),f(),document.querySelector("#local-search .search-close-button").addEventListener("click",m),d.addEventListener("click",m),GLOBAL_CONFIG.localSearch.preload&&o.fetchData(),o.highlightSearchWords(document.getElementById("article-container")),window.addEventListener("pjax:complete",(()=>{!btf.isHidden(d)&&m(),o.highlightSearchWords(document.getElementById("article-container")),f()}))}));c675, _0x4581d1) {
2
+ const _0x390f83 = _0x4c10a7;
3
+ let _0xad79b4 = _0x4581d1[0x0], {
4
+ position: _0x52a774,
5
+ word: _0x27c386
6
+ } = _0xad79b4;
7
+ const _0x3b1be0 = [], _0x43ba56 = new Set();
8
+ while (_0x52a774 + _0x27c386[_0x390f83(0xac)] <= _0x2cc675 && _0x4581d1['length'] !== 0x0) {
9
+ _0x43ba56[_0x390f83(0xf1)](_0x27c386), _0x3b1be0[_0x390f83(0x85)]({
10
+ 'position': _0x52a774,
11
+ 'length': _0x27c386[_0x390f83(0xac)]
12
+ });
13
+ const _0x3f8757 = _0x52a774 + _0x27c386['length'];
14
+ _0x4581d1[_0x390f83(0xd9)]();
15
+ while (_0x4581d1[_0x390f83(0xac)] !== 0x0) {
16
+ _0xad79b4 = _0x4581d1[0x0], _0x52a774 = _0xad79b4[_0x390f83(0xf6)], _0x27c386 = _0xad79b4[_0x390f83(0xa0)];
17
+ if (_0x3f8757 > _0x52a774)
18
+ _0x4581d1[_0x390f83(0xd9)]();
19
+ else
20
+ break;
21
+ }
22
+ }
23
+ return {
24
+ 'hits': _0x3b1be0,
25
+ 'start': _0xdfab57,
26
+ 'end': _0x2cc675,
27
+ 'count': _0x43ba56[_0x390f83(0xe7)]
28
+ };
29
+ }
30
+ ['highlightKeyword'](_0x5dc5ed, _0x579025) {
31
+ const _0x2cb45a = _0x4c10a7;
32
+ let _0x4692ac = '', _0x1ae9c3 = _0x579025['start'];
33
+ for (const {
34
+ position: _0x593dda,
35
+ length: _0x22b988
36
+ } of _0x579025[_0x2cb45a(0xd7)]) {
37
+ _0x4692ac += _0x5dc5ed[_0x2cb45a(0x10b)](_0x1ae9c3, _0x593dda), _0x1ae9c3 = _0x593dda + _0x22b988, _0x4692ac += _0x2cb45a(0x89) + _0x5dc5ed[_0x2cb45a(0x91)](_0x593dda, _0x22b988) + _0x2cb45a(0xfa);
38
+ }
39
+ return _0x4692ac += _0x5dc5ed[_0x2cb45a(0x10b)](_0x1ae9c3, _0x579025[_0x2cb45a(0xb4)]), _0x4692ac;
40
+ }
41
+ [_0x4c10a7(0x9b)](_0x29c4e5) {
42
+ const _0x42d1d7 = _0x4c10a7, _0x40b9df = [];
43
+ return this[_0x42d1d7(0xca)][_0x42d1d7(0x8d)](({
44
+ title: _0x3f4e23,
45
+ content: _0x383a4c,
46
+ url: _0x457447
47
+ }) => {
48
+ const _0x2ac126 = _0x42d1d7, [_0x22bd65, _0x429709] = this[_0x2ac126(0xda)](_0x29c4e5, _0x3f4e23), [_0x487104, _0x3c720b] = this['getIndexByWord'](_0x29c4e5, _0x383a4c), _0x12a8fb = new Set([
49
+ ..._0x429709,
50
+ ..._0x3c720b
51
+ ])[_0x2ac126(0xe7)], _0x4103db = _0x22bd65['length'] + _0x487104[_0x2ac126(0xac)];
52
+ if (_0x4103db === 0x0)
53
+ return;
54
+ const _0x56751d = [];
55
+ _0x22bd65[_0x2ac126(0xac)] !== 0x0 && _0x56751d[_0x2ac126(0x85)](this[_0x2ac126(0x86)](0x0, _0x3f4e23[_0x2ac126(0xac)], _0x22bd65));
56
+ let _0x203974 = [];
57
+ while (_0x487104[_0x2ac126(0xac)] !== 0x0) {
58
+ const _0x9c101d = _0x487104[0x0], {position: _0x533f17} = _0x9c101d, _0x4f668c = Math[_0x2ac126(0x8a)](0x0, _0x533f17 - 0x14), _0x109643 = Math[_0x2ac126(0xe3)](_0x383a4c[_0x2ac126(0xac)], _0x533f17 + 0x64);
59
+ _0x203974['push'](this['mergeIntoSlice'](_0x4f668c, _0x109643, _0x487104));
60
+ }
61
+ _0x203974['sort']((_0x424b41, _0x1bdd9c) => {
62
+ const _0x31a99f = _0x2ac126;
63
+ if (_0x424b41[_0x31a99f(0x8c)] !== _0x1bdd9c[_0x31a99f(0x8c)])
64
+ return _0x1bdd9c['count'] - _0x424b41[_0x31a99f(0x8c)];
65
+ else {
66
+ if (_0x424b41[_0x31a99f(0xd7)][_0x31a99f(0xac)] !== _0x1bdd9c[_0x31a99f(0xd7)]['length'])
67
+ return _0x1bdd9c[_0x31a99f(0xd7)]['length'] - _0x424b41['hits']['length'];
68
+ }
69
+ return _0x424b41[_0x31a99f(0xd0)] - _0x1bdd9c[_0x31a99f(0xd0)];
70
+ });
71
+ const _0x24159e = parseInt(this[_0x2ac126(0x8f)], 0xa);
72
+ _0x24159e >= 0x0 && (_0x203974 = _0x203974[_0x2ac126(0xe4)](0x0, _0x24159e));
73
+ let _0x50e2f0 = '';
74
+ _0x457447 = new URL(_0x457447, location['origin']), _0x457447['searchParams'][_0x2ac126(0xc4)]('highlight', _0x29c4e5['join']('\x20')), _0x56751d['length'] !== 0x0 ? _0x50e2f0 += _0x2ac126(0xf4) + _0x457447['href'] + _0x2ac126(0x96) + this[_0x2ac126(0x10d)](_0x3f4e23, _0x56751d[0x0]) + _0x2ac126(0x100) : _0x50e2f0 += '<div\x20class=\x22local-search-hit-item\x22><a\x20href=\x22' + _0x457447[_0x2ac126(0xcf)] + _0x2ac126(0x96) + _0x3f4e23 + _0x2ac126(0x100), _0x203974['forEach'](_0x315238 => {
75
+ const _0x16fc06 = _0x2ac126;
76
+ _0x50e2f0 += _0x16fc06(0xce) + this[_0x16fc06(0x10d)](_0x383a4c, _0x315238) + _0x16fc06(0xd1);
77
+ }), _0x50e2f0 += _0x2ac126(0xa9), _0x40b9df[_0x2ac126(0x85)]({
78
+ 'item': _0x50e2f0,
79
+ 'id': _0x40b9df[_0x2ac126(0xac)],
80
+ 'hitCount': _0x4103db,
81
+ 'includedCount': _0x12a8fb
82
+ });
83
+ }), _0x40b9df;
84
+ }
85
+ [_0x4c10a7(0xee)]() {
86
+ const _0x26e44f = _0x4c10a7, _0x549726 = !this[_0x26e44f(0xb5)][_0x26e44f(0xe2)](_0x26e44f(0xc1));
87
+ fetch(this['path'])['then'](_0xdcde66 => _0xdcde66[_0x26e44f(0xeb)]())[_0x26e44f(0xdf)](_0x227e8f => {
88
+ const _0x1bd8de = _0x26e44f;
89
+ this[_0x1bd8de(0xcc)] = !![], this[_0x1bd8de(0xca)] = _0x549726 ? [...new DOMParser()[_0x1bd8de(0xbf)](_0x227e8f, 'text/xml')[_0x1bd8de(0x104)](_0x1bd8de(0x90))][_0x1bd8de(0xae)](_0x8384fa => ({
90
+ 'title': _0x8384fa[_0x1bd8de(0x94)](_0x1bd8de(0xa6))[_0x1bd8de(0xd4)],
91
+ 'content': _0x8384fa[_0x1bd8de(0x94)](_0x1bd8de(0xe9))[_0x1bd8de(0xd4)],
92
+ 'url': _0x8384fa['querySelector'](_0x1bd8de(0xf2))[_0x1bd8de(0xd4)]
93
+ })) : JSON['parse'](_0x227e8f), this[_0x1bd8de(0xca)] = this[_0x1bd8de(0xca)][_0x1bd8de(0xa5)](_0x554258 => _0x554258['title'])[_0x1bd8de(0xae)](_0x3cedbe => {
94
+ const _0x400196 = _0x1bd8de;
95
+ return _0x3cedbe['title'] = _0x3cedbe[_0x400196(0xa6)]['trim'](), _0x3cedbe['content'] = _0x3cedbe[_0x400196(0xe9)] ? _0x3cedbe['content'][_0x400196(0x101)]()[_0x400196(0xad)](/<[^>]+>/g, '') : '', _0x3cedbe[_0x400196(0xf2)] = decodeURIComponent(_0x3cedbe[_0x400196(0xf2)])['replace'](/\/{2,}/g, '/'), _0x3cedbe;
96
+ }), window[_0x1bd8de(0xfe)](new Event(_0x1bd8de(0x10a)));
97
+ });
98
+ }
99
+ ['highlightText'](_0x2b260b, _0x50ef11, _0x668ffa) {
100
+ const _0x2460c8 = _0x4c10a7, _0x1a0df0 = _0x2b260b[_0x2460c8(0xea)];
101
+ let _0x4332eb = _0x50ef11[_0x2460c8(0xd0)];
102
+ const _0xa6156c = [];
103
+ for (const {
104
+ position: _0x22a692,
105
+ length: _0x4f9c42
106
+ } of _0x50ef11[_0x2460c8(0xd7)]) {
107
+ const _0x4ef069 = document['createTextNode'](_0x1a0df0[_0x2460c8(0x10b)](_0x4332eb, _0x22a692));
108
+ _0x4332eb = _0x22a692 + _0x4f9c42;
109
+ const _0x8ebb14 = document[_0x2460c8(0xc2)]('mark');
110
+ _0x8ebb14['className'] = _0x668ffa, _0x8ebb14[_0x2460c8(0xb0)](document[_0x2460c8(0x99)](_0x1a0df0[_0x2460c8(0x91)](_0x22a692, _0x4f9c42))), _0xa6156c[_0x2460c8(0x85)](_0x4ef069, _0x8ebb14);
111
+ }
112
+ _0x2b260b['nodeValue'] = _0x1a0df0[_0x2460c8(0x10b)](_0x4332eb, _0x50ef11[_0x2460c8(0xb4)]), _0xa6156c['forEach'](_0x1f3743 => {
113
+ const _0x2801ed = _0x2460c8;
114
+ _0x2b260b[_0x2801ed(0xf9)][_0x2801ed(0x93)](_0x1f3743, _0x2b260b);
115
+ });
116
+ }
117
+ [_0x4c10a7(0xe5)](_0x4572f1) {
118
+ const _0x141031 = _0x4c10a7, _0x44eb86 = new URL(location['href'])[_0x141031(0xe1)]['get']('highlight'), _0x46c909 = _0x44eb86 ? _0x44eb86[_0x141031(0x109)]('\x20') : [];
119
+ if (!_0x46c909['length'] || !_0x4572f1)
120
+ return;
121
+ const _0x125fb1 = document[_0x141031(0xf7)](_0x4572f1, NodeFilter['SHOW_TEXT'], null), _0x4070df = [];
122
+ while (_0x125fb1[_0x141031(0xc6)]()) {
123
+ if (!_0x125fb1['currentNode']['parentNode'][_0x141031(0x107)](_0x141031(0xdb)))
124
+ _0x4070df[_0x141031(0x85)](_0x125fb1[_0x141031(0xf0)]);
125
+ }
126
+ _0x4070df['forEach'](_0x376cad => {
127
+ const _0x3ad993 = _0x141031, [_0x4ce4fc] = this[_0x3ad993(0xda)](_0x46c909, _0x376cad[_0x3ad993(0xea)]);
128
+ if (!_0x4ce4fc[_0x3ad993(0xac)])
129
+ return;
130
+ const _0x5e9b81 = this[_0x3ad993(0x86)](0x0, _0x376cad[_0x3ad993(0xea)]['length'], _0x4ce4fc);
131
+ this[_0x3ad993(0xf8)](_0x376cad, _0x5e9b81, _0x3ad993(0x98));
132
+ });
133
+ }
134
+ }
135
+ window[_0x4c10a7(0xcd)](_0x4c10a7(0xe0), () => {
136
+ const _0x3d2754 = _0x4c10a7, {
137
+ path: _0x1ffd74,
138
+ top_n_per_article: _0x3c9aa6,
139
+ unescape: _0x4fed73,
140
+ languages: _0x29beb3
141
+ } = GLOBAL_CONFIG[_0x3d2754(0xb3)], _0x34e300 = new LocalSearch({
142
+ 'path': _0x1ffd74,
143
+ 'top_n_per_article': _0x3c9aa6,
144
+ 'unescape': _0x4fed73
145
+ }), _0x14ed56 = document['querySelector']('#local-search-input\x20input'), _0x1cba4b = document['getElementById'](_0x3d2754(0x83)), _0x57069c = document[_0x3d2754(0xfb)]('loading-status'), _0x58ee1b = !_0x1ffd74[_0x3d2754(0xe2)](_0x3d2754(0xc1)), _0x6f67b0 = () => {
146
+ const _0x25f42f = _0x3d2754;
147
+ if (!_0x34e300[_0x25f42f(0xcc)])
148
+ return;
149
+ let _0x32b8e1 = _0x14ed56[_0x25f42f(0xab)][_0x25f42f(0x101)]()[_0x25f42f(0x9f)]();
150
+ _0x58ee1b && (_0x32b8e1 = _0x32b8e1[_0x25f42f(0xad)](/</g, _0x25f42f(0x88))['replace'](/>/g, _0x25f42f(0xe8)));
151
+ if (_0x32b8e1 !== '')
152
+ _0x57069c[_0x25f42f(0xb9)] = _0x25f42f(0xf5);
153
+ const _0x283990 = _0x32b8e1[_0x25f42f(0x109)](/[-\s]+/), _0x3b6e99 = document[_0x25f42f(0xfb)](_0x25f42f(0xd2));
154
+ let _0x42e599 = [];
155
+ _0x32b8e1[_0x25f42f(0xac)] > 0x0 && (_0x42e599 = _0x34e300[_0x25f42f(0x9b)](_0x283990));
156
+ if (_0x283990[_0x25f42f(0xac)] === 0x1 && _0x283990[0x0] === '')
157
+ _0x3b6e99[_0x25f42f(0xd4)] = '', _0x1cba4b[_0x25f42f(0xd4)] = '';
158
+ else {
159
+ if (_0x42e599[_0x25f42f(0xac)] === 0x0) {
160
+ _0x3b6e99[_0x25f42f(0xd4)] = '';
161
+ const _0x5c03e5 = document[_0x25f42f(0xc2)](_0x25f42f(0xa8));
162
+ _0x5c03e5['className'] = _0x25f42f(0xb6), _0x5c03e5[_0x25f42f(0xd4)] = _0x29beb3[_0x25f42f(0xba)][_0x25f42f(0xad)](/\$\{query}/, _0x32b8e1), _0x1cba4b[_0x25f42f(0xb9)] = _0x5c03e5[_0x25f42f(0xb7)];
163
+ } else {
164
+ _0x42e599[_0x25f42f(0xa1)]((_0x304bdc, _0x4eec66) => {
165
+ const _0x4d97c5 = _0x25f42f;
166
+ if (_0x304bdc[_0x4d97c5(0x105)] !== _0x4eec66[_0x4d97c5(0x105)])
167
+ return _0x4eec66[_0x4d97c5(0x105)] - _0x304bdc[_0x4d97c5(0x105)];
168
+ else {
169
+ if (_0x304bdc[_0x4d97c5(0x102)] !== _0x4eec66['hitCount'])
170
+ return _0x4eec66[_0x4d97c5(0x102)] - _0x304bdc[_0x4d97c5(0x102)];
171
+ }
172
+ return _0x4eec66['id'] - _0x304bdc['id'];
173
+ });
174
+ const _0x5d757e = _0x29beb3[_0x25f42f(0xc0)][_0x25f42f(0xad)](/\$\{hits}/, _0x42e599[_0x25f42f(0xac)]);
175
+ _0x3b6e99[_0x25f42f(0xb9)] = '<div\x20class=\x22search-result-list\x22>' + _0x42e599[_0x25f42f(0xae)](_0x2a68a => _0x2a68a[_0x25f42f(0x108)])[_0x25f42f(0x103)]('') + '</div>', _0x1cba4b[_0x25f42f(0xb9)] = _0x25f42f(0xde) + _0x5d757e + _0x25f42f(0xa9), window[_0x25f42f(0xcb)] && window[_0x25f42f(0xcb)][_0x25f42f(0x82)](_0x3b6e99);
176
+ }
177
+ }
178
+ _0x57069c[_0x25f42f(0xd4)] = '';
179
+ };
180
+ let _0x381e49 = ![];
181
+ const _0x461058 = document[_0x3d2754(0xfb)]('search-mask'), _0x1497fd = document[_0x3d2754(0x94)](_0x3d2754(0x92)), _0x48f67b = () => {
182
+ const _0x3907df = _0x3d2754;
183
+ window[_0x3907df(0xbd)] < 0x300 && _0x1497fd[_0x3907df(0xb2)][_0x3907df(0xc9)]('--search-height', window[_0x3907df(0xec)] + 'px');
184
+ }, _0x54ea8e = () => {
185
+ const _0x1d20f5 = _0x3d2754, _0x5bb7d4 = document[_0x1d20f5(0x9c)][_0x1d20f5(0xb2)];
186
+ _0x5bb7d4['width'] = _0x1d20f5(0xa4), _0x5bb7d4[_0x1d20f5(0xaa)] = _0x1d20f5(0xd3), btf[_0x1d20f5(0xbc)](_0x461058, 'to_show\x200.5s'), btf['animateIn'](_0x1497fd, _0x1d20f5(0xa7)), setTimeout(() => {
187
+ const _0x308d01 = _0x1d20f5;
188
+ _0x14ed56[_0x308d01(0x10c)]();
189
+ }, 0x12c), !_0x381e49 && (!_0x34e300['isfetched'] && _0x34e300[_0x1d20f5(0xee)](), _0x14ed56[_0x1d20f5(0xcd)](_0x1d20f5(0x84), _0x6f67b0), _0x381e49 = !![]), document[_0x1d20f5(0xcd)](_0x1d20f5(0xbe), function _0x1e9263(_0x55d202) {
190
+ const _0x349f51 = _0x1d20f5;
191
+ _0x55d202[_0x349f51(0xa2)] === _0x349f51(0xe6) && (_0x13c8d5(), document[_0x349f51(0xdd)]('keydown', _0x1e9263));
192
+ }), _0x48f67b(), window[_0x1d20f5(0xcd)](_0x1d20f5(0x95), _0x48f67b);
193
+ }, _0x13c8d5 = () => {
194
+ const _0x4187b5 = _0x3d2754, _0x4fdecd = document[_0x4187b5(0x9c)]['style'];
195
+ _0x4fdecd[_0x4187b5(0xd5)] = '', _0x4fdecd[_0x4187b5(0xaa)] = '', btf[_0x4187b5(0x9d)](_0x1497fd, _0x4187b5(0xed)), btf[_0x4187b5(0x9d)](_0x461058, _0x4187b5(0x8e)), window['removeEventListener'](_0x4187b5(0x95), _0x48f67b);
196
+ }, _0x43c7e3 = () => {
197
+ const _0x489880 = _0x3d2754;
198
+ btf['addEventListenerPjax'](document['querySelector'](_0x489880(0xc7)), 'click', _0x54ea8e);
199
+ }, _0x2f09b5 = () => {
200
+ const _0x270c76 = _0x3d2754;
201
+ document[_0x270c76(0x94)](_0x270c76(0xd6))[_0x270c76(0xcd)]('click', _0x13c8d5), _0x461058[_0x270c76(0xcd)](_0x270c76(0xbb), _0x13c8d5), GLOBAL_CONFIG['localSearch'][_0x270c76(0xfc)] && _0x34e300[_0x270c76(0xee)](), _0x34e300[_0x270c76(0xe5)](document[_0x270c76(0xfb)](_0x270c76(0x9e)));
202
+ };
203
+ window['addEventListener']('search:loaded', () => {
204
+ const _0x44337e = _0x3d2754, _0x4b82b4 = document[_0x44337e(0xfb)](_0x44337e(0xc8));
205
+ _0x4b82b4['nextElementSibling'][_0x44337e(0xb2)]['display'] = _0x44337e(0xfd), _0x4b82b4[_0x44337e(0xff)]();
206
+ }), _0x43c7e3(), _0x2f09b5(), window['addEventListener'](_0x3d2754(0xd8), () => {
207
+ const _0xc31ad8 = _0x3d2754;
208
+ !btf[_0xc31ad8(0x8b)](_0x461058) && _0x13c8d5(), _0x34e300[_0xc31ad8(0xe5)](document['getElementById'](_0xc31ad8(0x9e))), _0x43c7e3();
209
+ });
210
+ });
package/js/tianli_gpt.js CHANGED
@@ -1 +1,147 @@
1
- function whenDOMReadyTianliGPT(){function t(t){!function(){const t=document.querySelector(".post-TianliGPT");t&&t.parentElement.removeChild(t)}();const n=document.querySelector(t);if(!n)return;const e=document.createElement("div");e.className="post-TianliGPT";const i=document.createElement("div");i.className="tianliGPT-title",e.appendChild(i);const o=document.createElement("i");o.className="tianliGPT-title-icon",i.appendChild(o),o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48px" height="48px" viewBox="0 0 48 48">\n <title>机器人</title>\n <g id="&#x673A;&#x5668;&#x4EBA;" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n <path d="M34.717885,5.03561087 C36.12744,5.27055371 37.079755,6.60373651 36.84481,8.0132786 L35.7944,14.3153359 L38.375,14.3153359 C43.138415,14.3153359 47,18.1768855 47,22.9402569 L47,34.4401516 C47,39.203523 43.138415,43.0650727 38.375,43.0650727 L9.625,43.0650727 C4.861585,43.0650727 1,39.203523 1,34.4401516 L1,22.9402569 C1,18.1768855 4.861585,14.3153359 9.625,14.3153359 L12.2056,14.3153359 L11.15519,8.0132786 C10.920245,6.60373651 11.87256,5.27055371 13.282115,5.03561087 C14.69167,4.80066802 16.024865,5.7529743 16.25981,7.16251639 L17.40981,14.0624532 C17.423955,14.1470924 17.43373,14.2315017 17.43948,14.3153359 L30.56052,14.3153359 C30.56627,14.2313867 30.576045,14.1470924 30.59019,14.0624532 L31.74019,7.16251639 C31.975135,5.7529743 33.30833,4.80066802 34.717885,5.03561087 Z M38.375,19.4902885 L9.625,19.4902885 C7.719565,19.4902885 6.175,21.0348394 6.175,22.9402569 L6.175,34.4401516 C6.175,36.3455692 7.719565,37.89012 9.625,37.89012 L38.375,37.89012 C40.280435,37.89012 41.825,36.3455692 41.825,34.4401516 L41.825,22.9402569 C41.825,21.0348394 40.280435,19.4902885 38.375,19.4902885 Z M14.8575,23.802749 C16.28649,23.802749 17.445,24.9612484 17.445,26.3902253 L17.445,28.6902043 C17.445,30.1191812 16.28649,31.2776806 14.8575,31.2776806 C13.42851,31.2776806 12.27,30.1191812 12.27,28.6902043 L12.27,26.3902253 C12.27,24.9612484 13.42851,23.802749 14.8575,23.802749 Z M33.1425,23.802749 C34.57149,23.802749 35.73,24.9612484 35.73,26.3902253 L35.73,28.6902043 C35.73,30.1191812 34.57149,31.2776806 33.1425,31.2776806 C31.71351,31.2776806 30.555,30.1191812 30.555,28.6902043 L30.555,26.3902253 C30.555,24.9612484 31.71351,23.802749 33.1425,23.802749 Z" id="&#x5F62;&#x72B6;&#x7ED3;&#x5408;" fill="#444444" fill-rule="nonzero"></path>\n </g>\n </svg>';const l=document.createElement("div");l.className="tianliGPT-title-text",l.textContent="文章摘要",i.appendChild(l);const a=document.createElement("div");a.className="tianliGPT-tag",a.id="tianliGPT-tag",a.textContent="TianliGPT",i.appendChild(a);const s=document.createElement("div");s.className="tianliGPT-explanation",s.innerHTML='生成中...<span class="blinking-cursor"></span>',e.appendChild(s),n.insertBefore(e,n.firstChild)}tianliGPT_postSelector="#post #article-container",tianliGPT_key_list=["6NnrHU4xKAPwwYxZr8WB","FbXpqokdh8qY61bdJEme","PKgVCDRcgwtP4X7bIBBB","OVWfZmDbf1jqsE0OXW4C","WF6NSQdXy7nBmc6BaiFo"],tianliGPT_randomIndex=Math.floor(Math.random()*tianliGPT_key_list.length),tianliGPT_key=tianliGPT_key_list[tianliGPT_randomIndex],tianliGPTIsRunning=!1,tianliGPT_postURL="*/posts/*",tianliGPT_typingAnimate=!1;var n={getTitleAndContent:function(){try{const t=document.title,n=document.querySelector(tianliGPT_postSelector);if(!n)return console.warn("TianliGPT:找不到文章容器。请尝试将引入的代码放入到文章容器之后。如果本身没有打算使用摘要功能可以忽略此提示。"),"";const e=n.getElementsByTagName("p"),i=n.querySelectorAll("h1, h2, h3, h4, h5");let o="";for(let t of i)o+=t.innerText+" ";for(let t of e){o+=t.innerText.replace(/https?:\/\/[^\s]+/g,"")}let l=1e3;"undefined"!=typeof tianliGPT_wordLimit&&(l=tianliGPT_wordLimit);return(t+" "+o).slice(0,l)}catch(t){return console.error("TianliGPT错误:可能由于一个或多个错误导致没有正常运行,原因出在获取文章容器中的内容失败,或者可能是在文章转换过程中失败。",t),""}},fetchTianliGPT:async function(t){if("blog.cpen.top"!==window.location.host)return"获取文章摘要失败,请访问 blog.cpen.top";if(!tianliGPT_key)return"没有获取到key,代码可能没有安装正确。如果你需要在tianli_gpt文件引用前定义tianliGPT_key变量。详细请查看文档。";if("5Q5mpqRK5DkwT1X9Gi5e"===tianliGPT_key)return"请购买 key 使用,如果你能看到此条内容,则说明代码安装正确。";var n=window.location.href;const e=document.title,i=`https://summary.tianli0.top/?content=${encodeURIComponent(t)}&key=${encodeURIComponent(tianliGPT_key)}&url=${encodeURIComponent(n)}&title=${encodeURIComponent(e)}`;try{const t=new AbortController,n=(setTimeout((()=>t.abort()),2e4),await fetch(i,{signal:t.signal}));if(n.ok){return(await n.json()).summary}throw 402===n.status&&document.querySelectorAll(".post-TianliGPT").forEach((t=>{t.style.display="none"})),new Error("TianliGPT:余额不足,请充值后请求新的文章")}catch(t){return"AbortError"===t.name?"localhost"===window.location.hostname?(console.warn("警告:请勿在本地主机上测试 API 密钥。"),"获取文章摘要超时。请勿在本地主机上测试 API 密钥。"):(console.error("请求超时"),"获取文章摘要超时。当你出现这个问题时,可能是key或者绑定的域名不正确。也可能是因为文章过长导致的 AI 运算量过大,你可以稍等一下然后刷新页面重试。"):(console.error("请求失败:",t),"获取文章摘要失败,请稍后再试。")}},aiShowAnimation:function(t){const n=document.querySelector(".tianliGPT-explanation");if(!n)return;if(tianliGPTIsRunning)return;if("undefined"!=typeof tianliGPT_typingAnimate&&!tianliGPT_typingAnimate)return void(n.innerHTML=t);tianliGPTIsRunning=!0;n.style.display="block",n.innerHTML='生成中...<span class="blinking-cursor"></span>';let e=!0,i=0,o=performance.now();const l=()=>{if(i<t.length&&e){const e=performance.now(),s=e-o,r=t.slice(i,i+1);s>=(/[,。!、?,.!?]/.test(r)?150:25)&&(n.innerText=t.slice(0,i+1),o=e,i++,i<t.length?n.innerHTML=t.slice(0,i)+'<span class="blinking-cursor"></span>':(n.innerHTML=t,n.style.display="block",tianliGPTIsRunning=!1,a.disconnect())),requestAnimationFrame(l)}},a=new IntersectionObserver((t=>{let n=t[0].isIntersecting;e=n,e&&setTimeout((()=>{requestAnimationFrame(l)}),200)}),{threshold:0});let s=document.querySelector(".post-TianliGPT");a.observe(s)}};function e(){t(tianliGPT_postSelector);const e=n.getTitleAndContent();postUrlIsContained=null,tianligptJsonData&&(postHref=window.location.href,postRegex=/\/+posts\/+([\w-]+)(\.html)?/,postMatch=postHref.match(postRegex),postFilteredValue=postMatch?postMatch[1]:null,postUrl="https://blog.cpen.top/posts/"+postFilteredValue+".html",postUrlIsContained=postsUrls.includes(postUrl)),postUrlIsContained?(postMatchedSummary=tianligptJsonData.summaries.find((t=>t.url===postUrl)),postSummary=postMatchedSummary.summary,n.aiShowAnimation(postSummary)):n.fetchTianliGPT(e).then((t=>{n.aiShowAnimation(t)}))}!function(){if("undefined"!=typeof tianliGPT_postURL)try{const t=t=>new RegExp("^"+t.split(/\*+/).map(n).join(".*")+"$"),n=t=>t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&"),i=t(tianliGPT_postURL),o=window.location.href;i.test(o)&&e()}catch(t){console.error("TianliGPT:我没有看懂你编写的自定义链接规则,所以我决定不执行摘要功能",t)}else e()}()}if(xhr=new XMLHttpRequest,xhr.open("GET","https://cdn.jsdmirror.com/npm/mycpen-blog@0.0.0-fyupepumck/json/tianli_gpt.json",!1),xhr.send(),200===xhr.status)try{tianligptJsonData=JSON.parse(xhr.responseText),postsUrls=tianligptJsonData.summaries.map((t=>t.url))}catch(t){console.error("解析JSON数据出错:",t),tianligptJsonData=null}else console.error("加载文件失败:",xhr.statusText),tianligptJsonData=null;whenDOMReadyTianliGPT(),document.addEventListener("pjax:complete",whenDOMReadyTianliGPT);
1
+ function whenDOMReadyTianliGPT(){function t(t){!function(){const t=document.querySelector(".post-TianliGPT");t&&t.parentElement.removeChild(t)}();const n=document.querySelector(t);if(!n)return;const e=document.createElement("div");e.className="post-TianliGPT";const i=document.createElement("div");i.className="tianliGPT-title",e.appendChild(i);const o=document.createElement("i");o.className="tianliGPT-title-icon",i.appendChild(o),o.innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="48px" height="48px" viewBox="0 0 48 48">\n <title>机器人</title>\n <g id="&#x673A;&#x5668;&#x4EBA;" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">\n <path d="M34.717885,5.03561087 C36.12744,5.27055371 37.079755,6.60373651 36.84481,8.0132786 L35.7944,14.3153359 L38.375,14.3153359 C43.138415,14.3153359 47,18.1768855 47,22.9402569 L47,34.4401516 C47,39.203523 43.138415,43.0650727 38.375,43.0650727 L9.625,43.0650727 C4.861585,43.0650727 1,39.203523 1,34.4401516 L1,22.9402569 C1,18.1768855 4.861585,14.3153359 9.625,14.3153359 L12.2056,14.3153359 L11.15519,8.0132786 C10.920245,6.60373651 11.87256,5.27055371 13.282115,5.03561087 C14.69167,4.80066802 16.024865,5.7529743 16.25981,7.16251639 L17.40981,14.0624532 C17.423955,14.1470924 17.43373,14.2315017 17.43948,14.3153359 L30.56052,14.3153359 C30.56627,14.2313867 30.576045,14.1470924 30.59019,14.0624532 L31.74019,7.16251639 C31.975135,5.7529743 33.30833,4.80066802 34.717885,5.03561087 Z M38.375,19.4902885 L9.625,19.4902885 C7.719565,19.4902885 6.175,21.0348394 6.175,22.9402569 L6.175,34.4401516 C6.175,36.3455692 7.719565,37.89012 9.625,37.89012 L38.375,37.89012 C40.280435,37.89012 41.825,36.3455692 41.825,34.4401516 L41.825,22.9402569 C41.825,21.0348394 40.280435,19.4902885 38.375,19.4902885 Z M14.8575,23.802749 C16.28649,23.802749 17.445,24.9612484 17.445,26.3902253 L17.445,28.6902043 C17.445,30.1191812 16.28649,31.2776806 14.8575,31.2776806 C13.42851,31.2776806 12.27,30.1191812 12.27,28.6902043 L12.27,26.3902253 C12.27,24.9612484 13.42851,23.802749 14.8575,23.802749 Z M33.1425,23.802749 C34.57149,23.802749 35.73,24.9612484 35.73,26.3902253 L35.73,28.6902043 C35.73,30.1191812 34.57149,31.2776806 33.1425,31.2776806 C31.71351,31.2776806 30.555,30.1191812 30.555,28.6902043 L30.555,26.3902253 C30.555,24.9612484 31.71351,23.802749 33.1425,23.802749 Z" id="&#x5F62;&#x72B6;&#x7ED3;&#x5408;" fill="#444444" fill-rule="nonzero"></path>\n </g>\n </svg>';const l=document.createElement("div");l.className="tianliGPT-title-text",l.textContent="文章摘要",i.appendChild(l);const a=document.createElement("div");a.className="tianliGPT-tag",a.id="tianliGPT-tag",a.textContent="TianliGPT",i.appendChild(a);const s=document.createElement("div");s.className="tianliGPT-explanation",s.innerHTML='生成中...<span class="blinking-cursor"></span>',e.appendChild(s),n.insertBefore(e,n.firstChild)}tianliGPT_postSelector="#post #article-container",tianliGPT_key_list=["6NnrHU4xKAPwwYxZr8WB","FbXpqokdh8qY61bdJEme","PKgVCDRcgwtP4X7bIBBB","OVWfZmDbf1jqsE0OXW4C","WF6NSQdXy7nBmc6BaiFo"],tianliGPT_randomIndex=Math.floor(Math.random()*tianliGPT_key_list.length),tianliGPT_key=tianliGPT_key_list[tianliGPT_randomIndex],tianliGPTIsRunning=!1,tianliGPT_postURL="*/posts/*",tianliGPT_typingAnimate=!1;var n={getTitleAndContent:function(){try{const t=document.title,n=document.querySelector(tianliGPT_postSelector);if(!n)return console.warn("TianliGPT:找不到文章容器。请尝试将引入的代码放入到文章容器之后。如果本身没有打算使用摘要功能可以忽略此提示。"),"";const e=n.getElementsByTagName("p"),i=n.querySelectorAll("h1, h2, h3, h4, h5");let o="";for(let t of i)o+=t.innerText+" ";for(let t of e){o+=t.innerText.replace(/https?:\/\/[^\s]+/g,"")}let l=1e3;"undefined"!=typeof tianliGPT_wordLimit&&(l=tianliGPT_wordLimit);return(t+" "+o).slice(0,l)}catch(t){return console.error("TianliGPT错误:可能由于一个或多个错误导致没有正常运行,原因出在获取文章容器中的内容失败,或者可能是在文章转换过程中失败。",t),""}},fetchTianliGPT:async function(t){if("blog.cpen.top"!==window.location.host)return"获取文章摘要失败,请访问 blog.cpen.top";if(!tianliGPT_key)return"没有获取到key,代码可能没有安装正确。如果你需要在tianli_gpt文件引用前定义tianliGPT_key变量。详细请查看文档。";if("5Q5mpqRK5DkwT1X9Gi5e"===tianliGPT_key)return"请购买 key 使用,如果你能看到此条内容,则说明代码安装正确。";var n=window.location.href;const e=document.title,i=`https://summary.tianli0.top/?content=${encodeURIComponent(t)}&key=${encodeURIComponent(tianliGPT_key)}&url=${encodeURIComponent(n)}&title=${encodeURIComponent(e)}`;try{const t=new AbortController,n=(setTimeout((()=>t.abort()),2e4),await fetch(i,{signal:t.signal}));if(n.ok){return(await n.json()).summary}throw 402===n.status&&document.querySelectorAll(".post-TianliGPT").forEach((t=>{t.style.display="none"})),new Error("TianliGPT:余额不足,请充值后请求新的文章")}catch(t){return"AbortError"===t.name?"localhost"===window.location.hostname?(console.warn("警告:请勿在本地主机上测试 API 密钥。"),"获取文章摘要超时。请勿在本地主机上测试 API 密钥。"):(console.error("请求超时"),"获取文章摘要超时。当你出现这个问题时,可能是key或者绑定的域名不正确。也可能是因为文章过长导致的 AI 运算量过大,你可以稍等一下然后刷新页面重试。"):(console.error("请求失败:",t),"获取文章摘要失败,请稍后再试。")}},aiShowAnimation:function(t){const n=document.querySelector(".tianliGPT-explanation");if(!n)return;if(tianliGPTIsRunning)return;if("undefined"!=typeof tianliGPT_typingAnimate&&!tianliGPT_typingAnimate)return void(n.innerHTML=t);tianliGPTIsRunning=!0;n.style.display="block",n.innerHTML='生成中...<span class="blinking-cursor"></span>';let e=!0,i=0,o=performance.now();const l=()=>{if(i<t.length&&e){const e=performance.now(),s=e-o,r=t.slice(i,i+1);s>=(/[,。!、?,.!?]/.test(r)?150:25)&&(n.innerText=t.slice(0,i+1),o=e,i++,i<t.length?n.innerHTML=t.slice(0,i)+'<span class="blinking-cursor"></span>':(n.innerHTML=t,n.style.display="block",tianliGPTIsRunning=!1,a.disconnect())),requestAnimationFrame(l)}},a=new IntersectionObserver((t=>{let n=t[0].isIntersecting;e=n,e&&setTimeout((()=>{requestAnimationFrame(l)}),200)}),{threshold:0});let s=document.querySelector(".post-TianliGPT");a.observe(s)}};function e(){t(tianliGPT_postSelector);const e=n.getTitleAndContent();postUrlIsContained=null,tianligptJsonData&&(postHref=window.location.href,postRegex=/\/+posts\/+([\w-]+)(\.html)?/,postMatch=postHref.match(postRegex),postFilteredValue=postMatch?postMatch[1]:null,postUrl="https://blog.cpen.top/posts/"+postFilteredValue+".html",postUrlIsContained=postsUrls.includes(postUrl)),postUrlIsContained?(postMatchedSummary=tianligptJsonData.summaries.find((t=>t.url===postUrl)),postSummary=postMatchedSummary.summary,n.aiShowAnimation(postSummary)):n.fetchTianliGPT(e).then((t=>{n.aiShowAnimation(t)}))}!function(){if("undefined"!=typeof tianliGPT_postURL)try{const t=t=>new RegExp("^"+t.split(/\*+/).map(n).join(".*")+"$"),n=t=>t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&"),i=t(tianliGPT_postURL),o=window.location.href;i.test(o)&&e()}catch(t){console.error("TianliGPT:我没有看懂你编写的自定义链接规则,所以我决定不执行摘要功能",t)}else e()}()}if(xhr=new XMLHttpRequest,xhr.open("GET","https://cdn.cbd.int/mycpen-blog@0.0.0-fyvdazuhhw/json/tianli_gpt.json",!1),xhr.send(),200===xhr.status)try{tianligptJsonData=JSON.parse(xhr.responseText),postsUrls=tianligptJsonData.summaries.map((t=>t.url))}catch(t){console.error("解析JSON数据出错:",t),tianligptJsonData=null}else console.error("加载文件失败:",xhr.statusText),tianligptJsonData=null;whenDOMReadyTianliGPT(),document.addEventListener("pjax:complete",whenDOMReadyTianliGPT);6dd27(0xbb)] = _0x26dd27(0xae), _0x12bf0e['appendChild'](_0x5d0593), _0x5d0593[_0x26dd27(0xb5)] = _0x26dd27(0xfc);
2
+ const _0x30da04 = document['createElement'](_0x26dd27(0xfa));
3
+ _0x30da04[_0x26dd27(0xbb)] = _0x26dd27(0x105), _0x30da04[_0x26dd27(0x10e)] = _0x26dd27(0xce), _0x12bf0e['appendChild'](_0x30da04);
4
+ const _0x4c1e24 = document[_0x26dd27(0xdc)]('div');
5
+ _0x4c1e24[_0x26dd27(0xbb)] = _0x26dd27(0xe6), _0x4c1e24['id'] = _0x26dd27(0xe6), _0x4c1e24['textContent'] = _0x26dd27(0x111), _0x12bf0e[_0x26dd27(0xca)](_0x4c1e24);
6
+ const _0x43ead0 = document[_0x26dd27(0xdc)](_0x26dd27(0xfa));
7
+ _0x43ead0[_0x26dd27(0xbb)] = 'tianliGPT-explanation', _0x43ead0[_0x26dd27(0xb5)] = _0x26dd27(0xd2) + _0x26dd27(0xff), _0x4e1bad['appendChild'](_0x43ead0), _0x4efb92[_0x26dd27(0xe0)](_0x4e1bad, _0x4efb92['firstChild']);
8
+ }
9
+ function _0x48f141() {
10
+ const _0x173c81 = _0x4f0a97, _0x15db08 = document[_0x173c81(0xb8)](_0x173c81(0x110));
11
+ _0x15db08 && _0x15db08['parentElement'][_0x173c81(0xe4)](_0x15db08);
12
+ }
13
+ var _0x5dd9a9 = {
14
+ 'getTitleAndContent': function () {
15
+ const _0x304e6a = _0x4f0a97;
16
+ try {
17
+ const _0x105173 = document[_0x304e6a(0xbf)], _0x2193cc = document['querySelector'](tianliGPT_postSelector);
18
+ if (!_0x2193cc)
19
+ return console[_0x304e6a(0xdb)](_0x304e6a(0x10d)), '';
20
+ const _0x33df4b = _0x2193cc['getElementsByTagName']('p'), _0x4df40e = _0x2193cc['querySelectorAll']('h1,\x20h2,\x20h3,\x20h4,\x20h5');
21
+ let _0xc8e8de = '';
22
+ for (let _0x5d32ab of _0x4df40e) {
23
+ _0xc8e8de += _0x5d32ab[_0x304e6a(0xc1)] + '\x20';
24
+ }
25
+ for (let _0xb13a0e of _0x33df4b) {
26
+ const _0x1073a4 = _0xb13a0e['innerText'][_0x304e6a(0xbc)](/https?:\/\/[^\s]+/g, '');
27
+ _0xc8e8de += _0x1073a4;
28
+ }
29
+ const _0x3e8195 = _0x105173 + '\x20' + _0xc8e8de;
30
+ let _0x30db2a = 0x3e8;
31
+ typeof tianliGPT_wordLimit !== 'undefined' && (_0x30db2a = tianliGPT_wordLimit);
32
+ const _0x673b4d = _0x3e8195[_0x304e6a(0xf4)](0x0, _0x30db2a);
33
+ return _0x673b4d;
34
+ } catch (_0x5a57fd) {
35
+ return console[_0x304e6a(0xd1)](_0x304e6a(0xe5), _0x5a57fd), '';
36
+ }
37
+ },
38
+ 'fetchTianliGPT': async function (_0x3b0780) {
39
+ const _0x3474b8 = _0x4f0a97;
40
+ if (window[_0x3474b8(0x108)][_0x3474b8(0xe9)] !== _0x3474b8(0x10c))
41
+ return _0x3474b8(0xe7);
42
+ if (!tianliGPT_key)
43
+ return _0x3474b8(0xfb);
44
+ if (tianliGPT_key === '5Q5mpqRK5DkwT1X9Gi5e')
45
+ return _0x3474b8(0xc4);
46
+ var _0x412d09 = window[_0x3474b8(0x108)][_0x3474b8(0xba)];
47
+ const _0x4d66c9 = document[_0x3474b8(0xbf)], _0xda09ea = _0x3474b8(0xb3) + encodeURIComponent(_0x3b0780) + _0x3474b8(0xcf) + encodeURIComponent(tianliGPT_key) + _0x3474b8(0xbd) + encodeURIComponent(_0x412d09) + _0x3474b8(0xb2) + encodeURIComponent(_0x4d66c9), _0x5e9498 = 0x4e20;
48
+ try {
49
+ const _0x404f3f = new AbortController(), _0x41f815 = setTimeout(() => _0x404f3f[_0x3474b8(0xdf)](), _0x5e9498), _0x168738 = await fetch(_0xda09ea, { 'signal': _0x404f3f[_0x3474b8(0xe3)] });
50
+ if (_0x168738['ok']) {
51
+ const _0x15ea4a = await _0x168738[_0x3474b8(0xbe)]();
52
+ return _0x15ea4a['summary'];
53
+ } else {
54
+ _0x168738['status'] === 0x192 && document[_0x3474b8(0xb9)]('.post-TianliGPT')['forEach'](_0x40567c => {
55
+ const _0x197e6c = _0x3474b8;
56
+ _0x40567c[_0x197e6c(0xf9)][_0x197e6c(0xe8)] = 'none';
57
+ });
58
+ throw new Error('TianliGPT:余额不足,请充值后请求新的文章');
59
+ }
60
+ } catch (_0x1f27e2) {
61
+ return _0x1f27e2[_0x3474b8(0xf7)] === 'AbortError' ? window[_0x3474b8(0x108)]['hostname'] === _0x3474b8(0xb0) ? (console['warn'](_0x3474b8(0xcc)), _0x3474b8(0xee)) : (console['error'](_0x3474b8(0x113)), _0x3474b8(0xc6)) : (console[_0x3474b8(0xd1)](_0x3474b8(0x107), _0x1f27e2), _0x3474b8(0xb6));
62
+ }
63
+ },
64
+ 'aiShowAnimation': function (_0x149bd3) {
65
+ const _0x55444c = _0x4f0a97, _0x45a29b = document[_0x55444c(0xb8)](_0x55444c(0xf0));
66
+ if (!_0x45a29b)
67
+ return;
68
+ if (tianliGPTIsRunning)
69
+ return;
70
+ if (typeof tianliGPT_typingAnimate !== _0x55444c(0x10b) && !tianliGPT_typingAnimate) {
71
+ _0x45a29b[_0x55444c(0xb5)] = _0x149bd3;
72
+ return;
73
+ }
74
+ tianliGPTIsRunning = !![];
75
+ const _0x5b6ee1 = 0x19, _0x8f3029 = 0x3e8, _0x1f3f3e = 0x6;
76
+ _0x45a29b[_0x55444c(0xf9)][_0x55444c(0xe8)] = _0x55444c(0x101), _0x45a29b[_0x55444c(0xb5)] = _0x55444c(0xd2) + '<span\x20class=\x22blinking-cursor\x22></span>';
77
+ let _0x1fde59 = !![], _0x3d69d1 = 0x0, _0x322208 = !![], _0x2d8528 = performance[_0x55444c(0xe1)]();
78
+ const _0x338cdd = () => {
79
+ const _0x2a505e = _0x55444c;
80
+ if (_0x3d69d1 < _0x149bd3['length'] && _0x1fde59) {
81
+ const _0x2c1bb5 = performance[_0x2a505e(0xe1)](), _0x1feb63 = _0x2c1bb5 - _0x2d8528, _0xc28aa7 = _0x149bd3[_0x2a505e(0xf4)](_0x3d69d1, _0x3d69d1 + 0x1), _0x1aa492 = /[,。!、?,.!?]/[_0x2a505e(0xc9)](_0xc28aa7), _0x593d2e = _0x1aa492 ? _0x5b6ee1 * _0x1f3f3e : _0x5b6ee1;
82
+ _0x1feb63 >= _0x593d2e && (_0x45a29b[_0x2a505e(0xc1)] = _0x149bd3[_0x2a505e(0xf4)](0x0, _0x3d69d1 + 0x1), _0x2d8528 = _0x2c1bb5, _0x3d69d1++, _0x3d69d1 < _0x149bd3[_0x2a505e(0xf6)] ? _0x45a29b[_0x2a505e(0xb5)] = _0x149bd3[_0x2a505e(0xf4)](0x0, _0x3d69d1) + '<span\x20class=\x22blinking-cursor\x22></span>' : (_0x45a29b[_0x2a505e(0xb5)] = _0x149bd3, _0x45a29b[_0x2a505e(0xf9)][_0x2a505e(0xe8)] = _0x2a505e(0x101), tianliGPTIsRunning = ![], _0xa9ee27[_0x2a505e(0x100)]())), requestAnimationFrame(_0x338cdd);
83
+ }
84
+ }, _0xa9ee27 = new IntersectionObserver(_0x4d2d3c => {
85
+ const _0x4e6619 = _0x55444c;
86
+ let _0x5e29da = _0x4d2d3c[0x0][_0x4e6619(0xb7)];
87
+ _0x1fde59 = _0x5e29da, _0x1fde59 && _0x322208 && setTimeout(() => {
88
+ requestAnimationFrame(_0x338cdd);
89
+ }, 0xc8);
90
+ }, { 'threshold': 0x0 });
91
+ let _0x4dffd2 = document[_0x55444c(0xb8)](_0x55444c(0x110));
92
+ _0xa9ee27[_0x55444c(0x102)](_0x4dffd2);
93
+ }
94
+ };
95
+ function _0xc96971() {
96
+ const _0x29ebd0 = _0x4f0a97;
97
+ _0x4e2b78(tianliGPT_postSelector);
98
+ const _0x30618a = _0x5dd9a9['getTitleAndContent']();
99
+ if (_0x30618a) {
100
+ }
101
+ postUrlIsContained = null, tianligptJsonData && (postHref = window[_0x29ebd0(0x108)][_0x29ebd0(0xba)], postRegex = /\/+posts\/+([\w-]+)(\.html)?/, postMatch = postHref['match'](postRegex), postFilteredValue = postMatch ? postMatch[0x1] : null, postUrl = _0x29ebd0(0x103) + 'posts/' + postFilteredValue + _0x29ebd0(0xd9), postUrlIsContained = postsUrls[_0x29ebd0(0xb1)](postUrl)), postUrlIsContained ? (postMatchedSummary = tianligptJsonData[_0x29ebd0(0xc3)][_0x29ebd0(0xfd)](_0x5c6df1 => _0x5c6df1[_0x29ebd0(0xf1)] === postUrl), postSummary = postMatchedSummary['summary'], _0x5dd9a9[_0x29ebd0(0xac)](postSummary)) : _0x5dd9a9[_0x29ebd0(0xb4)](_0x30618a)[_0x29ebd0(0x104)](_0x328c83 => {
102
+ const _0x2a2a11 = _0x29ebd0;
103
+ _0x5dd9a9[_0x2a2a11(0xac)](_0x328c83);
104
+ });
105
+ }
106
+ function _0x4b2565() {
107
+ const _0x3b6435 = _0x4f0a97;
108
+ if (typeof tianliGPT_postURL === _0x3b6435(0x10b)) {
109
+ _0xc96971();
110
+ return;
111
+ }
112
+ try {
113
+ const _0x39c9c3 = _0x1ddbec => {
114
+ const _0x3955cd = _0x3b6435;
115
+ return new RegExp('^' + _0x1ddbec[_0x3955cd(0xad)](/\*+/)['map'](_0x1bb0a0)[_0x3955cd(0xd7)]('.*') + '$');
116
+ }, _0x1bb0a0 = _0x4542ea => {
117
+ const _0x2487d0 = _0x3b6435;
118
+ return _0x4542ea[_0x2487d0(0xbc)](/[|\\{}()[\]^$+*?.]/g, _0x2487d0(0xf5));
119
+ }, _0x35f7e5 = _0x39c9c3(tianliGPT_postURL), _0x19cafd = window[_0x3b6435(0x108)][_0x3b6435(0xba)];
120
+ if (_0x35f7e5[_0x3b6435(0xc9)](_0x19cafd))
121
+ _0xc96971();
122
+ else {
123
+ }
124
+ } catch (_0x59bd4c) {
125
+ console[_0x3b6435(0xd1)](_0x3b6435(0xeb), _0x59bd4c);
126
+ }
127
+ }
128
+ _0x4b2565();
129
+ }
130
+ xhr = new XMLHttpRequest(), xhr['open'](_0x54511a(0x106), _0x54511a(0xc7), ![]), xhr[_0x54511a(0xea)]();
131
+ function _0x512f(_0x353c91, _0x4affc9) {
132
+ const _0x98e530 = _0x98e5();
133
+ return _0x512f = function (_0x512fad, _0x8024ab) {
134
+ _0x512fad = _0x512fad - 0xac;
135
+ let _0x230486 = _0x98e530[_0x512fad];
136
+ return _0x230486;
137
+ }, _0x512f(_0x353c91, _0x4affc9);
138
+ }
139
+ if (xhr[_0x54511a(0xcb)] === 0xc8)
140
+ try {
141
+ tianligptJsonData = JSON[_0x54511a(0xc5)](xhr['responseText']), postsUrls = tianligptJsonData['summaries'][_0x54511a(0xd8)](_0x10a2ca => _0x10a2ca[_0x54511a(0xf1)]);
142
+ } catch (_0x559b5e) {
143
+ console[_0x54511a(0xd1)](_0x54511a(0xc0), _0x559b5e), tianligptJsonData = null;
144
+ }
145
+ else
146
+ console['error'](_0x54511a(0xed), xhr[_0x54511a(0xc8)]), tianligptJsonData = null;
147
+ whenDOMReadyTianliGPT(), document[_0x54511a(0xf3)](_0x54511a(0xde), whenDOMReadyTianliGPT);