オンライン欄増殖

try to take over the world!

As of 2020-05-18. See the latest version.

// ==UserScript==
// @name         オンライン欄増殖
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  try to take over the world!
// @author       You
// @match        *.x-feeder.info/*/
// @exclude      *.x-feeder.info/*/sp*
// @exclude      *.x-feeder.info/*/settings/**
// @require      https://greasyfork.org/scripts/396472-yaju1919/code/yaju1919.js?version=802405
// @require      https://greasyfork.org/scripts/388005-managed-extensions/code/Managed_Extensions.js?version=720959
// @grant        GM.setValue
// @grant        GM.getValue
// @grant        GM.xmlHttpRequest
// ==/UserScript==

(function() {
    'use strict';
    function setCookie(c_name,value,expiredays){
        // pathの指定
        var path = location.pathname;
        // pathをフォルダ毎に指定する場合のIE対策
        var paths = new Array();
        paths = path.split("/");
        if(paths[paths.length-1] != ""){
            paths[paths.length-1] = "";
            path = paths.join("/");
        }
        // 有効期限の日付
        var extime = new Date().getTime();
        var cltime = new Date(extime + (60*60*24*1000*expiredays));
        var exdate = cltime.toUTCString();
        // クッキーに保存する文字列を生成
        var s = "";
        s += c_name + "=" + value;// 値はエンコードしない
        s += "; path=" + path;
        if(expiredays){
            s += "; expires=" +exdate+"; ";
        }else{
            s += "; ";
        }
        // クッキーに保存
        document.cookie=s;
    }
    var h_input, input_bool, input_time, r2, input_now;
    win.Managed_Extensions["オンライン欄増殖"] = {
        config: ()=>{
            const h = $("<div>");
            h_input = $("<div>").appendTo(h);
            input_time = yaju1919.addInputNumber(h_input,{
                title: "リクエスト間隔[秒]",
                max: 10,
                min: 0,
                value: 0.3,
                save: "wait"
            });
            h.append("<br>");
            yaju1919.addInputText(h,{
                title: "名前",
                change: function(v){
                    if(v) setCookie("name", v);
                }
            });
            h.append("<br>");
            input_now = yaju1919.addInputText(h,{
                placeholder: "今なにしてる?",
                save: "now"
            });
            h.append("<br>");
            yaju1919.addInputBool(h,{
                title: "オンライン欄更新停止", // 自分が重くなるのを防ぐ
                change: function(v){
                    if(v) {
                        r2 = unsafeWindow.refreshOnlineUsersView;
                        unsafeWindow.refreshOnlineUsersView = () => {};
                    }
                    else {
                        if(r2){
                            unsafeWindow.refreshOnlineUsersView = r2;
                        }
                    }
                }
            });
            h.append("<br>");
            h.append("<br>");
            input_bool = yaju1919.addInputBool(h,{
                title: "run",
                change: function(v){
                    if(v) main();
                }
            });
            return h;
        },
    };
    const main = () => {
        setCookie("sid",'',0);
        GM.xmlHttpRequest({
            method: "GET",
            url: location.href,
            onload: r => {
                if(!input_bool()) return;
                var hds = r.responseHeaders;
                var m = hds.match(/sid/);
                if(!m) return console.error("sidが見つかりませんでした。"); // sidが無い
                var sid = hds.slice(m.index + 4).match(/[0-9a-zA-Z]+/)[0];
                setCookie("sid",sid,0);
                //--- syncMyStatus
                var statusData = unsafeWindow.getStatusData();
                $.post('/' + unsafeWindow.profileId + '/update_status.php', {
                    'is_mobile': statusData['isMobile'],
                    'status': statusData['status'],
                    'status_text': input_now(),
                    'now_broadcasting': statusData['nowBroadcasting']
                });
                //---
                setTimeout(main, input_time() * 1000);
            },
        });
    };
})();