2019-07-06 05:15:35 +02:00
// ==UserScript==
// @name NPR text only
// @description Redirects to the privacy respecting, text-only version of articles on npr.org and limits the text-width to 80 characters.
// @description:de Leitet auf die datenschutzfreundliche, nur-text version von artikeln auf npr.org weiter und beschränkt die text-breite auf 80 zeichen.
2020-06-14 18:32:09 +02:00
// @version 2020.06.14.1
2019-07-06 05:15:35 +02:00
// @author tastytea
2020-06-14 18:32:09 +02:00
// @copyright 2019-2020, tastytea (https://tastytea.de/)
2019-07-06 05:15:35 +02:00
// @license GPL-3.0-only
// @namespace tastytea.de
// @homepageURL https://schlomp.space/tastytea/userscripts
// @supportURL https://schlomp.space/tastytea/userscripts/issues
// @downloadURL https://schlomp.space/tastytea/userscripts/raw/branch/main/news/npr_text_only.user.js
// @grant GM_addStyle
// @match https://*.npr.org/*
// @run-at document-start
// @inject-into content
// ==/UserScript==
function main ( )
{
if ( window . location . href . startsWith ( "https://text.npr.org" ) )
{
add _css ( ) ;
}
else
{
redirect ( ) ;
}
}
function redirect ( )
{
2020-06-14 18:32:09 +02:00
const re _date = new RegExp ( '/[0-9]{4}/[0-9]{2}/[0-9]{2}/([0-9]+)/' ) ;
const re _transcript = new RegExp ( '/transcripts/([0-9]+)$' ) ;
let result = re _date . exec ( window . location . href ) ;
if ( result === null )
{
result = re _transcript . exec ( window . location . href ) ;
}
2019-07-06 05:15:35 +02:00
if ( result !== null && result . length > 1 )
{
window . location . assign ( "https://text.npr.org/s.php?sId=" + result [ 1 ] ) ;
}
else
{
2019-07-06 05:32:02 +02:00
console . warn ( "Could not find sId." ) ;
2019-07-06 05:15:35 +02:00
}
}
function add _css ( )
{
GM _addStyle ( "p { max-width: 80ch; }" ) ; // jshint ignore:line
}
main ( ) ;