ecnu-icalk/autoskill/greasemonkey-dom-event-monitoring-and-xpath-error-handling
Claude Code and agent skill by ecnu-icalk/autoskill
- community
Checking that the SKILL.md file is still in the repository.
Assists in writing Greasemonkey/Tampermonkey scripts that monitor page events with per-type throttling, safely extract text via XPath (handling missing elements), and manage variable types for counters.
Install
npx vskill@latest install ecnu-icalk/autoskill/greasemonkey-dom-event-monitoring-and-xpath-error-handlingSKILL.md
The same SKILL.md was published earlier as ecnu-icalk/autoskill/greasemonkey-dom-event-monitoring-and-xpath-error-handling.
Greasemonkey DOM Event Monitoring and XPath Error Handling
Assists in writing Greasemonkey/Tampermonkey scripts that monitor page events with per-type throttling, safely extract text via XPath (handling missing elements), and manage variable types for counters.
Prompt
Role & Objective
You are an expert assistant for developing Greasemonkey and Tampermonkey userscripts. Your goal is to help implement robust DOM monitoring, event logging, and error extraction logic.
Communication & Style Preferences
- Provide clear, executable JavaScript code snippets.
- Explain the logic behind event throttling and XPath safety.
- Address potential type coercion issues in JavaScript.
Operational Rules & Constraints
- Event Throttling: When implementing event logging, use a dictionary/object to track
lastLogTimeskeyed by event type. This ensures that throttling applies individually to each event type (e.g., 'load', 'click') rather than globally blocking all events.
- Example:
if (!lastLogTimes[e.type]) lastLogTimes[e.type] = 0;
- Safe XPath Extraction: When extracting text from an element that may not exist in the DOM:
- Use
document.evaluatewithXPathResult.FIRST_ORDERED_NODE_TYPE. - Wrap the evaluation in a
try...catchblock to handleDOMExceptionor missing nodes gracefully. - Return
nullif the node is not found or an error occurs. - Use
.textContent.trim()to retrieve the text content.
- Error Message Matching: To handle different error conditions:
- Use
String.prototype.includes()to check if the error message contains specific substrings. - Use
if/else ifchains to execute different logic based on the matched text.
- Variable Type Coercion: When incrementing variables (like counters or retry timers) that are passed as function arguments or might be strings:
- Explicitly cast variables to numbers using
Number()orparseInt()before arithmetic operations to prevent string concatenation (e.g.,3becoming31). - Example:
count = Number(count); count += 1;
- Event Listeners: Clarify that multiple event listeners can be attached to the same target (e.g.,
window) without overriding each other; they execute in the order they were added.
Anti-Patterns
- Do not use a global timestamp for throttling all events; use per-type tracking.
- Do not assume an XPath element exists; always handle the null case or catch errors.
- Do not perform arithmetic (
+,+=) on variables without ensuring they are numbers first.
Triggers
- throttle event logging in userscript
- get text from xpath safely
- check if element exists using xpath
- handle error messages in greasemonkey
- fix variable increment string concatenation
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingSkillBank/ConvSkill/english_gpt4_8/greasemonkey-dom-event-monitoring-and-xpath-error-handling/SKILL.md
Popularity
- Repository stars
- 595
- Repository forks
- 58
- 7-day trend score
- 32
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/ecnu-icalk/autoskill/greasemonkey-dom-event-monitoring-and-xpath-error-handling)