Automatically extracts invoice data and registers payments on Moneybird
Size
2.4 KB
Version
1.0.1
Created
Jan 14, 2026
Updated
21 days ago
1// ==UserScript==
2// @name Moneybird Auto Payment Registration
3// @description Automatically extracts invoice data and registers payments on Moneybird
4// @version 1.0.1
5// @match https://*.moneybird.com/*
6// @icon https://assets-app-cdn.moneybird.com/assets/favicon-b1fb00eb89b4530acc973e4c2cd93f58f7fc4095a79f9bb2a7d88f692b994273.ico
7// ==/UserScript==
8(function() {
9 'use strict';
10
11 // Debounce function to prevent multiple rapid executions
12 function debounce(func, wait) {
13 let timeout;
14 return function executedFunction(...args) {
15 const later = () => {
16 clearTimeout(timeout);
17 func(...args);
18 };
19 clearTimeout(timeout);
20 timeout = setTimeout(later, wait);
21 };
22 }
23
24 async function init() {
25 console.log('Moneybird Auto Payment Registration - Starting');
26
27 // Extract invoice date
28 const dateElement = document.querySelector('p.document-date');
29 if (dateElement) {
30 const invoiceDate = dateElement.textContent.trim();
31 console.log('Invoice Date:', invoiceDate);
32 } else {
33 console.log('Invoice date not found');
34 }
35
36 // Extract contact name
37 const contactElement = document.querySelector('p.document-contact a[href*="/contacts/"]');
38 if (contactElement) {
39 const contactName = contactElement.textContent.trim();
40 console.log('Contact Name:', contactName);
41 } else {
42 console.log('Contact name not found');
43 }
44
45 // Click the "Register Payment" button
46 const registerPaymentButton = document.querySelector('a.btn.btn--secondary[title="Registreer betaling"][href*="/payments/new"]');
47 if (registerPaymentButton) {
48 console.log('Register Payment button found, clicking...');
49 registerPaymentButton.click();
50 } else {
51 console.log('Register Payment button not found');
52 }
53 }
54
55 // Wait for the page to be fully loaded
56 if (document.readyState === 'loading') {
57 document.addEventListener('DOMContentLoaded', init);
58 } else {
59 init();
60 }
61
62 // Observe DOM changes in case content loads dynamically
63 const debouncedInit = debounce(init, 1000);
64 const observer = new MutationObserver(debouncedInit);
65
66 if (document.body) {
67 observer.observe(document.body, {
68 childList: true,
69 subtree: true
70 });
71 }
72})();