上一主题 下一主题
ScriptCat,新一代的脚本管理器脚本站,与全世界分享你的用户脚本油猴脚本开发指南教程目录
返回列表 发新帖

关于GM_notification函数 延迟显示和集中弹出等问题

[复制链接]
  • TA的每日心情
    擦汗
    2024-1-28 11:21
  • 签到天数: 59 天

    [LV.5]常住居民I

    18

    主题

    101

    回帖

    120

    积分

    中级工程师

    积分
    120
    发表于 2023-4-26 16:11:12 | 显示全部楼层 | 阅读模式
    悬赏20油猫币未解决

    // ==UserScript==
    // @name 关于我们提醒通知
    // @namespace http://tampermonkey.net/
    // @version 0.1
    // @description try to take over the world!
    // @author You
    // @match https://www.baidu.com/
    // @icon https://www.google.com/s2/favicons?sz=64&domain=5054399.com
    // @grant GM_notification
    // @grant GM_setValue
    // @grant GM_getValue
    // ==/UserScript==

    function formatDate(offset, format) {
    const today = new Date();
    const relativeDate = new Date(today)
    relativeDate.setDate(today.getDate() + offset)

    const year = relativeDate.getFullYear();
    const month = String(relativeDate.getMonth() + 1).padStart(2, '0');
    const day = String(relativeDate.getDate()).padStart(2, '0');
    const hour = String(relativeDate.getHours()).padStart(2, '0');
    const minute = String(relativeDate.getMinutes()).padStart(2, '0');
    const second = String(relativeDate.getSeconds()).padStart(2, '0');

    // 根据传入的格式参数,返回不同格式的日期字符串
    switch (format) {
    case 'yyyy-MM-dd':
    return ${year}-${month}-${day};
    case 'yyyy-MM-dd HH:mm:ss':
    return ${year}-${month}-${day} ${hour}:${minute}:${second};
    case 'yyyy/MM/dd':
    return ${year}/${month}/${day};
    case 'yyyy/MM/dd HH:mm:ss':
    return ${year}/${month}/${day} ${hour}:${minute}:${second};
    default:
    return ${hour}:${minute}:${second};
    }
    }
    function H5提醒(文案){
    // 显示通知
    GM_notification({
    text: 文案 , // 提示信息内容
    title: '提示', // 提示信息标题
    timeout: 1000, // 提示信息显示时间(毫秒),默认为4000毫秒

    });
    console.log("结束"+formatDate(0))

    }
    async function 延迟执行(func,文案, 秒) {
    await new Promise((resolve) => setTimeout(resolve, 秒 * 1000));
    func(文案)
    console.log("提醒"+formatDate(0))
    }

    //=========================================================================================================

    if(document.location.href.includes('https://www.baidu.com/')){
    延迟执行(H5提醒,"超时", 0)

    }

    哥哥们,麻了,这个油猴的H5提醒函数,老是不准时,我用延时函数执行和用点击触发,都是要等好久的,要么就是集中一个时间段弹出来。各位哥哥帮忙看下

  • TA的每日心情
    慵懒
    10 小时前
  • 签到天数: 603 天

    [LV.9]以坛为家II

    30

    主题

    523

    回帖

    1379

    积分

    荣誉开发者

    积分
    1379

    荣誉开发者新人进步奖油中2周年生态建设者新人报道挑战者 lv2油中3周年喜迎中秋

    发表于 2023-4-26 17:39:59 | 显示全部楼层
    https://bbs.tampermonkey.net.cn/thread-4337-1-1.html
    可以参考一下这个脚本 里面都有注释
    回复

    使用道具 举报

    发表回复

    本版积分规则

    快速回复 返回顶部 返回列表