Duolingo Blur

Blur the text unless shift is held

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         Duolingo Blur
// @description  Blur the text unless shift is held
// @namespace    http://tampermonkey.net/
// @version      1.0.4
// @author       You
// @match        https://www.duolingo.com/*
// @license      MIT
// ==/UserScript==

const duoBlurClass = 'duo-blur'

const startLessonButtons = [
    '_1rcV8 _1VYyp _1ursp _7jW2t PbV1v _2sYfM _19ped', // start lesson
    '_1rcV8 _1VYyp _1ursp _7jW2t _2CzYJ _2JGBA _1A_ri', // complete legendary
]

const skipDataTests = [
    'session-duo',
    'session-complete-slide',
    'daily-quest-progress-slide',
    'daily-quest-reward-slide',
]

const style = document.createElement('style');
style.textContent = `
    .duo-blur .XxgPa {
        filter: blur(6px);
    }
`;
document.head.appendChild(style);
document.body.classList.add(duoBlurClass)

let hideBlurOverride = false;
let disableBlur = false;

function setBlurEnabled(blurEnabled) {
    const enabled = blurEnabled && !disableBlur
    if (enabled && !document.body.classList.contains(duoBlurClass)) {
        document.body.classList.add(duoBlurClass);
    } else if (!enabled && document.body.classList.contains(duoBlurClass)) {
        document.body.classList.remove(duoBlurClass);
    }
}

function setShiftDown(shiftDown) {
    setBlurEnabled(!shiftDown);
    hideBlurOverride = shiftDown;
}

document.addEventListener('keydown', e => {
    if (e.key === 'Shift') {
        setShiftDown(true);
        hideBlurOverride = true;
    } else if (e.key === "F8" ) {
        disableBlur = !disableBlur
        setShiftDown(false);
    } else if (e.key === 'Enter') {
        if (location.href === 'https://www.duolingo.com/learn') {
            for (const btn of document.getElementsByClassName('_1gEmM _7jW2t _1333i _22TV_ _3Jm09')) {
                const sibling = btn.parentElement.querySelector('div._36bu_')
                if (sibling && sibling.textContent.trim() === 'START') {
                    btn.click()
                    break
                }
            }
        }

        for (const className of startLessonButtons) {
            document.getElementsByClassName(className)[0]?.click()
        }
    }
});
document.addEventListener('keyup', e => {
    if (e.key === 'Shift') {
        setShiftDown(false);
    }
});

function hasSpeakerButton() {
    return !!document.getElementsByClassName('_1OCYa').length
}

function shouldSkipScreen() {
    for (const dataTest of skipDataTests) {
        if (document.querySelector(`[data-test="${dataTest}"]`)) {
            return true
        }
    }

    return false
}

function clickNext() {
    document.querySelector('[data-test="player-next"]')?.click()
}

function onTimer() {
    if (!hideBlurOverride) {
        setBlurEnabled(hasSpeakerButton());
    }

    if (shouldSkipScreen()) {
        clickNext()
    }
}

document.addEventListener('visibilitychange', () => {
    if (document.hidden) setShiftDown(false);
});

window.addEventListener('blur', () => {
    setShiftDown(false);
});

setInterval(onTimer, 50)

window.addEventListener('keydown', e => {
    if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === 'r') {
        e.preventDefault();
        location.href = location.href;
    }
}, true); // useCapture = true