1

目标是为谷歌的谷歌翻译工具包添加键盘快捷键。那里的大多数功能都有键盘快捷键,但这两个没有。

第一个函数称为 Merge Down。执行此小书签时,它会正确触发:

javascript:document.evaluate("//div[(@id='gtc-merge-arent')]/div[(@class='modal-dialog
gtc-merge')]/div[(@class='modal-dialog-buttons')]/button[(text()='OK')]",    document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,
null).singleNodeValue.click();

Apply to All 功能比较复杂。通常您必须单击三次才能执行此功能:

#1单击使“重复”对话框可见并设置参数的按钮:用什么替换什么。
#2单击“全部应用”并在整个
#3中触发实际替换以隐藏对话框元素。

我不想弄乱谷歌的内部代码,所以像鼠标一样正常点击是最好的。

#2和#3很容易触发:相同的书签,有一个暂停:

javascript:(function(pause) { 
document.evaluate("//div[(@id='fnrDialogParent')]/div[(@class='modal-dialog gtc-rep-modal-dialog')]/div[(@class='modal-dialog-buttons')]/button[(text()='Apply to all')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();
setTimeout(() => document.evaluate("//div[(@id='fnrDialogParent')]/div[(@class='modal-dialog gtc-rep-modal-dialog')]/div[(@class='modal-dialog-buttons')]/button[(text()='Exit')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click(), pause) 
            })(400);

我无法模拟单击“重复”按钮,该按钮应该会弹出我需要单击以完成工作的两个按钮。按钮本身是一个 iframe 内带有 img 的 div。我尝试了大多数我在这里找到的点击模拟方法,最新的是这个,但它并不完全一样(参考正确)

var ifrm = document.querySelectorAll('iframe')[2];<br> 
$(ifrm).contents().find('img.jfk-button-img.gtc-img-rep').click();

(按钮本身是一个内部带有 img 的 div。根据片段是否在其他地方重复,该按钮是启用还是禁用。这是启用按钮的 HTML 代码:

<div role="button" class="goog-inline-block jfk-button jfk-button-standard jfk-button-narrow jfk-button-collapse-left jfk-button-collapse-right jfk-button-clear-outline" tabindex="0" id="goog-gtc-repbutton" aria-label="Repeated: 3" data-tooltip="Repeated: 3" style="user-select: none;"><img src="./images/cleardot.gif" class="jfk-button-img gtc-img-rep" style="width: 21px; height: 21px;"></div>
4

1 回答 1

0
javascript: (function() {
    const a = f => new MouseEvent(f, { bubbles: !0 }),
        b = f => () => document.querySelector(f).click(),
        c = f => `#fnrDialogParent .gtc-rep-modal-dialog .modal-dialog-buttons button[name=${f}]`,
        d = { imgSel: (f => () => {
                const g = a('mousedown'),
                    h = a('mouseup'),
                    i = document.querySelector(f);
                i.dispatchEvent(g), i.dispatchEvent(h) })('img.jfk-button-img.gtc-img-rep'), applyToAll: b(c('repDialogReplaceAll')), exit: b(c('repDialogExit')) };
    d.imgSel(), d.applyToAll(), d.exit() })();

这是回答我的问题并点击 3 次的小书签。这个答案给了我提示

于 2016-12-29T22:13:46.063 回答