stat2025 commited on
Commit
6fbaa52
ยท
verified ยท
1 Parent(s): 4be4e6c

Update app.js

Browse files
Files changed (1) hide show
  1. app.js +18 -11
app.js CHANGED
@@ -61,7 +61,13 @@ const arabicDigitsMap={"ู ":"0","ูก":"1","ูข":"2","ูฃ":"3","ูค":"4","ูฅ":"5","ูฆ
61
 
62
  function normalizeText(s){
63
  if(typeof s!=="string")return"";
64
- return s.replace(/\r\n/g,"\n").replace(/[\u200f\u200e\u202a-\u202e\u2066-\u2069\u00a0]/g," ").replace(/[ู -ูฉ]/g,d=>arabicDigitsMap[d]).replace(/[ู€ู€]+/g,"").replace(/[ \t]+\n/g,"\n").replace(/\n{3,}/g,"\n\n").trim();
 
 
 
 
 
 
65
  }
66
  function lettersOnly(ar){return(ar||"").replace(/[^A-Za-z\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\s]/g,"").replace(/\s{2,}/g," ").trim()}
67
  function alnumAr(s){return(s||"").replace(/[^0-9A-Za-z\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\s\-\._/]/g,"").replace(/\s{2,}/g," ").trim()}
@@ -74,7 +80,7 @@ const LABEL_FIXES=[
74
  [/(^|\n)\s*ุฑู‚ู…\s*ุงู„ู‡ูˆูŠู‡/gi,"$1ุฑู‚ู… ุงู„ู‡ูˆูŠุฉ"],
75
  [/(^|\n)\s*ุงู„ู…ู†ุทู‚ู‡/gi,"$1ุงู„ู…ู†ุทู‚ุฉ"],
76
  [/(^|\n)\s*ุงุณู…\s*ุงู„ู…ู†ุทู‚ุฉ/gi,"$1ุงู„ู…ู†ุทู‚ุฉ"],
77
- [/(^|\n)\ุณ*ุงุณู…\s*ุงู„ู…ุณุญ/gi,"$1ุงู„ู…ุณุญ"],
78
  [/(^|\n)\s*ุงู„ู‡ุงุชู/gi,"$1ุฑู‚ู… ุงู„ุฌูˆุงู„"],
79
  [/(^|\n)\s*ุฌูˆุงู„/gi,"$1ุฑู‚ู… ุงู„ุฌูˆุงู„"]
80
  ];
@@ -93,7 +99,7 @@ function hijriToGregorian(hy,hm,hd){
93
  let n=Math.floor(4*l/146097);l=l-Math.floor((146097*n+3)/4);
94
  let i=Math.floor(4000*(l+1)/1461001);l=l-Math.floor(1461*i/4)+31;
95
  let j=Math.floor(80*l/2447);const d=l-Math.floor(2447*j/80);
96
- l=Math.floor(j/11);const m=j+2-12*l;const y=100*(n-49)+i+l;
97
  return[y,m,d];
98
  }
99
  function isTimeOnly(t){
@@ -127,7 +133,7 @@ function normalizeDateOnly(raw){
127
  else if(c>31){y=c;mo=b;d=a}
128
  else{y=c;mo=b;d=a}
129
  if(y<100)y+=2000;
130
- if(mo>12&&ุฏ<=12){const tmp=mo;mo=d;d=tmp}
131
  if(mo<1||mo>12||d<1||d>31)return"";
132
  return`${String(y).padStart(4,"0")}-${String(mo).padStart(2,"0")}-${String(d).padStart(2,"0")}`
133
  }
@@ -153,7 +159,7 @@ function findBlockAfterLabel(text,labels,allLabels=START_LABELS){
153
  const esc=s=>s.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');
154
  const lblAlt=labels.map(esc).join("|");
155
  const allAlt=allLabels.map(esc).join("|");
156
- const re=new RegExp(`(?:^|\\n)\\s*(?:${lblAlt})\\s*(?::|๏ผš|\\s)\\s*([\\ุณ\\S]*?)(?=\\n\\s*(?:${allAlt})\\s*(?::|๏ผš|\\s)|$)`,"i");
157
  const m=hay.match(re);
158
  return m?m[1].trim():"";
159
  }
@@ -164,7 +170,13 @@ function splitTickets(raw){
164
  if(TICKET_SEP.test(text))return text.split(TICKET_SEP).map(p=>p.trim()).filter(Boolean);
165
  const niu=findStartsByLabels(text,["ู†ูˆุน ุงู„ู…ุดูƒู„ุฉ","ู†ูˆุน ุงู„ู…ุดูƒู„ู‡"]).sort((a,b)=>a-b);
166
  if(niu.length>=2){
167
- const parts=[];for(let i=0;i<niu.length;i++){const s=niu[i];const e=i+1<niu.length?niu[i+1]:text.length;const slice=text.slice(s,e).trim();if(slice)parts.push(slice)}
 
 
 
 
 
 
168
  if(parts.length)return parts;
169
  }
170
  return[text];
@@ -232,7 +244,6 @@ function parseTicketsWithExtras(raw,agentName,defaultRegion){
232
  if(!isValidNationalId(id))id="";
233
  if(!isPhoneNumber(phone))phone="";
234
  if(!dev&&isValidNationalId(id))dev=id;
235
- if(!dev&&!id&&phone)dev=phone;
236
  if(!id&&isValidNationalId(dev))id=dev;
237
  const dateOnly=f["ูˆู‚ุช ุญุฏูˆุซ ุงู„ู…ุดูƒู„ุฉ"]||"";
238
  return{
@@ -500,10 +511,8 @@ function updateThemeLabel(){
500
 
501
  function isUnlocked(){try{return localStorage.getItem("ticketParser_unlocked")==="1"}catch{return false}}
502
  function markUnlocked(){try{localStorage.setItem("ticketParser_unlocked","1")}catch{}}
503
-
504
  function getLockBtn(){return document.getElementById("lockBtn")||document.getElementById("unlockBtn")||document.querySelector('[data-action="unlock"]')}
505
  function getLockInput(){return document.getElementById("lockPass")||document.querySelector('input[type="password"][name="lock"]')}
506
-
507
  function showGate(){
508
  if(isUnlocked()){hideGate();return}
509
  const ov=document.getElementById("lockOverlay");
@@ -523,13 +532,11 @@ function tryUnlock(){
523
  if(m){m.hidden=false;setTimeout(()=>m.hidden=true,1500)}
524
  }
525
  }
526
-
527
  function wireLock(){
528
  const btn=getLockBtn();
529
  const inp=getLockInput();
530
  if(btn)btn.addEventListener("click",tryUnlock);
531
  if(inp)inp.addEventListener("keydown",e=>{if(e.key==="Enter")tryUnlock()});
532
- document.addEventListener("click",e=>{const t=e.target;if(t&&t.closest&&t.closest("#lockBtn, #unlockBtn, [data-action='unlock']"))tryUnlock()},{once:true});
533
  }
534
 
535
  function init(){
 
61
 
62
  function normalizeText(s){
63
  if(typeof s!=="string")return"";
64
+ return s.replace(/\r\n/g,"\n")
65
+ .replace(/[\u200f\u200e\u202a-\u202e\u2066-\u2069\u00a0]/g," ")
66
+ .replace(/[ู -ูฉ]/g,d=>arabicDigitsMap[d])
67
+ .replace(/[ู€ู€]+/g,"")
68
+ .replace(/[ \t]+\n/g,"\n")
69
+ .replace(/\n{3,}/g,"\n\n")
70
+ .trim();
71
  }
72
  function lettersOnly(ar){return(ar||"").replace(/[^A-Za-z\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\s]/g,"").replace(/\s{2,}/g," ").trim()}
73
  function alnumAr(s){return(s||"").replace(/[^0-9A-Za-z\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\s\-\._/]/g,"").replace(/\s{2,}/g," ").trim()}
 
80
  [/(^|\n)\s*ุฑู‚ู…\s*ุงู„ู‡ูˆูŠู‡/gi,"$1ุฑู‚ู… ุงู„ู‡ูˆูŠุฉ"],
81
  [/(^|\n)\s*ุงู„ู…ู†ุทู‚ู‡/gi,"$1ุงู„ู…ู†ุทู‚ุฉ"],
82
  [/(^|\n)\s*ุงุณู…\s*ุงู„ู…ู†ุทู‚ุฉ/gi,"$1ุงู„ู…ู†ุทู‚ุฉ"],
83
+ [/(^|\n)\s*ุงุณู…\s*ุงู„ู…ุณุญ/gi,"$1ุงู„ู…ุณุญ"],
84
  [/(^|\n)\s*ุงู„ู‡ุงุชู/gi,"$1ุฑู‚ู… ุงู„ุฌูˆุงู„"],
85
  [/(^|\n)\s*ุฌูˆุงู„/gi,"$1ุฑู‚ู… ุงู„ุฌูˆุงู„"]
86
  ];
 
99
  let n=Math.floor(4*l/146097);l=l-Math.floor((146097*n+3)/4);
100
  let i=Math.floor(4000*(l+1)/1461001);l=l-Math.floor(1461*i/4)+31;
101
  let j=Math.floor(80*l/2447);const d=l-Math.floor(2447*j/80);
102
+ l=Math.floor(j/11);const m=j+2-12*l;const y=100*(ู†-49)+i+l;
103
  return[y,m,d];
104
  }
105
  function isTimeOnly(t){
 
133
  else if(c>31){y=c;mo=b;d=a}
134
  else{y=c;mo=b;d=a}
135
  if(y<100)y+=2000;
136
+ if(mo>12&&d<=12){const tmp=mo;mo=d;d=tmp}
137
  if(mo<1||mo>12||d<1||d>31)return"";
138
  return`${String(y).padStart(4,"0")}-${String(mo).padStart(2,"0")}-${String(d).padStart(2,"0")}`
139
  }
 
159
  const esc=s=>s.replace(/[.*+?^${}()|[\]\\]/g,'\\$&');
160
  const lblAlt=labels.map(esc).join("|");
161
  const allAlt=allLabels.map(esc).join("|");
162
+ const re=new RegExp(`(?:^|\\n)\\s*(?:${lblAlt})\\s*(?::|๏ผš|\\s)\\s*([\\s\\S]*?)(?=\\n\\s*(?:${allAlt})\\s*(?::|๏ผš|\\s)|$)`,"i");
163
  const m=hay.match(re);
164
  return m?m[1].trim():"";
165
  }
 
170
  if(TICKET_SEP.test(text))return text.split(TICKET_SEP).map(p=>p.trim()).filter(Boolean);
171
  const niu=findStartsByLabels(text,["ู†ูˆุน ุงู„ู…ุดูƒู„ุฉ","ู†ูˆุน ุงู„ู…ุดูƒู„ู‡"]).sort((a,b)=>a-b);
172
  if(niu.length>=2){
173
+ const parts=[];
174
+ for(let i=0;i<niu.length;i++){
175
+ const s=niu[i];
176
+ const e=i+1<niu.length?niu[i+1]:text.length;
177
+ const slice=text.slice(s,e).trim();
178
+ if(slice)parts.push(slice);
179
+ }
180
  if(parts.length)return parts;
181
  }
182
  return[text];
 
244
  if(!isValidNationalId(id))id="";
245
  if(!isPhoneNumber(phone))phone="";
246
  if(!dev&&isValidNationalId(id))dev=id;
 
247
  if(!id&&isValidNationalId(dev))id=dev;
248
  const dateOnly=f["ูˆู‚ุช ุญุฏูˆุซ ุงู„ู…ุดูƒู„ุฉ"]||"";
249
  return{
 
511
 
512
  function isUnlocked(){try{return localStorage.getItem("ticketParser_unlocked")==="1"}catch{return false}}
513
  function markUnlocked(){try{localStorage.setItem("ticketParser_unlocked","1")}catch{}}
 
514
  function getLockBtn(){return document.getElementById("lockBtn")||document.getElementById("unlockBtn")||document.querySelector('[data-action="unlock"]')}
515
  function getLockInput(){return document.getElementById("lockPass")||document.querySelector('input[type="password"][name="lock"]')}
 
516
  function showGate(){
517
  if(isUnlocked()){hideGate();return}
518
  const ov=document.getElementById("lockOverlay");
 
532
  if(m){m.hidden=false;setTimeout(()=>m.hidden=true,1500)}
533
  }
534
  }
 
535
  function wireLock(){
536
  const btn=getLockBtn();
537
  const inp=getLockInput();
538
  if(btn)btn.addEventListener("click",tryUnlock);
539
  if(inp)inp.addEventListener("keydown",e=>{if(e.key==="Enter")tryUnlock()});
 
540
  }
541
 
542
  function init(){