Skip to content

Instantly share code, notes, and snippets.

@rebane2001
Last active November 29, 2024 18:59
Show Gist options
  • Save rebane2001/6bd1e195ddb501c9ce76f2f3bd033b1b to your computer and use it in GitHub Desktop.
Save rebane2001/6bd1e195ddb501c9ce76f2f3bd033b1b to your computer and use it in GitHub Desktop.
Userscript that adds a button to Omniva's interface to immediately take you to eMTA and fill in the right fields. Use at your own discretion.
// ==UserScript==
// @name Omniva auto-declare
// @namespace rebane
// @match https://maasikas.emta.ee/smartdecl/wicket/page
// @match https://maasikas.emta.ee/smartdecl/parcel
// @match https://minu.omniva.ee/s/*
// @match https://minuold.omniva.ee/s/*
// @grant none
// @version 1.1
// @author rebane
// @description Userscript that adds a button to Omniva's interface to immediately take you to eMTA and fill in the right fields. Use at your own discretion.
// ==/UserScript==
function addEmtaButton() {
const tracking = document.querySelector(".info-step__h1")?.innerText;
if (!tracking) {
setTimeout(()=>addEmtaButton(), 100);
return;
}
const mrn = Array.from(document.querySelectorAll(".customs-overview-field__text")).find(e=>e.innerText.includes("MRN")).lastChild.textContent;
const params = `${tracking}:${mrn}`.replace(/[^\w:]/g, '');
const emtaUrl = `https://maasikas.emta.ee/smartdecl/parcel#${params}`;
const emtaLink = document.createElement('a');
emtaLink.innerText = "e-MTA autofill";
emtaLink.href = emtaUrl;
emtaLink.rel = "noreferrer";
emtaLink.classList.add("button2", "button2--primary", "customs__link");
document.querySelector(".customs__info").insertAdjacentElement("afterend", emtaLink);
}
function autofillRedirect() {
const pageId = parseInt(document.location.search.slice(1));
const targetUrl = `https://maasikas.emta.ee/smartdecl/parcel?${pageId}-1.ILinkListener-newDeclarationLink${document.location.hash}`;
document.location.href = targetUrl;
}
function attemptAutofill() {
const [tracking, mrn] = document.location.hash.slice(1).split(":");
document.querySelector("#id-parcel-nr").value = tracking;
document.querySelector("#id-prev-mrn").value = mrn;
document.querySelector("#id-check-nes").checked = true;
}
window.addEventListener("load", () => {
if (document.location.href.startsWith("https://minu.omniva.ee/s/") || document.location.href.startsWith("https://minuold.omniva.ee/s/")) {
addEmtaButton();
}
if (document.location.hash.includes(":")) {
switch (document.location.href.split("?")[0]) {
case "https://maasikas.emta.ee/smartdecl/parcel":
autofillRedirect();
break;
case "https://maasikas.emta.ee/smartdecl/wicket/page":
attemptAutofill();
break;
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment