Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bulletinmybeard/10170f0a6134043bbc4e2fedc7d62802 to your computer and use it in GitHub Desktop.
Save bulletinmybeard/10170f0a6134043bbc4e2fedc7d62802 to your computer and use it in GitHub Desktop.
Chill Institute - Update Button Auto Clicker (Browser Userscript)
// ==UserScript==
// @name         Chill Institute - Update Button Auto Clicker
// @namespace    https://rschu.me/
// @homepage     https://rschu.me/
// @version      1.0.0
// @encoding     utf-8
// @description  Chill Institute - Update Button Auto Clicker
// @author       Robin Schulz
// @match        *://chill.institute/*
// @compatible   chrome
// @compatible   firefox
// @compatible   opera
// @compatible   safari
// @connect      chill.institute
// @run-at       document-end
// ==/UserScript==

const observeElement = (selector, queryType = 'qs', callback) => {
    return new MutationObserver((mutationsList, observer) => {
        for (const mutation of mutationsList) {
            if (mutation.type === 'childList') {
                let element
                if (queryType === 'qsa') {
                    element = document.querySelectorAll(selector)
                    if (element.length) {
                        callback(element)
                    }
                } else {
                    element = document.querySelector(selector)
                    if (element) {
                        callback(element)
                    }
                }
            }
        }
    }).observe(document.body, {
        childList: true,
        subtree: true,
    })
}

(async () => {
    let resultElementFound = false
    const observer = observeElement('div[data-title]', 'qs', (element) => {
        const text = element.innerText
        if (!resultElementFound && (typeof text === 'string' && text.trim().toLowerCase().indexOf('found') > -1)) {
            resultElementFound = true
            const buttons = [...document.querySelectorAll('[data-button]')]
            const updateButton = buttons.find(button => button.textContent.trim().toLowerCase() === 'update')
            if (updateButton) {
                setTimeout(() => {
                    updateButton.click()
                    resultElementFound = false
                }, 350)
            }
        }
    })
})().catch(err => {
    console.error(err)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment