From a587ea1004b4fd57635c987fd4dafed4b178e5c0 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Mon, 6 Aug 2018 01:48:35 +0200 Subject: 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 --- npr-text-mode-redirect.user.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 npr-text-mode-redirect.user.js 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); -- cgit v1.2.3