Greasy Fork

TAB shortcut-key play voice for Duolingo

TAB shortcut-key play voice for Duolingo (タブキーで発音を聞く)

目前为 2019-12-29 提交的版本。查看 最新版本

// ==UserScript==
// @name         TAB shortcut-key play voice for Duolingo
// @namespace    TAB shortcut-key play voice for Duolingo
// @version      0.4
// @description  TAB shortcut-key play voice for Duolingo (タブキーで発音を聞く)
// @author       meguru
// @match        https://www.duolingo.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function playSound(evt) {
        if (evt.keyCode === 9) {
            const ae = document.activeElement;
            const t3 = document.evaluate('//*[@id="root"]/div/div/div/div/div[2]/div/div/div/div/div/div[1]/div/div[1]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
            const t4 = document.evaluate('//*[@id="root"]/div/div/div/div/div[2]/div/div/div/div/div/div[1]/button', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
            if (t3.snapshotLength > 0) t3.snapshotItem(0).click();
            if (t4.snapshotLength > 0) t4.snapshotItem(0).click();
            evt.preventDefault();
        }
    }

    document.addEventListener("keydown", playSound, false);
})();