StrokesPlus.net教程及脚本持续更新

桌面显示倒计时

输入截止时间后,桌面显示倒计时,结束后发出嘀声

时间格式
年, 月, 日, 时, 分(可选), 秒(可选)
比如 ‘2022,3,8,12,30’ or ‘22,3,8,12,30’ or ‘22,3,8,12,30,30’

年-月-日-时-分(可选)-秒(可选)
比如 ‘2022-3-8-12-30’ or ‘22-3-8-12-30’ or ‘22-3-8-12-30-30’

回车,执行,ESC,退出

第一部分

添加到全局动作-启动/退出-启动(开启)

重要:如果已经添加过DisplayTextInfo计时器,直接复制添加if(sp.GetStoredBool("countDownTime")) {}之间的代码(即开始结束之间)

sp.CreateTimer("LangWatch", 
               250, 
               250, 
               `var info = new DisplayTextInfo();
              
               info.TitleFont = new Font('Segoe UI', 12, host.flags(FontStyle.Bold));
               info.MessageFont = new Font("Segoe UI Semibold", 12);
               info.BackColor = "15,179,98"; 
               info.ForeColor = "255,255,255";
               info.Duration = 1000;
               info.Opacity = 0.5;
               info.Location = "190,809"; 
               info.FadeSteps = 5;
               info.Padding = 10;
               info.Message = "";

               //开始
               if(sp.GetStoredBool("countDownTime")) {
                    var getStrTime = sp.GetStoredString('strTime');
                    //sp.ConsoleLog(getStrTime)
                    if(getStrTime.indexOf(',') > -1) {
                        var yearSet = ("20" + (getStrTime.split(',')[0])).slice(-4);
                        var monSet = ("0" + (parseInt(getStrTime.split(',')[1]) - 1)).slice(-2);
                        var daySet = ("0" + (getStrTime.split(',')[2])).slice(-2);
                        var hourSet = getStrTime.split(',')[3] != null ? ("0" + (getStrTime.split(',')[3])).slice(-2) : "00";
                        var minSet = getStrTime.split(',')[4] != null ? ("0" + (getStrTime.split(',')[4])).slice(-2) : "00";
                        var secSet = getStrTime.split(',')[5] != null ? ("0" + (getStrTime.split(',')[5])).slice(-2) : "00";
                    } else if(getStrTime.indexOf('-') > -1) {
                        var yearSet = ("20" + (getStrTime.split('-')[0])).slice(-4);
                        var monSet = ("0" + (parseInt(getStrTime.split('-')[1]) - 1)).slice(-2);
                        var daySet = ("0" + (getStrTime.split('-')[2])).slice(-2);
                        var hourSet = getStrTime.split('-')[3] != null ? ("0" + (getStrTime.split('-')[3])).slice(-2) : "00";
                        var minSet = getStrTime.split('-')[4] != null ? ("0" + (getStrTime.split('-')[4])).slice(-2) : "00";
                        var secSet = getStrTime.split('-')[5] != null ? ("0" + (getStrTime.split('-')[5])).slice(-2) : "00";
                    }
 
                    var newTime = new Date(parseInt(yearSet), parseInt(monSet), parseInt(daySet), parseInt(hourSet), parseInt(minSet), parseInt(secSet));

                    var diff = parseInt((newTime - Date.now()) / 1000);
                    var sec = parseInt(diff % 60);
                    var min = parseInt((diff / 60) % 60);
                    var hour = parseInt(diff / 3600);
                    var day = parseInt(diff / 3600 / 24);
                    var lastime = hour + "Hour" + min + "Min" + sec + "Sec";

                    if(hour == 0 && min == 0 && sec == 0) {
                        sp.StoreBool('countDownTime', false);
                        sp.DeleteStoredString('strTime');
                        System.Console.Beep(800, 1000);
                    }

                    if(info.Message.length > 0) {
                        info.Message += " - ";
                        info.BackColor = "255,105,180";//pink
                        info.Location = "90,809";
                    } else {
                        info.BackColor = "56,142,142";//green
                        info.Location = "225,809";
                    }
                    info.Message += lastime;  
                } 
                //结束

                try {

                } catch {}  


                if(info.Message.length > 0) { 
                    if(sp.GetStoredBool("LangShown")) {
                        sp.DisplayTextUpdate(info);
                    } else { 
                        sp.DisplayText(info);
                        sp.StoreBool("LangShown", true);
                    }
                } else {
                    sp.DisplayTextClose();
                    sp.StoreBool("LangShown", false);
                }
               `
);

第二部分

执行动作

if(!sp.GetStoredBool('countDownTime')) {
    var input = shouInput();
    //sp.ConsoleLog(input);
    if(input != '') {
        sp.StoreString('strTime', input);
        sp.StoreBool('countDownTime', true);
    }
} else {
    sp.StoreBool('countDownTime', false);
    sp.DeleteStoredString('strTime');
}


