coyoteazul / imprime_certificados_bcra

// ==UserScript==
// @name         imprime_certificados_bcra
// @namespace    imprime_certificados_bcra
// @version      0.1
// @description  try to take over the world!
// @author       coyoteazul
// @include      https://www5.bcra.gob.ar/activosypasivosexternos/*
// @copyright 2020, coyoteazul (https://openuserjs.org/users/coyoteazul)
// @license MIT
// @grant        none
// @updateURL    https://openuserjs.org/meta/coyoteazul/imprime_certificados_bcra.meta.js
// ==/UserScript==

function print_link() {
  'use strict';

  var links = document.getElementsByTagName("a");

  for (var i = 0; i < links.length; i++) {
    if (links[i].innerHTML == "Detalles") {
      var detalle = links[i].href;
      links[i].href = detalle.replace("Details", "ExportarDetalle");
      links[i].target = "_blank";
      links[i].click();
      links[i].href = detalle;
    }
  }
}

console.log(window.location);
if (window.location.href == "https://www5.bcra.gob.ar/activosypasivosexternos/EZ_02_03_01/index" ||
  window.location.href == "https://www5.bcra.gob.ar/activosypasivosexternos/EZ_02_03_01/" ||
  window.location.href == "https://www5.bcra.gob.ar/activosypasivosexternos/EZ_02_03_02/index" ||
  window.location.href == "https://www5.bcra.gob.ar/activosypasivosexternos/EZ_02_03_02/"
) {
  print_link();
}
else if (window.location.href.includes("https://www5.bcra.gob.ar/activosypasivosexternos/EZ_02_03_01/ExportarDetalle/") ||
  window.location.href.includes("https://www5.bcra.gob.ar/activosypasivosexternos/EZ_02_03_02/ExportarDetalle/")) {
  var ente = document.getElementsByTagName("dd")[9].innerHTML;
  var periodo = document.getElementsByTagName("dd")[4].innerHTML;

  var tempTitle = document.title;
  document.title = "Validacion " + ente + " " + periodo + ".pdf";
  window.print();
}