Greasy Fork

Die WELT Online | Artikelkommentare Automatisch Einblenden

Alle Antworten zu Artikeln bei WELT.DE immer einblenden (Always automatically expand all WELT.DE article comments)

目前为 2018-11-25 提交的版本。查看 最新版本

// ==UserScript==
// @name            Die WELT Online | Artikelkommentare Automatisch Einblenden
// @namespace       de.sidneys.userscripts
// @homepage        https://gist.githubusercontent.com/sidneys/4392fdde27a0cf60cb12ada20c95fb81/raw/
// @version         1.5.0
// @description     Alle Antworten zu Artikeln bei WELT.DE immer einblenden (Always automatically expand all WELT.DE article comments)
// @author          sidneys
// @icon            https://www.welt.de/favicon.ico
// @include         https://www.welt.de/*article*
// @require         https://greasyfork.org/scripts/38888-greasemonkey-color-log/code/Greasemonkey%20%7C%20Color%20Log.js
// @grant           GM.addStyle
// @run-at          document-end
// ==/UserScript==

/**
 * ESLint configuration
 */
/* global DEBUG, waitForKeyElements */

/**
 * @default
 * @constant
 */
DEBUG = false

/**
 * Minimum Delay between Lookups
 * @default
 * @constant
 */
const minimumLookupIntervalDuration = 1000



/**
 * Inject Stylesheet
 */
let injectStylesheet = () => {
    console.debug('injectStylesheet')

    GM.addStyle(`
        /* .busy
           ========================================================================== */

        .busy,
        .busy *
        {
            cursor: wait !important;
        }
    `)
}

/**
 * Busy mode
 * @param {Boolean} isBusy - Yes/No
 */
let setBusy = (isBusy) => {
    console.debug('setBusy')

    if (isBusy) {
        document.querySelector('html').classList.add('busy')
    } else {
        document.querySelector('html').classList.remove('busy')
    }
}

/**a
 * Look for & click any "Antworten Einblenden" buttons
 */
let enableAutoLoadComments = () => {
    console.debug('enableAutoLoadComments')

    let requestId
    let initialTimestamp = new Date().getTime()

    let lookup = () => {
        const currentTimestamp = new Date().getTime()
        const currentInterval = currentTimestamp - initialTimestamp

        // Execute if interval long enough
        if (currentInterval >= minimumLookupIntervalDuration) {
            // Look for element
            let element = document.querySelector('div.c-content-container:nth-child(1) > div:nth-child(4) > div:nth-child(4) > div:nth-child(1) > div > div:nth-child(3) > div:nth-child(2) > a:nth-child(1)')

            if (!element) {
                // No more elements found
                console.debug('enableAutoLoadComments', 'no more elements found')
                setBusy(false)
            } else {
                // New element found
                console.debug('enableAutoLoadComments', 'new element found')
                setBusy(true)
                element.click()
            }

            // Update timestamp
            initialTimestamp = new Date().getTime()
        }

        // Rerun lookup
        requestId = window.requestAnimationFrame(lookup)
    }

    // Start lookup
    requestId = window.requestAnimationFrame(lookup)
}


/**
 * Init
 */
let init = () => {
    console.info('init')

    // Add Stylesheet
    injectStylesheet()

    // Enable Auto-Loading Comments
    enableAutoLoadComments()
}


/**
 * @listens window:Event#load
 */
window.addEventListener('load', () => {
    console.debug('window#load')

    init()
})