Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

284
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda