本文介绍如何编写 tampermonkey 脚本,在页面中匹配特定 `
在自动化处理通知列表(如下载队列、任务提醒)时,为每项添加可视化的序号能显著提升人工操作效率——尤其当你需要按顺序逐个点击触发动作(例如下载导出文件)。虽然问题中提到了转向 Bookmarklet 方案,但 Tampermonkey 完全可胜任此任务,且更稳定、易维护、支持跨 iframe(需正确配置)。
以下是一个健壮、生产就绪的 Tampermonkey 脚本示例,它:

✅ 完整脚本如下(已适配你提供的 HTML 结构与类名):
// ==UserScript==
// @name Notification List Numbering
// @namespace https://github.com/yourname
// @version 1.2
// @description Add sequential numbers to each notification item (e.g., "1. Widget ready...")
// @author You
// @match *://warnerhotels.eu.qualtrics.com/*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function () {
'use strict';
// 等待目标列表加载(防动态渲染)
const waitForList = () => {
const ul = document.querySelector('ul[data-testid="notifications-list"]');
if (ul) {
annotateNotifications(ul);
} else {
setTimeout(waitForList, 300);
}
};
const annotateNotifications = (ul) => {
const items = ul.querySelectorAll('li[data-testid="notification-container"]');
items.forEach((li, index) => {
const num = index + 1;
// ✅ 方案一:在标题前插入序号(最直观、不影响原 aria-label)
const header = li.querySelector('h3.header-text--TaaKMDumePzcO7v');
if (header && !header.hasAttribute('data-numbered')) {
const originalText = header.textContent.trim();
header.textContent = `${num}. ${originalText}`;
header.setAttribute('data-numbered', 'true');
}
// ? 方案二(可选):增强 aria-label(取消注释启用)
/*
const notificationDiv = li.querySelector('[data-testid="notification"]');
if (notificationDiv && notificationDiv.hasAttribute('aria-label')) {
const label = notificationDiv.getAttribute('aria-label');
const enhancedLabel = label.replace(
/(.+?)\s*\(\d+\s*of\s*\d+\)/i,
`【${num}】$1`
);
notificationDiv.setAttribute('aria-label', enhancedLabel);
}
*/
});
console.log(`✅ Annotated ${items.length} notification items.`);
};
// 启动
waitForList();
})();? 关键说明与注意事项:
const iframe = document.querySelector('iframe[src*="notifications"]');
if (iframe?.contentDocument) {
const ul = iframe.contentDocument.querySelector('ul[data-testid="notifications-list"]');
// ...后续同理
}? 进阶提示:如需支持“点击序号快速跳转”或“键盘快捷键(如 Ctrl+1~9)触发对应项”,可在序号旁插入
该脚本轻量、无外部依赖、开箱即用,是处理通知类列表序号标注的专业级解决方案。