Duolingo Speedy Timed Practice

Duolingo - Speedier Timed Practice

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Duolingo Speedy Timed Practice
// @namespace    mog86uk-duo-speedy-timed-practice
// @version      1.0
// @description  Duolingo - Speedier Timed Practice
// @author       mog86uk (aka. testmoogle)
// @match        https://www.duolingo.com
// @match        https://www.duolingo.com/practice
// @match        https://www.duolingo.com/skill/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @grant        none
// @run-at       document-idle
// @noframes
// ==/UserScript==

(function() {
    'use strict';
    var $clonedResultBar;
    var speedyToggle = 0;
    var timerSpeedy;
    var timerCheckPageUrl;

    function addGlobalStyle(css) {
        var head, style;
        head = document.getElementsByTagName('head')[0];
        if (!head) { return; }
        style = document.createElement('style');
        style.type = 'text/css';
        style.innerHTML = css;
        head.appendChild(style);
    }

    jQuery.noConflict();
    jQuery(document).ready(function($) {

        addGlobalStyle('#duplicateResultBar div.PYCF5 * {color:#BBB!important;}');
        addGlobalStyle('#duplicateResultBar div._2KMvD._3nzjY {cursor:help;}');
        //addGlobalStyle('#duplicateResultBar {bottom:120px!important;height:120px!important;}');

        function Speedy() {
            if (!$('button._1pp2C._1MQOP._3qSMp._3cu46.T6NVk._27uC9').length) {
                if (!$('button[data-test="player-skip"]').length &&
                    $('button._3XJPq._1MQOP._3qSMp._3cu46._27uC9:enabled').length) {

                    if ($('#duplicateResultBar').length) {
                        $('#duplicateResultBar').remove();
                    }

                    $clonedResultBar =  $('div._1sntG').clone().prop('id', 'duplicateResultBar');
                    $('div._1sntG').after($clonedResultBar);
                    $('#duplicateResultBar button._3XJPq._1MQOP._3qSMp._3cu46._27uC9').remove();
                    $('#duplicateResultBar div._2KMvD._3nzjY')
                        .attr('title', 'Click to SKIP the current question')
                        .on('click', function(){$('button[data-test="player-skip"]').click();});

                    $('button._3XJPq._1MQOP._3qSMp._3cu46._27uC9').click();
                }
            }
            else {
                if (!$('button[data-test="secondary-button"]').length) {
                    if ($('#duplicateResultBar').length) {
                        $('#duplicateResultBar').remove();
                    }
                }
            }
        }

        function CheckPageUrl() {
            if (/^https:\/\/www\.duolingo\.com\/(practice|skill\/.+\/.+\/practice)/.test(window.location.href)) {
                if (speedyToggle === 0) {
                    window.clearInterval(timerSpeedy);
                    timerSpeedy = window.setInterval(Speedy, 50);
                    speedyToggle = 1;
                }
            }
            else {
                if (speedyToggle === 1) {
                    window.clearInterval(timerSpeedy);
                    speedyToggle = 0;
                }
            }
        }
        timerCheckPageUrl = window.setInterval(CheckPageUrl, 2000);
    });
})();