我正在尝试为 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(); 进入控制台,它按预期工作。