Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

285
Vistas
Adding a hotkey with a Tamper Monkey script

I'm new to tamper monkey and trying to write a script that allows me to press a hotkey and have it search through the page and open a URL based on the results of that search. Here's the code I have so far:

 // ==UserScript==
// @name         Paragon to Paramount Debug Forwarding
// @namespace    http://tampermonkey.net/
// @version      1
// @description  cntrl-click forwarding from a paragon run diag to paramount debugger
// @author       taurone
// @run-at       document-start
// ==/UserScript==

function getElementByXPath(path) {
  return document.evaluate(
    path,
    document,
    null,
    XPathResult.FIRST_ORDERED_NODE_TYPE,
    null
  ).singleNodeValue.nodeValue;
}

function openDebugURL(runDiag) {
  let runDiagURL = `https://my_website.com/#/debugger/${runDiag}`;
  window.open(runDiagURL);
}

function iterateThroughWorkflowTabs() {
  let workflowTabs = document.getElementsByClassName("a-tabs")[0].children;
  let tabCounter = 1;
  let runDiag;

  for (tab of workflowTabs) {
    if (tab.className.includes("active")) {
      try {
        runDiag = getElementByXPath(
          "/html/body/div[9]/div/div[2]/div/div[2]/div[2]/div/div[3]/div/div/div/pm-tab-set/div[" +
            String(tabCounter) +
            "]/pm-tab/ng-transclude/ng-transclude/pm-card/div/pm-workflow-card/div/div[2]/workflow-step-templates/div/workflow-default-step/div/div[3]/div/div[1]/div/pm-continue-button/div/aui-button/span/@data-csm-meta-pm-diagrunid"
        );
      } catch {
        runDiag = getElementByXPath(
          "/html/body/div[9]/div/div[2]/div/div[2]/div[2]/div/div[3]/div/div/div/pm-tab-set/div[" +
            String(tabCounter) +
            "]/pm-tab/ng-transclude/ng-transclude/pm-card/div/pm-workflow-card/div/div[2]/workflow-step-templates/div/workflow-default-step/div/div[3]/div/div[2]/label/@data-csm-meta-pm-diagrunid"
        );
      }
      openDebugURL(runDiag);
      return;
    }
    tabCounter++;
  }
}

function doc_keyUp(e) {
  if (e.altKey && e.key === "w") {
    unsafeWindow.iterateThroughWorkflowTabs();
  }
}

document.addEventListener("keyup", doc_keyUp, false);

In reading the Stack Overflow question adding-a-custom-keyboard-shortcut-using-userscript-to-chrome-with-tampermonkey and the unsafeWindow documentation, it seemed like it would be as simple as adding unsafeWindow before my function calls, but that isn't working. I've tried just inserting the code into the console and it works when I do that. It seems like there is some sort of setup on Tamper Monkey that I don't understand. Any input would be greatly appreciated. Thank you

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It looks like the unsafeWindow was actually the problem to running the page. When I changed

function doc_keyUp(e) {
  if (e.altKey && e.key === "w") {
    unsafeWindow.iterateThroughWorkflowTabs();
  }
}

to

function doc_keyUp(e) {
  if (e.altKey && e.key === "w") {
    iterateThroughWorkflowTabs();
  }
}

The script ran without a problem

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda