Tower Rest(休息一下)

更优雅的使用Tower

目前為 2019-09-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Tower Rest(休息一下)
// @namespace    https://tower.im/
// @version      1.1
// @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();
})();