您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Press Shift+Space to play sentence audio (plus adds number keys support for more word bank exercises)
当前为
- // ==UserScript==
- // @name Duolingo keyboard shortcuts
- // @description Press Shift+Space to play sentence audio (plus adds number keys support for more word bank exercises)
- // @version 1.1.4
- // @match https://www.duolingo.com/*
- // @grant none
- // @author szupie szupie@gmail.com
- // @namespace szupie
- // @license Unlicense
- // ==/UserScript==
- (function () {
- 'use strict';
- const speakerButtonSelector = 'button._1KXUd, button._3nOBS, label.sgs9X button, [data-test="speaker-button"]';
- function handleKeyboard(e) {
- if (e.shiftKey === true && e.key === ' ') {
- const speakButton = document.querySelector(speakerButtonSelector);
- if (speakButton) {
- speakButton.click();
- e.preventDefault();
- }
- }
- // use number keys for sentence completion with word bank
- if (e.key >= "1" && e.key <= "9") {
- if (document.querySelector('[data-test="word-bank"]')) {
- const wordBankButtonSelector = `:nth-child(${e.key}) > [data-test="challenge-tap-token"]`;
- const wordBankButton = document.querySelector(`[data-test="word-bank"] ${wordBankButtonSelector}:not([aria-disabled])`);
- if (wordBankButton) {
- wordBankButton.click();
- } else {
- // remove word from sentence
- const disabledClass = '_2Hlc9';
- document.querySelectorAll(`._1gad7 :not(.${disabledClass})${wordBankButtonSelector}`).forEach(node => node.click());
- }
- }
- }
- }
- document.addEventListener('keypress', handleKeyboard, false);
- document.addEventListener('keyup', handleKeyboard, false);
- })();