Focusmate button simulator - Gmail style

Focusmate pressing automation

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Focusmate button simulator - Gmail style
// @namespace    http://tampermonkey.net/
// @version      0.3.4
// @description  Focusmate pressing automation
// @author       Contact WeChat @H2018336
// @match        https://www.focusmate.com/dashboard
// @icon         https://www.google.com/s2/favicons?domain=focusmate.com
// @require      https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// ==/UserScript==

(function() {
    'use strict';
    function ck(v){
        $(v).length && $(v)[0].click();
    };
    $(document).ready(
        function(){
            let off = !1;
            document.onkeyup=function(e){
                if(e.keyCode==71){
                    // placeholder bit, for key-sequence activation.
                }else{
                    off = !1;
                }
            };
            document.onkeydown = function(e) {
                if(e.keyCode==71){ // g-key,as the trigger
                    off = !0;
                }else if(e.keyCode==13){// Enter key: (In "Book a session" box, hit Enter to confirm booking.)
                    $('[name="title"]').length && ck('app-spinner-button button[type="submit"]');
                }else if(e.keyCode==27){//ESC
                    ck('.ng-star-inserted fa-icon.std-modal-close')
                }else if(off){
                    console.log(e.keyCode)
                    switch(e.keyCode){
                        case 65 ://a - View all
                            ck('.upc-header a.upc-header-link');
                            break;
                        case 66 ://b - Book a session
                            ck("button.f-btn--primary");
                            setTimeout(function(){ $('input[name="title"]').attr('autocomplete','off')[0].focus()},300);
                            break;
                        case 67 ://c - Book/Create a session (same as gb)
                            ck("button.f-btn--primary");
                            setTimeout(function(){ $('input[name="title"]').attr('autocomplete','off')[0].focus()},300);
                            break;
                        case 84 ://t - Today (button)
                            ck('.fm-cal-toolbar a.today-btn')
                            break;
                        case 80 ://p - left-button
                            ck('.fm-cal-toolbar a.left')
                            break;
                        case 78 ://n - right-button
                            ck('.fm-cal-toolbar a.right')
                            break;
                        case 74 ://j - Join a session
                            ck('.upc-content-wrapper .fm-vid-btn-card')
                            break;
                        case 72 ://h
                            ck('a.fm-breadcrumb-item:contains(Calendar)')
                            break;
                        case 68 ://d - Delete a session: Cancel, and confirm very quickly
                            if($('button.cancel .cancel-yes .cancel-yes .ng-star-inserted').length){
                                ck('button.cancel .cancel-yes .cancel-yes .ng-star-inserted')
                            }else{
                                ck('.cancel')
                                setTimeout(function(){ck('.cancel-yes .cancel-yes .ng-star-inserted')},300);
                            }
                            break;
                        case 87 ://w - toggl Day/Week-view
                            ck('.fm-cal-toolbar a.day-week')
                            break;

                        case 73 ://i - Invite button
                            ck('.help-menu-btn-container a.fm-main-help-btn ')
                            break;
                        case 50 ://2 - Pick 25m
                            ck('.fm-cal-toolbar a.duration-left')
                            break;
                        case 53 ://5 - Pick 50m
                            ck('.fm-cal-toolbar a.duration-middle')
                            break;
                        case 55 ://7 - Pick 50m
                            ck('.fm-cal-toolbar a.duration-right')
                            break;

                    }
                }

            }
        }
    );
})();