A Tampermonkey userscript that adds "View Source" links to documentation sites with GitHub edit links.
- Automatically adds a "View Source" link next to "Edit this page" links on supported documentation sites
- Works with multiple documentation platforms through a configurable system
- Handles dynamically loaded content using a mutation observer
- Prevents duplicate links from being added
- Easy to extend for additional documentation sites
- Cloudflare Documentation (
developers.cloudflare.com
) - Python Packaging Documentation (
packaging.python.org
) - Python UV tool Documentation (
https://docs.astral.sh/uv/
) - Python PEP Documentation (
https://peps.python.org/
)
The script looks for GitHub edit links on documentation pages and creates a corresponding "View Source" link that points to the raw source file in the GitHub repository. This allows you to view the original markup file (Markdown, reStructuredText, etc.) that was used to generate the documentation page.
- Install the Tampermonkey browser extension
- Click on the Tampermonkey icon and select "Create a new script..."
- Copy and paste the entire script into the editor
- Save the script (Ctrl+S or File > Save)
To add support for a new documentation site, add a new configuration object to the siteConfigs
array with the following properties:
{
name: 'Site Name', // Name of the documentation site
selector: 'CSS selector for edit link', // CSS selector to find the GitHub edit link
container: 'CSS selector for container', // CSS selector for where to add the View Source link
replacements: [ // URL transformation rules
{
from: /pattern-to-replace/, // Regular expression to match in the edit URL
to: 'replacement-pattern' // String to replace it with
}
],
debug: '[SITE CODE]' // Debug prefix for console messages
}
{
name: 'Site Name', // Name of the documentation site
type: 'custom-pattern', // Type of configuration
container: 'selector1, selector2', // CSS selectors for where to add the View Source link
urlPattern: {
pageUrlRegex: /https:\/\/example\.com\/docs\/(.+)/, // Regex to extract documentation path
repoUrl: 'https://github.com/org/repo/raw/refs/heads/main/docs/$1.md', // URL pattern using captured group
transformations: [ // Optional transformations to apply to the path
{ from: /\/index$/, to: '' } // Example: remove /index from paths
]
},
debug: '[SITE CODE]' // Debug prefix for console messages
}
## Contributing
Feel free to add support for additional documentation sites by forking this repository and submitting a pull request with your changes.
## License
This script is provided under the MIT License.