diff options
author | Teddy Wing | 2018-08-06 01:48:35 +0200 |
---|---|---|
committer | Teddy Wing | 2018-08-06 01:48:35 +0200 |
commit | a587ea1004b4fd57635c987fd4dafed4b178e5c0 (patch) | |
tree | ea20b9ae4b71352d96f7baca1c2469d52673dd9b /npr-text-mode-redirect.user.js | |
download | npr-text-mode-redirect-a587ea1004b4fd57635c987fd4dafed4b178e5c0.tar.bz2 |
User script to redirect to NPR's text version
Since the site doesn't provide a function to do this, make a mechanism
to do it automatically.
The text mode version is light and doesn't track visitors.
In order to redirect to the text version of the article, we pull out the
article's ID and use it in the text mode URL.
Thanks to these MDN docs explaining how to parse query string arguments:
- https://developer.mozilla.org/en-US/docs/Web/API/URL/searchParams#Example
- https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/get#Example
Diffstat (limited to 'npr-text-mode-redirect.user.js')
-rw-r--r-- | npr-text-mode-redirect.user.js | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/npr-text-mode-redirect.user.js b/npr-text-mode-redirect.user.js new file mode 100644 index 0000000..026f8c4 --- /dev/null +++ b/npr-text-mode-redirect.user.js @@ -0,0 +1,19 @@ +// ==UserScript== +// @name NPR Text Mode Redirect +// @description Redirect to the site's text mode +// @namespace com.teddywing +// @match https://choice.npr.org/* +// ==/UserScript== + + +var location = document.location; + +// Get the article ID from the URL. +// Example: +// https://choice.npr.org/index.html?origin=https://www.npr.org/2018/07/20/630792401/sleep-scientist-warns-against-walking-through-life-in-an-underslept-state +// The article ID is `630792401` +var params = new URLSearchParams(location.search.substring(1)); +var redirect_url = params.get('origin'); +var article_id = redirect_url.split('/')[6]; + +location.assign('https://text.npr.org/s.php?sId=' + article_id); |