如何定期在桌面屏幕上闪烁消息(或弹出窗口)

How to flash messages (or pop-ups) on desktop screen at regular intervals

我正在尝试制作一个提醒我眨眼的应用程序,无论我打开了什么,它都会每 15 秒在屏幕中间显示一个闪烁的小动画(我有干眼症并且眨眼次数不够当我在电脑上时)。我的 phone 上已经安装了一个类似的应用程序,但找不到用于桌面的应用程序,所以我决定制作一个。我正在使用 Windows 10.

我试过使用 Electron,但到目前为止只能找到 api 来制作显示在右下角的常规 Windows 通知。

我已经下载了一个名为 EyeLeo 的应用程序,它的功能与我想要实现的功能类似,所以我知道这一定是可行的,尽管它每 5 分钟才闪烁一次消息(下图)

有人有什么想法吗?

编辑: 我不能使用警告框,因为它很大而且很碍事,而且据我所知不会自行消失就只是在屏幕上闪烁一个 html 元素(又名自定义警告)我'我不确定如何制作它,所以它会出现在我打开的任何内容上。例如,如果我打开浏览器并在后台运行应用程序,如何使元素显示在我的浏览器上 window?这就是难度

您可以为此设置一个异步间隔

// Define the notification function : 
function blink() {
  // Either add an html message in your page or just alert a message
  // alert("Blink");

  // Create a div for the blink-message (with absolute position at top)
  var alertBox = document.createElement('div');
  alertBox.innerText = "Reminder: Please Blink";
  alertBox.style.zIndex = "99999";
  alertBox.style.position = "fixed";
  alertBox.style.width = "100%";
  alertBox.style.top = "0px";
  //alertBox.style.left = "1%";
  alertBox.style.padding = "5px";
  alertBox.style.background = "#242424";
  alertBox.style.color = "white";
  alertBox.style.border = "1px solid white";
  alertBox.style.boxShadow = "5px 5px 5px 5px rgb(0,0,0,0.2)";
  
  // Append this div to the document body
  document.body.appendChild(alertBox);

  // Remove the notification msg after 2 sec
  setTimeout( function(){ document.body.removeChild(alertBox); }, 2000);
}
// Set an interval to alert every 10 seconds:
var blinkInterval = setInterval( blink, 10000);
// To unset the interval, use clearInterval : 
clearInterval(blinkInterval);

你可以使用带有超时和间隔的 Electronjs,就像这样

const { app, BrowserWindow } = require('electron')

app.whenReady().then(() => {
  const win = new BrowserWindow({
    width: 300,
    height: 220,
    frame: false,
    show: false
  })

  win.once('ready-to-show', () => {
    setInterval(() => win.show(), 15000) // 15s for show
  })

  win.on('show', () => {
    setTimeout(() => win.hide(), 3000) // 3s for hide
  })

  win.loadFile('index.html')
})