Chrome - Tampermonkey - Dailydictation script
// ==UserScript==
// @name Dailydictation Hotkeys
// @namespace http://tampermonkey.net/
// @version 2025-02-13
// @description This script allows users to use the key "\" to fill all the texts automatically
// @author You
// @match https://dailydictation.com/exercises/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=dailydictation.com
// @grant none
// ==/UserScript==
function playAudio() {
const audio = document.getElementsByTagName('audio')[0];
if (audio && audio.paused) {
audio.play();
}
else {
const playButton = document.getElementById("btn-play");
if (playButton && playButton.innerText.indexOf('Pause') < 0){
playButton.click();
}
}
}
(function() {
'use strict';
console.log("=========Tempermonkey script started!==========");
document.onkeypress = function (e) {
e = e || window.event;
if (e.key === '\\')
{
// enter the current sentence into the textarea and press Enter
if (window.appGlobals)
{
const index = document.getElementById("btn-arrow-left").nextSibling.innerText.split(' ')[0];
const sentence = appGlobals.challenges.find(x => x.position == index).content;
const textarea = document.getElementsByTagName('textarea')[0];
textarea.value = sentence;
playAudio();
setTimeout(() => {
//remove the redundant character '\' at the end
textarea.value = sentence;
//click "Check" button
const checkButton = document.getElementById("btn-check");
checkButton.click()
},100);
}
}
};
})();
No comments: