E-Arşiv Portal PDF

Düzenlenen faturalar PDF indirme butonu

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         E-Arşiv Portal PDF
// @namespace    http://tampermonkey.net/
// @version      2025-02-13
// @description  Düzenlenen faturalar PDF indirme butonu
// @author       Deniz Tunç
// @license GPLv3
// @match        https://earsivportal.efatura.gov.tr/index.jsp*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=gov.tr
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    entry()

})();

async function entry() {
  await waitForElement("div[rel='leftMenu'] ul ul li:nth-child(2) a", false);
  document.querySelector("div[rel='leftMenu'] ul ul li:nth-child(2) a").addEventListener("click", async () => {
    await waitForElement("div[rel='goster']")
    createButton()
  })
}

function createButton() {
  let goster = document.querySelector("*[rel='goster']")

  let pdf = goster.cloneNode(true)
  pdf.setAttribute("rel", "pdf")
  pdf.querySelector("input").value = "PDF"
  pdf.querySelector("i.fa").classList.replace("fa-file-text","fa-print")
  pdf.querySelector("input").onclick = async () => {
    console.log(goster.querySelector("input"))
    goster.querySelector("input").click()
    await waitForElement("iframe.csc-iframe")
    console.log(document.querySelector("iframe.csc-iframe"))
    document.querySelector("iframe.csc-iframe").contentWindow.print()
  }

  goster.parentElement.insertBefore(
    pdf, goster.parentElement.childNodes[1])
}

function waitForElement(selector, timeout = 30000) {
  return new Promise((resolve, reject) => {
    // Immediately check if the element already exists
    const element = document.querySelector(selector);
    if (element) {
      return resolve(element);
    }

    // Set up MutationObserver to watch for DOM changes
    const observer = new MutationObserver((mutations, obs) => {
      // Check if element exists after each DOM change
      const element = document.querySelector(selector);
      if (element) {
        obs.disconnect(); // Stop observing
        resolve(element);
      }
    });

    // Start observing the entire document for changes
    observer.observe(document, {
      childList: true,
      subtree: true
    });

    // Set timeout to prevent infinite waiting
    if (timeout) {
      setTimeout(() => {
        observer.disconnect();
        reject(new Error(`Element ${selector} not found within ${timeout}ms`));
      }, timeout);
    }
  });
}