JavaScript自动提示选择

huangapple go评论81阅读模式
英文:

Javascript automatic prompt choice

问题

这是一个来自提示的代码,当尝试向特定人发送电子邮件时出现,我想知道是否有可能在打开此提示时自动运行“继续”按钮,而无需单击它。一直在尝试自己实现,但我的JavaScript知识不允许我这样做。

示例提示

JavaScript自动提示选择

我尝试创建一个可以在Violentmonkey中实现的JavaScript代码,但我找不到实现的方法。

因此,代码的这部分负责“继续”的部分,但我无法想出如何使它自动按下:

Kn, {
  onClick: $,
  "data-testid": eI,
  children: re.formatMessage({
    id: "i18n.tco.ng.priceproposals.DIALOG_COMMUNICATION_SUBMIT"
  })

如果我理解正确,"继续"按钮的ID是这个:"Normalize_normalize__5biS5.Button_button__PnIym"。

所以我尝试创建了一些东西,但它不起作用:

(function() {
  'use strict';

  window.addEventListener('beforeunload', function(event) {
      event.preventDefault();
      event.returnValue = '';
  });

  window.alert = function(message) {
      console.log(message);
  };

  window.prompt = function(message) {
      console.log(message);
      return true;
  };

  window.confirm = function(message) {
      console.log(message);
      var continueAnywayButton = document.querySelector('Normalize_normalize__5biS5.Button_button__PnIym');
      if (continueAnywayButton) {
          continueAnywayButton.click();
          return true;
      } else {
          return false;
      }
  };
})();

希望这有帮助。

英文:

This is a code from the prompt which appears when trying to send an e-mail to specific people, and I wonder if it's possible to make "Continue anyway" run automatically when this prompt is opened without having to click it. Been trying to achieve it myself, but my Javascript knowledge doesn't allow me to do it.

Prompt example

JavaScript自动提示选择

I tried creating a javascript code that would be implemented in Violentmonkey, but I can't find a way to do it..

So this part of the code is responsible for "continue anyway" part, but I can't come up with a way to make it so that it's automatically pressed

ya.jsx)(Kn, {
  onClick: $,
  "data-testid": eI,
  children: re.formatMessage({
    id: "i18n.tco.ng.priceproposals.DIALOG_COMMUNICATION_SUBMIT"
  })

<!-- language: lang-js -->

JC = &quot;PriceProposalContactConfirmDialog/createPPLButton&quot;, eI = &quot;PriceProposalContactConfirmDialog/confirmButton&quot;, tI = &quot;PriceProposalContactConfirmDialog/abortButton&quot;, PriceProposalContactConfirmDialog = V =&gt; {
  let {
    onConfirm: $,
    onClose: Z,
    onClickOpenPriceProposalDialog: ee,
    showCreatePriceProposalButton: te
  } = V;
  const re = useIntl(),
    onClickCreatePriceProposal = () =&gt; {
      Z(),
        ee()
    };
  return (0,
    ya.jsx)(ConfirmDialog, {
    headline: re.formatMessage({
      id: &quot;i18n.tco.ng.priceproposals.DIALOG_COMMUNICATION_HEADER&quot;
    }),
    message: (0,
      ya.jsx)(&quot;div&quot;, {
      children: re.formatMessage({
        id: &quot;i18n.tco.ng.priceproposals.DIALOG_COMMUNICATION_INFO&quot;
      })
    }),
    onClose: Z,
    customFooter: te ? (0,
      ya.jsxs)(ya.Fragment, {
      children: [(0,
        ya.jsx)(Kn, {
        buttonStyle: &quot;primary&quot;,
        autoFocus: !0,
        onClick: onClickCreatePriceProposal,
        &quot;data-testid&quot;: JC,
        children: re.formatMessage({
          id: &quot;i18n.tco.ng.priceproposals.SUBMIT_DIALOG_HEADER&quot;
        })
      }), (0,
        ya.jsx)(Kn, {
        onClick: $,
        &quot;data-testid&quot;: eI,
        children: re.formatMessage({
          id: &quot;i18n.tco.ng.priceproposals.DIALOG_COMMUNICATION_SUBMIT&quot;
        })
      }), (0,
        ya.jsx)(Kn, {
        onClick: Z,
        buttonStyle: &quot;text&quot;,
        &quot;data-testid&quot;: tI,
        children: re.formatMessage({
          id: &quot;i18n.tco.ng.ABORT&quot;
        })
      })]
    }) : (0,
      ya.jsxs)(ya.Fragment, {
      children: [(0,
        ya.jsx)(Kn, { **
        onClick: $,
        buttonStyle: &quot;primary&quot;,
        autoFocus: !0,
        &quot;data-testid&quot;: eI,
        children: re.formatMessage({ **
          id: &quot;i18n.tco.ng.priceproposals.DIALOG_COMMUNICATION_SUBMIT&quot;
        })
      }), (0,
        ya.jsx)(Kn, {
        onClick: Z,
        buttonStyle: &quot;text&quot;,
        &quot;data-testid&quot;: tI,
        children: re.formatMessage({
          id: &quot;i18n.tco.ng.ABORT&quot;
        })
      })]
    })
  })
}

<!-- end snippet -->

If I understand it correctly, button ID for "Continue anyway" is this: "Normalize_normalize__5biS5.Button_button__PnIym"
JavaScript自动提示选择

So I tried creating something myself, but it doesn't work..

(function() {
&#39;use strict&#39;;

window.addEventListener(&#39;beforeunload&#39;, function(event) {
    event.preventDefault();
    event.returnValue = &#39;&#39;;
});

window.alert = function(message) {
    console.log(message);
};

window.prompt = function(message) {
    console.log(message);
    return true;
};

window.confirm = function(message) {
    console.log(message);
    var continueAnywayButton = document.querySelector(&#39;Normalize_normalize__5biS5.Button_button__PnIym&#39;);
    if (continueAnywayButton) {
        continueAnywayButton.click();
        return true;
    } else {
        return false;
    }
};

})();

答案1

得分: 1

谢谢你的评论,我想出了一种方法来检测出现提示时显示的文本,如果文本存在,则选择“继续 anyway” 选项。

JavaScript自动提示选择

英文:

Thank you for your comments, I came up with a way to detect a text shown when the prompt appears, and if the text is present, the "continue anyway" option is then selected.

JavaScript自动提示选择

huangapple
  • 本文由 发表于 2023年3月9日 20:47:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684834.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定