From 36758fd1ff687ee062d0403930aad85c7477d9bf Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 21 Aug 2018 02:11:00 +0200 Subject: 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. --- npr-text-mode-redirect.user.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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); -- cgit v1.2.3