Last active
October 15, 2018 00:21
-
-
Save saschanaz/acbd53772d017bb25bde0586f50d90bd to your computer and use it in GitHub Desktop.
twitter-force-pwa
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 Force Twitter PWA | |
// @namespace https://saschanaz.github.io/ | |
// @version 0.4.1 | |
// @description PWA is the future | |
// @author Kagami Sascha Rosylight | |
// @match https://twitter.com/* | |
// @grant none | |
// @run-at document-start | |
// ==/UserScript== | |
(() => { | |
'use strict'; | |
if (window !== window.top) { | |
// no-op within iframe | |
return; | |
} | |
const url = new URL(location.href); | |
const match = url.pathname.match(/^\/(\w+)/); | |
const firstPath = match && match[1]; | |
if (!firstPath && url.searchParams.get("status")) { | |
return; | |
} | |
if (url.hash.startsWith("#!/")) { | |
url.hostname = "mobile.twitter.com"; | |
url.pathname = url.hash.slice(2); | |
url.hash = ""; | |
location.href = url; | |
return; | |
} | |
if (url.pathname.startsWith("/i/topics/tweet/")) { | |
url.hostname = "mobile.twitter.com"; | |
location.href = url; | |
} | |
if ( | |
!["i", "intent", "oauth", "account", "share", "home"].includes(firstPath) && | |
!url.searchParams.has("force") | |
) { | |
url.hostname = "mobile.twitter.com"; | |
location.href = url; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment