aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-08-21 02:11:00 +0200
committerTeddy Wing2018-08-21 02:11:00 +0200
commit36758fd1ff687ee062d0403930aad85c7477d9bf (patch)
treeefe1667af6ea49e54bd9bd726fabf6a65a2e8e63
parent7f44413d44d080ad3ad209759e80fdb0292d8d5d (diff)
downloadnpr-text-mode-redirect-36758fd1ff687ee062d0403930aad85c7477d9bf.tar.bz2
Handle cases where the article ID isn't in 6th position
In this example: https://www.npr.org/sections/thesalt/2018/08/20/636845604/beer-drinking-water-and-fish-tiny-plastic-is-everywhere the article ID isn't in the position we expect it to be, and we instead get `08` as the `article_id`. Instead of expecting the article ID to always be in the same spot, look for it in the second-from-last position.
-rw-r--r--npr-text-mode-redirect.user.js5
1 files changed, 4 insertions, 1 deletions
diff --git a/npr-text-mode-redirect.user.js b/npr-text-mode-redirect.user.js
index 0fd0d35..00cb646 100644
--- a/npr-text-mode-redirect.user.js
+++ b/npr-text-mode-redirect.user.js
@@ -29,6 +29,9 @@ var location = document.location;
// 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];
+var url_parts = redirect_url.split('/');
+
+// Second-to-last URL part is the article ID
+var article_id = url_parts[url_parts.length - 2];
location.assign('https://text.npr.org/s.php?sId=' + article_id);