senritsu
9/15/2016 - 6:35 AM

Tampermonkey userscript to watch for Keyfalls in the invisible sun Kickstarter campaign

Tampermonkey userscript to watch for Keyfalls in the invisible sun Kickstarter campaign

// ==UserScript==
// @name         Invisible sun keyfall watcher
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  watches for keyfalls
// @author       senritsu
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser-polyfill.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js
// @match        https://www.kickstarter.com/projects/montecookgames/invisible-sun*
// ==/UserScript==

/* jshint ignore:start */
var inline_src = (<><![CDATA[
/* jshint ignore:end */
/* jshint esnext: true */
/* jshint asi: true */

const reloadDelay = 30

function setupWatcher() {
    const css = document.createElement('link')
    css.rel = 'stylesheet'
    css.href = 'https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css'
    document.head.appendChild(css)
    
    const pledge = document.querySelector('li.pledge-selectable-sidebar[data-reward-id="5326811"]')
    
    if(pledge.classList.contains('pledge--available')) {
        const notification = new Notification('Keys available!')
    }

    NProgress.configure({ trickle: false, minimum: 0.01 })
    NProgress.start()
    
    setInterval(() => {
        NProgress.inc(1 / reloadDelay)
    }, 1000)

    setTimeout(() => location.reload(), reloadDelay * 1000)
}
    
if(Notification.permission != 'granted') {
    Notification.requestPermission()
    .then((permission) => {
        if(permission == 'granted') {
            setupWatcher()
        }
    })
} else {
    setupWatcher()
}
    


/* jshint ignore:start */
]]></>).toString();
var c = babel.transform(inline_src);
eval(c.code);
/* jshint ignore:end */