Last active
April 17, 2021 18:43
-
-
Save jangxx/6b10183591fa26b7388a444ec7f19a23 to your computer and use it in GitHub Desktop.
A Userscript which disables the reader view on the Pocket website and opens links directly instead
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Pocket Open Links Directly | |
// @namespace http://jangxx.com/ | |
// @version 0.3.1 | |
// @description Disables the reader view on getpocket.com by redirecting to the target page directly | |
// @author jangxx | |
// @match *://getpocket.com/* | |
// @grant none | |
// @downloadURL https://gist.github.com/jangxx/6b10183591fa26b7388a444ec7f19a23/raw/pocket_open_links_directly.user.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let pushState = history.pushState; | |
history.pushState = function(...args) { | |
if (args[2].startsWith("/read/")) { | |
setTimeout(() => checkForLinks(true), 100); | |
} | |
pushState.apply(history, args); | |
} | |
function checkForLinks(pushed = false, retries = 30) { | |
if ((!window.location.href.includes("getpocket.com/read/") && !pushed) || retries == 0) { | |
return; | |
} | |
let link = document.getElementById("reader.external-link.view-original"); | |
if (link.href.startsWith("https://getpocket.com/redirect")) { | |
if (pushed) { | |
window.open(link.href); | |
window.history.back(); | |
} else { | |
window.location.href = link.href; | |
} | |
return; | |
} else { | |
window.location.href = link.href; | |
} | |
setTimeout(() => checkForLinks(pushed, retries - 1), 100); | |
} | |
setTimeout(checkForLinks, 100); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment