佛历-佛菩萨高僧纪念倒数日(每天显示3次)

只有4kb,打开任意网页右上角自动显示最近的佛菩萨高僧大德纪念日倒数日,每天显示3次,每次10秒。

  1. // ==UserScript==
  2. // @name 佛历-佛菩萨高僧纪念倒数日(每天显示3次)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2.1
  5. // @description 只有4kb,打开任意网页右上角自动显示最近的佛菩萨高僧大德纪念日倒数日,每天显示3次,每次10秒。
  6. // @author 极简实用
  7. // @match *://*/*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @license AGPL
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // 获取当前日期
  18. const today = new Date().toISOString().slice(0, 10); // YYYY-MM-DD 格式
  19.  
  20. // 获取已经查看的次数
  21. let viewCount = GM_getValue(today, 0);
  22.  
  23. // 设置每日限制(3次)
  24. const dailyLimit = 3;
  25.  
  26. // 如果已经达到限制,则不再显示弹出窗口
  27. if (viewCount >= dailyLimit) {
  28. console.log("今天已达到查看次数上限。");
  29. return;
  30. }
  31.  
  32. // 创建弹出窗口的HTML,并设置样式
  33. const popupWindow = document.createElement('div');
  34. popupWindow.style.position = 'fixed';
  35. popupWindow.style.top = '10px';
  36. popupWindow.style.right = '10px';
  37. popupWindow.style.width = '300px';
  38. popupWindow.style.height = '275px';
  39. popupWindow.style.background = 'white';
  40. popupWindow.style.border = '1px solid #ccc';
  41. popupWindow.style.boxShadow = '2px 2px 10px rgba(0,0,0,0.5)';
  42. popupWindow.style.zIndex = '9999';
  43. popupWindow.style.display = 'none';
  44. popupWindow.style.overflow = 'hidden';
  45. document.body.appendChild(popupWindow);
  46.  
  47. // 获取新浪网站内容
  48. GM_xmlhttpRequest({
  49. method: "GET",
  50. url: "http://fo.sina.com.cn/",
  51. onload: function(response) {
  52. if (response.status === 200) {
  53. const parser = new DOMParser();
  54. const doc = parser.parseFromString(response.responseText, 'text/html');
  55.  
  56. // 查找第一个 class 为 "ft_item" 的 li 元素
  57. const item = doc.querySelector('li.ft_item'); // 只取第一个
  58.  
  59. let content = '';
  60.  
  61. // 检查是否找到了内容
  62. if (!item) {
  63. content = '没有找到对应的内容';
  64. } else {
  65. const image = item.querySelector('img') ? item.querySelector('img').src : ''; // 获取图片链接
  66.  
  67. // 移除类名为 "fth_left" 的 span 元素
  68. const spans = item.querySelectorAll('span.fth_left');
  69. spans.forEach(span => span.remove());
  70.  
  71. // 获取文本内容并去除多余空白
  72. const text = item.textContent.trim();
  73.  
  74. // 构建显示内容
  75. content += '<div style="text-align:center; font-size:16px; font-family:\'微软雅黑\', sans-serif; margin-bottom: 10px;">';
  76. if (image) {
  77. content += `<img src="${image}" style="max-width:100%; height:auto;" alt="Image" />`; // 显示图片
  78. }
  79. content += `<div>${text}</div>`; // 添加文本
  80. content += '</div>';
  81. }
  82.  
  83. // 将内容插入到弹出窗口中
  84. popupWindow.innerHTML = content;
  85. popupWindow.style.display = 'block'; // 显示弹出窗口
  86.  
  87. // 增加查看次数
  88. viewCount++;
  89. GM_setValue(today, viewCount); // 保存当前查看次数
  90.  
  91. // 设置10秒后自动关闭弹出窗口
  92. setTimeout(function() {
  93. popupWindow.style.display = 'none'; // 隐藏弹出窗口
  94. }, 10000); // 10000毫秒 = 10秒
  95. } else {
  96. console.error("无法加载新浪网站内容,状态码:" + response.status);
  97. popupWindow.innerHTML = '加载内容失败,状态码:' + response.status;
  98. popupWindow.style.display = 'block';
  99. }
  100. },
  101. onerror: function() {
  102. console.error("请求出错");
  103. popupWindow.innerHTML = '请求出错,请稍后重试';
  104. popupWindow.style.display = 'block';
  105. }
  106. });
  107.  
  108. // 关闭弹出窗口(点击关闭)
  109. popupWindow.addEventListener('click', function() {
  110. this.style.display = 'none';
  111. });
  112. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址