Two Tampermonkey userscripts that make npm package browsing default to npmx.dev, while still allowing you to intentionally open the original npm package page from npmx.
Redirects npm package URLs to the same path on npmx.dev.
Runs on:
https://www.npmjs.com/package/*https://npmjs.com/package/*https://www.npmjs.org/package/*https://npmjs.org/package/*
Behavior:
- Runs at
document-start. - Redirects npm package pages to
https://npmx.dev. - Redirects when
activeTabis absent or set toreadme. - Preserves pathname, query string, and hash when redirecting.
- Skips redirecting when
activeTabis present and set to anything other thanreadme. - Skips redirecting when the npm page was opened from
npmx.dev.
Example:
https://www.npmjs.com/package/typescript?activeTab=readme
becomes:
https://npmx.dev/package/typescript?activeTab=readme
Allows npm links clicked from npmx.dev to send a referrer, so npmjs-to-npmx.js can detect that the visit came from npmx and avoid redirecting back.
Runs on:
https://npmx.dev/*
Behavior:
- Finds links to npm package pages.
- Removes only
noreferrerfrom matching links'relattribute. - Leaves
noopenerand any otherrelvalues intact. - Rechecks links when the page changes and immediately before pointer or keyboard activation.
This is needed because npm links on npmx.dev may use rel="noopener noreferrer". The noreferrer value prevents document.referrer from being set on npm, which would make the redirect script unable to know that the visit came from npmx.
Install both .js files as separate Tampermonkey scripts:
npmjs-to-npmx.jsnpmx-preserve-npm-referrer.js
The skip behavior depends on the browser sending a referrer from npmx.dev to npm. Removing noreferrer from the link is usually enough, but a site-wide Referrer-Policy: no-referrer from npmx.dev would still prevent this from working.
Thanks a lot for the script, it works well 🎉
Would you mind editing the file name to end with
.user.jsso that the web extension "catches" the raw file as an user script? Thanks!