Skip to content

Instantly share code, notes, and snippets.

@kylefmohr
Last active April 16, 2025 21:53
Show Gist options
  • Save kylefmohr/2d99869fbbe92f8f957def33106dbfb9 to your computer and use it in GitHub Desktop.
Save kylefmohr/2d99869fbbe92f8f957def33106dbfb9 to your computer and use it in GitHub Desktop.
GreaseMonkey/TamperMonkey Userscript to bypass the NYTimes paywall (and others) by automatically redirecting to archive.is
// ==UserScript==
// @name NYTimes to Archive.is Redirector
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Automatically redirects nytimes.com pages (and others) to archive.is/newest/<original_url>
// @author Kyle
// @match *://*.nytimes.com/*
// @match *://*.rollingstone.com/*
// @match *://*.wsj.com/*
// @match *://*.theguardian.com/*
// @match *://*.bbc.com/*
// @match *://*.cnn.com/*
// @match *://*.washingtonpost.com/*
// @match *://*.theatlantic.com/*
// @match *://*.forbes.com/*
// @match *://*.bloomberg.com/*
// @match *://*.ft.com/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const currentFullUrl = window.location.href;
const urlObject = new URL(currentFullUrl);
// Reconstruct the URL using only the protocol, hostname, and pathname
// in order to remove query params that can cause archive.is to get confused
const baseUrl = urlObject.origin + urlObject.pathname;
// urlObject.origin includes protocol and hostname (e.g., "https://www.nytimes.com")
// urlObject.pathname includes the leading slash and the path (e.g., "/2025/04/16/opinion/...")
// so for example:
//`https://www.nytimes.com/2025/04/16/opinion/harvard-university-trump.html?smtyp=cur`
// will change to
//`https://www.nytimes.com/2025/04/16/opinion/harvard-university-trump.html`
// Construct the target archive.is URL using the cleaned URL
const targetUrl = 'https://archive.is/newest/' + baseUrl;
console.log(`Tampermonkey: Redirecting ${currentFullUrl} to ${targetUrl}`); // Optional logging
// Immediately load the archive.is link
window.location.replace(targetUrl);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment