update mao

This commit is contained in:
chuqiuyu committed 2023-08-19 23:25:01 +08:00
1 parent a29e443ae4
commit 3abb72244a
3 files changed
+3

No files matched your search

+1
View File
@@ -0,0 +1 @@
var e,pe,t=function(){return(t=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)},n={xml:!1,decodeEntities:!0},r={_useHtmlParser2:!0,xmlMode:!0};function i(e){return null!=e&&e.xml?"boolean"==typeof e.xml?r:t(t({},r),e.xml):null!=e?e:void 0}!function(e){e.Root="root",e.Text="text",e.Directive="directive",e.Comment="comment",e.Script="script",e.Style="style",e.Tag="tag",e.CDATA="cdata",e.Doctype="doctype"}(e=e||{});const s=e.Root,a=e.Text,o=e.Directive,c=e.Comment,u=e.Script,l=e.Style,h=e.Tag,f=e.CDATA,p=e.Doctype;class d{constructor(){this.parent=null,this.prev=null,this.next=null,this.startIndex=null,this.endIndex=null}get parentNode(){return this.parent}set parentNode(e){this.parent=e}get previousSibling(){return this.prev}set previousSibling(e){this.prev=e}get nextSibling(){return this.next}set nextSibling(e){this.next=e}cloneNode(e=!1){return L(this,e)}}class m extends d{constructor(e){super(),this.data=e}get nodeValue(){return this.data}set nodeValue(e){this.data=e}}class _ extends m{constructor(){super(...arguments),this.type=e.Text}get nodeType(){return 3}}class E extends m{constructor(){super(...arguments),this.type=e.Comment}get nodeType(){return 8}}class T extends m{constructor(t,n){super(n),this.name=t,this.type=e.Directive}get nodeType(){return 1}}class A extends d{constructor(e){super(),this.children=e}get firstChild(){var e;return null!=(e=this.children[0])?e:null}get lastChild(){return 0<this.children.length?this.children[this.children.length-1]:null}get childNodes(){return this.children}set childNodes(e){this.children=e}}class g extends A{constructor(){super(...arguments),this.type=e.CDATA}get nodeType(){return 4}}class v extends A{constructor(){super(...arguments),this.type=e.Root}get nodeType(){return 9}}class y extends A{constructor(t,n,r=[],i="script"===t?e.Script:"style"===t?e.Style:e.Tag){super(r),this.name=t,this.attribs=n,this.type=i}get nodeType(){return 1}get tagName(){return this.name}set tagName(e){this.name=e}get attributes(){return Object.keys(this.attribs).map(e=>{var t;return{name:e,value:this.attribs[e],namespace:null==(t=this["x-attribsNamespace"])?void 0:t[e],prefix:null==(t=this["x-attribsPrefix"])?void 0:t[e]}})}}function S(t){return t.type===e.Tag||t.type===e.Script||t.type===e.Style}function C(t){return t.type===e.CDATA}function N(t){return t.type===e.Text}function b(t){return t.type===e.Comment}function I(t){return t.type===e.Directive}function O(t){return t.type===e.Root}function k(e){return Object.prototype.hasOwnProperty.call(e,"children")}function L(e,t=!1){let n;if(N(e))n=new _(e.data);else if(b(e))n=new E(e.data);else if(S(e)){const r=t?D(e.children):[],i=new y(e.name,{...e.attribs},r);r.forEach(e=>e.parent=i),null!=e.namespace&&(i.namespace=e.namespace),e["x-attribsNamespace"]&&(i["x-attribsNamespace"]={...e["x-attribsNamespace"]}),e["x-attribsPrefix"]&&(i["x-attribsPrefix"]={...e["x-attribsPrefix"]}),n=i}else if(C(e)){const r=t?D(e.children):[],i=new g(r);r.forEach(e=>e.parent=i),n=i}else if(O(e)){const r=t?D(e.children):[],i=new v(r);r.forEach(e=>e.parent=i),e["x-mode"]&&(i["x-mode"]=e["x-mode"]),n=i}else{if(!I(e))throw new Error("Not implemented yet: "+e.type);{const t=new T(e.name,e.data);null!=e["x-name"]&&(t["x-name"]=e["x-name"],t["x-publicId"]=e["x-publicId"],t["x-systemId"]=e["x-systemId"]),n=t}}return n.startIndex=e.startIndex,n.endIndex=e.endIndex,null!=e.sourceCodeLocation&&(n.sourceCodeLocation=e.sourceCodeLocation),n}function D(e){var t=e.map(e=>L(e,!0));for(let e=1;e<t.length;e++)t[e].prev=t[e-1],t[e-1].next=t[e];return t}const R={withStartIndices:!1,withEndIndices:!1,xmlMode:!1};class w{constructor(e,t,n){this.dom=[],this.root=new v(this.dom),this.done=!1,this.tagStack=[this.root],this.lastNode=null,this.parser=null,"function"==typeof t&&(n=t,t=R),"object"==typeof e&&(t=e,e=void 0),this.callback=null!=e?e:null,this.options=null!=t?t:R,this.elementCB=null!=n?n:null}onparserinit(e){this.parser=e}onreset(){this.dom=[],this.root=new v(this.dom),this.done=!1,this.tagStack=[this.root],this.lastNode=null,this.parser=null}onend(){this.done||(this.done=!0,this.parser=null,this.handleCallback(null))}onerror(e){this.handleCallback(e)}onclosetag(){this.lastNode=null;var e=this.tagStack.pop();this.options.withEndIndices&&(e.endIndex=this.parser.endIndex),this.elementCB&&this.elementCB(e)}onopentag(t,n){var r=this.options.xmlMode?e.Tag:void 0,t=new y(t,n,void 0,r);this.addNode(t),this.tagStack.push(t)}ontext(t){var n=this.lastNode;if(n&&n.type===e.Text)n.data+=t,this.options.withEndIndices&&(n.endIndex=this.parser.endIndex);else{const e=new _(t);this.addNode(e),this.lastNode=e}}oncomment(t){this.lastNode&&this.lastNode.type===e.Comment?this.lastNode.data+=t:(t=new E(t),this.addNode(t),this.lastNode=t)}oncommentend(){this.lastNode=null}oncdatastart(){var e=new _(""),t=new g([e]);this.addNode(t),e.parent=t,this.lastNode=e}oncdatLine truncated
+1
View File
@@ -0,0 +1 @@
function compareTwoStrings(first,second){if((first=first.replace(/\s+/g,""))===(second=second.replace(/\s+/g,"")))return 1;if(first.length<2||second.length<2)return 0;var firstBigrams=new Map;for(let i=0;i<first.length-1;i++){var bigram=first.substring(i,i+2),count=firstBigrams.has(bigram)?firstBigrams.get(bigram)+1:1;firstBigrams.set(bigram,count)}let intersectionSize=0;for(let i=0;i<second.length-1;i++){const bigram=second.substring(i,i+2),count=firstBigrams.has(bigram)?firstBigrams.get(bigram):0;0<count&&(firstBigrams.set(bigram,count-1),intersectionSize++)}return 2*intersectionSize/(first.length+second.length-2)}function findBestMatch(mainString,targetStrings){var ratings=[];let bestMatchIndex=0;for(let i=0;i<targetStrings.length;i++){var currentTargetString=targetStrings[i],currentRating=compareTwoStrings(mainString,currentTargetString);ratings.push({target:currentTargetString,rating:currentRating}),currentRating>ratings[bestMatchIndex].rating&&(bestMatchIndex=i)}return{ratings:ratings,bestMatch:ratings[bestMatchIndex],bestMatchIndex:bestMatchIndex}}function lcs(str1,str2){if(!str1||!str2)return{length:0,sequence:"",offset:0};for(var sequence="",str1Length=str1.length,str2Length=str2.length,num=new Array(str1Length),maxlen=0,lastSubsBegin=0,i=0;i<str1Length;i++){for(var subArray=new Array(str2Length),j=0;j<str2Length;j++)subArray[j]=0;num[i]=subArray}for(var thisSubsBegin=null,i=0;i<str1Length;i++)for(j=0;j<str2Length;j++)str1[i]!==str2[j]?num[i][j]=0:(num[i][j]=0===i||0===j?1:1+num[i-1][j-1],num[i][j]>maxlen&&(maxlen=num[i][j],lastSubsBegin===(thisSubsBegin=i-num[i][j]+1)?sequence+=str1[i]:(lastSubsBegin=thisSubsBegin,sequence="",sequence+=str1.substr(lastSubsBegin,i+1-lastSubsBegin))));return{length:maxlen,sequence:sequence,offset:thisSubsBegin}}function findBestLCS(mainString,targetStrings){var results=[];let bestMatchIndex=0;for(let i=0;i<targetStrings.length;i++){var currentTargetString=targetStrings[i],currentLCS=lcs(mainString,currentTargetString);results.push({target:currentTargetString,lcs:currentLCS}),currentLCS.length>results[bestMatchIndex].lcs.length&&(bestMatchIndex=i)}return{allLCS:results,bestMatch:results[bestMatchIndex],bestMatchIndex:bestMatchIndex}}export{compareTwoStrings,findBestMatch,findBestLCS};
+1
View File
@@ -0,0 +1 @@
function isSub(ext){return"srt"==ext||"ass"==ext||"ssa"==ext}function getSize(size){return size<=0?"":1099511627776<size?(size/=1099511627776).toFixed(2)+"TB":1073741824<size?(size/=1073741824).toFixed(2)+"GB":1048576<size?(size/=1048576).toFixed(2)+"MB":(size/=1024).toFixed(2)+"KB"}function removeExt(text){return-1<text.indexOf(".")?text.substring(0,text.lastIndexOf(".")):text}async function log(str){}export{isSub,getSize,removeExt,log};