jkwon23 Saver

Ask jkwon23 to sleep when he is sitting up.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name           jkwon23 Saver
// @description    Ask jkwon23 to sleep when he is sitting up.
// @grant          GM_xmlhttpRequest
// @include        http://harddrop.com/file/shout/shout.php
// @version 0.0.1.20140809083510
// @namespace https://greasyfork.org/users/2233
// ==/UserScript==

var wnd = window
var doc = wnd.document
var loc = location
var href = loc.href

if(doc.getElementById('ShoutCloud-Container')==null) { throw 'exit' }

// enable the input box
addEventListener('load', function() {
    doc.getElementsByName('ShoutCloud-Msg')[0].disabled=false
    doc.getElementsByName('ShoutCloud-Msg')[0].value=''
}, false)

// don't clear unsent text when unfocuing the input box
doc.getElementsByName('ShoutCloud-Msg')[0].onblur = function() { return }

var is_late_night = function()
{
    try{
        var gm_xhr = GM_xmlhttpRequest({
            method: 'GET',
            url: 'http://www.timeanddate.com/worldclock/fullscreen.html?n=137',
            synchronous: true,
        })
        var res = gm_xhr.responseText
        var hh = /(.+):(.+):(.+)/.exec(/id=.?i_time.?>([^<]+)<\/div>/.exec(res)[1])[1] // get LA time
        if(/0[0-6]/.test(hh)) { return true }
        return false
    }
    catch(e) { return true }
}

var users = ['Aaron', 'jkwon23']
var len_users = users.length

var send_night_msg = function()
{
    try{
        var chats = doc.getElementsByClassName('shout-msg')
        var last_chat = chats[chats.length-1]
        for(var i=0; i<len_users; i++)
        {
            if(last_chat.children[0].id.indexOf(users[i])!=-1)
            {
                doc.getElementsByName('ShoutCloud-Msg')[0].value = users[i] + ', go to bed. (this msg is auto-sent by a userscript)'
                doc.getElementById('ShoutCloud-Shout').click()
            }
        }
    }catch(e) { alert(e) }
}

addEventListener('load', function() {
    var len = doc.getElementsByClassName('shout-msg').length
    addEventListener('DOMNodeInserted', function() {
    //addEventListener('DOMSubtreeModified', function() { // only for testing purposes. this will fire every time you press a key in the input box.
        var len2 = doc.getElementsByClassName('shout-msg').length
        if(len2 > len)
        {
            len = len2
            try{
                if(is_late_night())
                {
                    send_night_msg()
                }
            }catch(e) { alert(e) }
        }
    }, false)
}, false)