function shouInput() {
    var ht = sp.ForegroundWindow().Screen.Bounds.Height;
    var wd = sp.ForegroundWindow().Screen.Bounds.Width;

    var input = "";

    var Forms = forms.System.Windows.Forms;
    var form = new Forms.Form;

    form.StartPosition = Forms.FormStartPosition.Manual;
    form.FormBorderStyle = Forms.FormBorderStyle.FixedToolWindow;
    form.TopMost = true;
    form.ControlBox = false;
    form.ShowInTaskbar = false;
    form.Margin = new Forms.Padding(0);
    form.Padding = new Forms.Padding(1); 
    form.MinimumSize = new Size(100, 10);
    //form.Size = new Size(300, 26);
    form.Size = new Size(300, 34);
    //form.Location = currentMouseLocation;
    form.Location = new Point(wd/2 - 150, ht/2 - 60);
    form.AutoSize = true;
    form.GetType().GetProperty("DoubleBuffered",
            host.flags(clr.System.Reflection.BindingFlags.NonPublic,
            clr.System.Reflection.BindingFlags.Instance))
            .SetValue(form, true);
    form.BackColor = Color.WhiteSmoke;

    var textBox = new Forms.TextBox;
    textBox.Size = new Size(150, 20);
    textBox.Location = new Point(50, 5);
    //textBox.Font = new System.Drawing.Font("Microsoft YaHei", 8, FontStyle.Regular);
    textBox.Font = new System.Drawing.Font("Microsoft YaHei", 13, FontStyle.Regular);
    textBox.Text = "";
    textBox.Dock = System.Windows.Forms.DockStyle.Fill;
    form.Controls.Add(textBox);

    dragMoveBlind = ShowImageBindDragMove(form, form);
    dragMoveBlind = ShowImageBindDragMove(form, textBox);

    var form_shown = 
    form.Shown.connect(
    function (sender, args) {
        form.TopMost = true;
        form.Activate();
    });

    var textBox_KeyPress = 
    textBox.KeyPress.connect(
    function (sender, e) {
        // The keypressed method uses the KeyChar property to check 
        // whether the ENTER key is pressed. 
        // then, do action and close the Form
        if (e.KeyChar == 13)
        {
            input = textBox.Text;
            form.Close();
        // The keypressed method uses the KeyChar property to check 
        // whether the ESCAPE key is pressed. 
        // then close the Form
        } else if(e.KeyChar == 27) {
            form.Close();
        }
    });

    var textBox_KeyDown = 
    textBox.KeyDown.connect(
    function (sender, e) {
        // The keydown method uses the KeyChar property to check 
        // whether the Ctrl+SHIFT+J key is pressed. 
        // then, close the Form
        var hk = e.KeyCode
        if((e.Control) && (e.KeyCode==System.Windows.Forms.Keys.U) && (e.Shift)) {
            input = '';
            form.Close();
            
        }
    });

    // Enable to double click the mouse right button to 
    // drag the From
    var textBox_doubleClick = 
    textBox.DoubleClick.connect(
    function (sender, args) {
        dragMoveBlind = ShowImageBindDragMove(form, textBox);
    });

    var form_doubleClick = 
    form.DoubleClick.connect(
    function (sender, args) {
        dragMoveBlind = ShowImageBindDragMove(form, form);
    });

    Forms.Application.Run(form);

    var regmin = /^([1-9]\d{3}|2[0-9]),([1-9]|1[0-2]),([1-9]|[1-2][0-9]|3[0-1]),([0-9]|[1-2][0-3]),([0-9]|[0-5][0-9])$/;
    var reghour = /^([1-9]\d{3}|2[0-9]),([1-9]|1[0-2]),([1-9]|[1-2][0-9]|3[0-1]),([0-9]|[1-2][0-3])$/;
    var _regmin = /^([1-9]\d{3}|2[0-9])-([1-9]|1[0-2])-([1-9]|[1-2][0-9]|3[0-1])-([0-9]|[1-2][0-3])-([0-9]|[0-5][0-9])$/;
    var _reghour = /^([1-9]\d{3}|2[0-9])-([1-9]|1[0-2])-([1-9]|[1-2][0-9]|3[0-1])-([0-9]|[1-2][0-3])$/;
    if(input == '') {
        return input;
    } else {
        if(input.match(regmin) || input.match(reghour) ||input.match(_regmin) || input.match(_reghour)) {
            return input;
        } else {
            return shouInput();
        }
    }

    function ShowImageBindDragMove(form, item) {
        var Cursors = forms.System.Windows.Forms.Cursors;
        var ReleaseCapture = sp_config.GetType().Assembly.GetType("API").GetMethod("ReleaseCapture");

        var item_mouseMove = 
        item.MouseMove.connect(
        function (sender, e) {
            var hitResize = form.Height + form.Width - (e.X + e.Y) < 30;
            var cursor = hitResize ? Cursors.SizeNWSE : Cursors.IBeam;
            if (item.Cursor != cursor) item.Cursor = cursor;
            if (e.Button == MouseButtons.Left) {
                ReleaseCapture.Invoke(null, null);
                sp.WindowFromHandle(form.Handle).SendMessageObj(0x0112,
                    hitResize ? 0xF008 : 0xF012, 0);
            }
        });

        return [item_mouseMove];
    }
}