E-Arşiv Portal PDF

Düzenlenen faturalar PDF indirme butonu

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
    }
  });
}