Bunpro: Helpful Events

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

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/370623/1192045/Bunpro%3A%20Helpful%20Events.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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)