Feed Finder

Detect the feed of the current website to facilitate subscription of RSS content.

Author
Gholts
Daily installs
1
Total installs
3
Ratings
0 0 0
Version
13.0
Created
2025-10-08
Updated
2025-10-08
Size
18.4 KB
License
AGPL-3.0
Applies to
All sites

Summary

Feed Finder is a Violentmonkey user script designed to automatically detect and display RSS, Atom, or JSON feeds on the current webpage. It operates by employing a multi-phase discovery process that includes site-specific rules, DOM scanning, and network probing. Found feeds are presented in a convenient, non-intrusive floating widget that displays a count of available feeds and expands to show a clickable list of their titles and URLs. The script is optimized for modern web browsing, with support for Single Page Applications (SPAs) and efficient, debounced execution to minimize performance impact.

Key Features

  • Multi-Faceted Discovery Mechanism: The script uses a prioritized, three-phase approach to maximize the chances of finding a feed.

    1. Site-Specific Rules: It first checks for hard-coded rules for specific domains (e.g., github.com, medium.com). These rules provide high-accuracy feed links based on the URL structure, such as links to commits or releases on a GitHub repository.
    2. DOM Scanning: If no site-specific rule applies, the script scans the page's HTML for <link> and <a> elements that commonly point to feeds. It identifies them based on type attributes (e.g., application/rss+xml), rel="alternate", and href attributes containing keywords like rss, feed, or file extensions like .xml.
    3. Network Probing: As a final step, it constructs and probes common feed paths (e.g., /feed, /rss.xml) relative to the website's domain and current path. It uses efficient HEAD requests to check the Content-Type header of the response, confirming if the URL points to a valid feed without downloading the entire file.
  • Dynamic and Unobtrusive UI:

    • Floating Widget: A small, circular widget is placed at the bottom-right corner of the page.
    • Feed Counter: When collapsed, the widget displays the number of feeds discovered.
    • Expandable List: Clicking the widget expands it into a panel that lists all found feeds with clickable titles and their full URLs.
  • Single Page Application (SPA) Support: The script actively monitors URL changes that occur without a full page reload, which is common in modern web applications. By patching history.pushState and history.replaceState and listening for navigation events (popstate, hashchange), it automatically re-runs the discovery process on in-page navigation.

  • Efficient and Optimized:

    • Debouncing: Discovery actions and URL change checks are debounced to prevent excessive execution during rapid navigation or DOM changes.
    • Asynchronous Operations: All network requests and the main discovery process are asynchronous, ensuring the user interface remains responsive.
    • Lightweight Probing: Network probes use HEAD requests instead of GET, saving bandwidth and improving speed.
  • Custom Styling: The script injects its own CSS for the widget and dynamically fetches and embeds the "Monaspace Neon" font for a consistent and polished appearance, carefully handling relative font paths to comply with Content Security Policies (CSP).

Architecture and Key Functions

The script is encapsulated within a single Immediately Invoked Function Expression (IIFE) to avoid polluting the global namespace. Its structure is logical and modular.

  • siteSpecificRules (Object): A configuration map where keys are hostnames and values are functions. Each function takes the current URL object as an argument and returns a Map of high-quality, known feed URLs for that site. This is the first and most precise discovery method.

  • discoverFeeds(initialDocument, url) (async Function): This is the core orchestration function. It executes the three discovery phases in sequence:

    1. Applies site-specific rules. If a rule matches and finds feeds, it may return early.
    2. Calls the internal findFeedsInNode function to scan the DOM.
    3. Initiates network probes using gmFetch. It aggregates results from all phases into a single list, ensuring no duplicates.
  • gmFetch(url, options) (Function): A Promise-based wrapper for the Greasemonkey API function GM_xmlhttpRequest. This is crucial for performing cross-origin network requests, which are necessary for network probing and fetching the external font stylesheet.

  • UI Management: A set of variables and functions is dedicated to creating, styling, and managing the UI widget.

    • injectCSS(): Injects the widget's styles into the document's head.
    • Element creation (widget, content, listEl): Builds the necessary DOM elements for the UI.
    • renderResults(): Populates the UI with the list of discovered feeds.
    • Event handlers (widget.addEventListener, handleClickOutside): Manage the widget's expand/collapse behavior.
  • SPA Navigation Handling:

    • patchHistoryMethod(): A helper function that wraps the native history.pushState and history.replaceState methods. When these methods are called by the website, the wrapper dispatches a custom event.
    • Event listeners for popstate, hashchange, pushstate, and replacestate trigger handleUrlChange, which resets the script's state and initiates a new discovery process.

Permissions

  • GM_xmlhttpRequest: This permission is required to perform cross-origin network requests. It is used for two purposes:
    1. The network probing phase, which sends HEAD requests to potential feed URLs.
    2. Fetching the external font stylesheet (Monaspace Neon) from a CDN.
  • @match *://*/*: The script is configured to run on all HTTP and HTTPS websites. This broad matching pattern is necessary for it to be a general-purpose feed finder, capable of discovering feeds on any site the user visits.