0

我正在尝试为 DeviantArt 创建一个脚本,当我按下删除键时单击“从通知中删除”。Deviantart 允许用户关注艺术家并在通用通知系统下提供任何新的艺术作品。当您单击通知中的某些艺术品时,右侧有一个按钮,可让用户从通知中删除该艺术品。

图片链接

这是我尝试过的代码不起作用。

// ==UserScript==
// @name           Deviations remove shortcut
// @namespace      DeviationsRemShortcut
// @include      http://www.deviantart.com/art/*
// @include      https://www.deviantart.com/art/*
// ==/UserScript==

(function(){
document.addEventListener('keydown', function(e) {
 // pressed del
  if (e.keyCode == 46 && !e.shiftKey && !e.ctrlKey && !e.altKey &&     !e.metaKey) {
  document.querySelector(".remove-message-button").click(); // this will trigger the click event
  }
}, false);
})();

当我手动输入 document.querySelector(".remove-message-button").click(); 进入控制台,它按预期工作。

4

1 回答 1

0

我假设您想Remove from notifications通过按下一个键来为该功能创建一个快捷键。

我在网上找到了一段示例代码http://jsfiddle.net/arunpjohny/SZ9TG/1/

要让它工作,请将光标移动到 UI 输出区域,然后单击输出部分的任意位置,我认为这样它就知道您在此窗口中。然后它听你的keydown事件。它使用window.addEventListener而不是document.addEventListener

于 2017-06-24T03:46:38.330 回答