Bunpro: Helpful Events

A set of custom events which make it easier to detect changes on the page.

Questo script non dovrebbe essere installato direttamente. È una libreria per altri script da includere con la chiave // @require https://update.greasyfork.org/scripts/370623/1192045/Bunpro%3A%20Helpful%20Events.js

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Bunpro: Helpful Events
// @namespace    http://tampermonkey.net/
// @version      1.0.3
// @author       Kumirei
// @require      https://greasyfork.org/scripts/432418-wait-for-selector/code/Wait%20For%20Selector.js?version=990207
// @include      *bunpro.jp*
// @exclude      *community.bunpro.jp*
// ==/UserScript==

;(function (wfs) {
    // Add a custom event for when BP creates a new body
    var newBody = new Event('new-body')
    wfs.wait('body > header', function (e) {
        fireEvent(newBody)
    })

    // Add a custom event for when you get a new item in reviews
    var newReviewItem = new Event('new-review-item')
    wfs.wait('.level_lesson_info a', function (e) {
        fireEvent(newReviewItem)
    })

    // Add a custom event when you go to study or cram page
    var quizPage = new Event('quiz-page')
    wfs.wait('#show-grammar', function (e) {
        fireEvent(quizPage)
    })

    // Add a custom event when you go to study page
    var studyPage = new Event('study-page')
    wfs.wait('#study-page #show-grammar', function (e) {
        fireEvent(studyPage)
    })

    // Add a custom event when you go to cram page
    var cramPage = new Event('cram-page')
    wfs.wait('#cram-page #show-grammar', function (e) {
        fireEvent(cramPage)
    })

    // Fires the given event on the HTML element
    function fireEvent(event) {
        var retryInterval = setInterval(function () {
            if (document.readyState == 'complete') {
                $('HTML')[0].dispatchEvent(event)
                clearInterval(retryInterval)
            }
        }, 100)
    }
})(window.wfs)