c-stone-invoice-check/tools/accountable_helfer.js
Markus Kruse 4f9bec81fe feat(tools): Qonto-Abgleich, Mailsuche, PDF-Export, Accountable-Helfer
Wiederverwendbare Session-Skripte parametrisiert ins Repo; Cron Wochenlauf in README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Wd9aeEvgYF6ZmZGc5PTULK
2026-11-15 19:25:53 +01:00

20 lines
No EOL
4.1 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Accountable-Browser-Helfer: Banktx "Zu kategorisieren" -> neue Ausgabe (Kategorie-Check, USt-Button, Speichern).
// Nutzung: im eingeloggten Accountable-Tab (Bank-Ansicht) per DevTools/javascript_tool einfügen, dann z.B.
// __bg([['suchbegriff', /regex-auf-zeilentext/, '19%']]); // vat: Button-Text, z.B. '19%', '0%', 'Ausländische USt.'
// Fortschritt: window.__log / window.__running / window.__cur. Bricht beim ersten Nicht-OK ab und verwirft das Formular.
// JS-Aufrufe < 45 s halten -> __bg läuft im Hintergrund, Status abfragen. Kontonummer der tx immer prüfen (privates Girokonto!).
window.__t=e=>(e.innerText||"").replace(/\u00AD/g,"").trim();
window.__sleep=ms=>new Promise(r=>setTimeout(r,ms)); window.__btn=t=>[...document.querySelectorAll('button')].find(x=>__t(x)===t);
window.__kat=()=>{const l=[...document.querySelectorAll('label,span,div,p')].find(e=>__t(e)==='Kategorie'&&e.children.length===0); let n=l; for(let i=0;i<4&&n;i++){n=n.parentElement; const t=__t(n).replace('Kategorie','').replace('Kann ich das absetzen?','').trim(); if(t) return t.split('\n')[0];} return '?';};
window.__ust=()=>{const u=[...document.querySelectorAll('div,span,p')].find(e=>/^USt\.: /.test(__t(e))&&e.children.length===0); return u?__t(u):'-';};
window.__closeRating=()=>{const d=[...document.querySelectorAll('div')].find(x=>/Gefällt dir Accountable/.test(__t(x))&&__t(x).length<200); if(d){const b=d.querySelector('button'); b&&b.click();}};
window.__search=async q=>{const inp=[...document.querySelectorAll('input')].find(i=>/Suche/.test((i.placeholder||'').replace(/­/g,''))); Object.getOwnPropertyDescriptor(HTMLInputElement.prototype,'value').set.call(inp,q); inp.dispatchEvent(new Event('input',{bubbles:true})); await __sleep(2500);};
window.__clickText=async(re)=>{const c=[...document.querySelectorAll('*')].filter(e=>re.test(__t(e))&&__t(e).length<80); if(!c.length) return false; const el=c[c.length-1]; (el.closest('button,[role=button],a')||el).click(); await __sleep(1500); return true;};
window.__discard=async()=>{ if(__btn('Schließen')){ __btn('Schließen').click(); await __sleep(800); const ja=__btn('Ja'); if(ja){ja.click(); await __sleep(800);} } };
window.__one=async(match,vat)=>{ const rows=[...document.querySelectorAll('tr')].filter(r=>{const t=__t(r).replace(/\s+/g,' '); return /Zu kategorisieren\s+-/.test(t)&&match.test(t.toLowerCase());}); if(!rows.length) return 'NONE'; const r=rows[0]; const desc=__t(r).replace(/\s+/g,' ').slice(0,60); const name=[...r.querySelectorAll('td')][1]||r; (name.querySelector('*')||name).click(); await __sleep(1800);
let ok=await __clickText(/^Neue Ausgabe erstellen/); if(!ok){ ok=await __clickText(/^Geschäftliche Ausgabe$/); if(ok) ok=await __clickText(/^Als neue Ausgabe hinzufügen/);} if(!ok||!__btn('Speichern')) return 'NOFORM '+desc;
const k=__kat(); if(!k||/Bitte|\?/.test(k)) return 'STOP-KAT '+k+' | '+desc; const b=__btn(vat); if(!b) return 'NOVAT '+desc; b.click(); await __sleep(700);
if(vat==='0%'){ const lab=[...document.querySelectorAll('*')].find(e=>/^Warum ist auf dieser Ausgabe keine USt/.test(__t(e))&&e.children.length===0); if(lab){ let n=lab.parentElement; const dd=n.querySelector('button,[role=combobox],[role=button]')||n.nextElementSibling; (dd.querySelector('button,[role=button]')||dd).click(); await __sleep(1000); const opt=[...document.querySelectorAll('*')].filter(e=>/^Der Artikel ist von der USt\. befreit/.test(__t(e))); if(!opt.length) return 'NOREASON '+desc; const o=opt[opt.length-1]; (o.closest('button,[role=button],label')||o.parentElement).click(); await __sleep(800);} }
const u=__ust(); if(vat==='Ausländische USt.'&&u!=='-') return 'STOP-UST '+u; __btn('Speichern').click(); await __sleep(2200); __closeRating(); if(__btn('Speichern')) return 'NOTSAVED '+desc; return 'OK '+k+' '+vat+' '+u+' | '+desc;};
window.__bg=async(jobs)=>{window.__running=true; for(const [q,re,vat] of jobs){ window.__cur=q; await __search(q); for(let i=0;i<120;i++){ const o=await __one(re,vat); if(o==='NONE'){__log.push(q+': fertig');break;} __log.push(o); if(!o.startsWith('OK')){ await __discard(); __log.push(q+': abgebrochen'); break;} await __sleep(400);} } window.__running=false; };
window.__log=[];"ok"