Tower Rest(休息一下)

更优雅的使用Tower

当前为 2019-09-25 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Tower Rest(休息一下)
// @namespace    https://tower.im/
// @version      1.0
// @description  更优雅的使用Tower
// @author       veking
// @match        https://tower.im/*
// @grant        none
// @require      https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// ==/UserScript==

(function() {
    var MyTower = {
        init: function() {
            this.rest();
        },
        rest: function() {
            var obj = this.getRestElement();
            var btn = $('.btn', obj);
            btn.unbind('click').click(function(){
                obj.fadeOut();
                $('.container, #link-to-help, .footer').animate({opacity: 0}, 500);
                MyTower.work();
            });
        },
        work: function() {
            var obj = this.getWorkElement();
            var btn = $('.btn', obj);
            console.log(btn.get(0))
            btn.unbind('click').click(function(){
                obj.fadeOut();
                $('.container, #link-to-help, .footer').animate({opacity: 1}, 500);
                MyTower.rest();
            });
        },
        changeBg: function() {
            //TODO
        },
        getRestElement: function() {
            var id = '__rest__';
            var obj = $('#'+id);
            if (!obj.length) {
                var html = '<div id="'+id+'" style="position:fixed;top:50%;right:0;width:45px;">';
                html += '<a class="btn" href="javascript:void(0);" style="background-color:#5cb85c;border-color:#3e8f3e;font-size:16px;">休息一下</a>';
                html += '</div>';
                $('.wrapper').append(html);
                obj = $('#'+id);
                obj.css('margin-top', '-'+obj.height() / 2+'px');
            } else {
                obj.fadeIn('slow');
            }
            return obj;
        },
        getWorkElement: function() {
            var id = '__work__';
            var obj = $('#'+id);
            if (!obj.length) {
                var html = '<div id="'+id+'" style="position:fixed;top:50%;right:0;width:45px;">';
                html += '<a class="btn" href="javascript:void(0);" style="background-color:#337ab7;border-color:#245580;font-size:16px;">继续工作</a>';
                html += '</div>';
                $('.wrapper').append(html);
                obj = $('#'+id);
                obj.css('margin-top', '-'+obj.height() / 2+'px');
            } else {
                obj.fadeIn('slow');
            }
            return obj;
        }
    };
    MyTower.init();
})();