Greasy Fork is available in English.
Automatically starts next lesson when Duolingo loads.
当前为
// ==UserScript==
// @name Duolingo - autoStart next Lesson
// @description Automatically starts next lesson when Duolingo loads.
// @version 1.2
// @namespace minirock
// @match https://www.duolingo.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// ==/UserScript==
var lURL0 = '';
var lURL1 = '';
function last_url() {
lURL0 = lURL1;
lURL1 = window.location.href;
}
function next_lesson_start() {
let lessons = document.querySelectorAll("div[class='QmbDT']");
if (lessons.length === 0) return;
for (let i = 0; i < lessons.length; ++i) {
var lesson = lessons[i].querySelector("div[data-test='level-crown']");
if (lesson === null) {
var last_finished = i;
break;
}
}
// go to next unfinished lesson
lessons[last_finished].querySelector("div[class='_2albn']").click();
var status = Array.prototype.filter.call(lessons[last_finished].querySelectorAll("div[class='_2yvEQ']"), function (element) {
return RegExp('^0% Complete').test(element.textContent);
});
// status > 0 == lesson : tips
if (status.length !== 0) {
console.log('TIPS');
lessons[last_finished].querySelectorAll("button")[1].click()
} else {
console.log('LESSON');
lessons[last_finished].querySelector("button[data-test='start-button']").click();
}
}
function next_lesson_start_from_tips() {
let tips = document.querySelector("div[class='_2LApJ']");
if (tips !== null) {
tips.querySelectorAll("button")[0].click();
}
}
$(document).ready(function () {
last_url();
next_lesson_start();
});
let keyEventListener = function (event) {
if (event.keyCode === 13) {
next_lesson_start_from_tips();
next_lesson_start();
}
}
document.addEventListener("keyup", keyEventListener);
// start automatically next after 2s
history.pushState = ( f => function pushState(){
var ret = f.apply(this, arguments);
window.dispatchEvent(new Event('pushstate'));
window.dispatchEvent(new Event('locationchange'));
last_url();
if (lURL0.indexOf('/practice') == -1) setTimeout(next_lesson_start, 2000);
else setTimeout(function () { window.location.href = '/practice'; }, 2000);
return ret;
})(history.pushState);
window.addEventListener('popstate',()=>{
window.dispatchEvent(new Event('locationchange'))
});