Skip to content

Instantly share code, notes, and snippets.

@cking
Created June 13, 2018 07:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cking/8555930a0c55fa831a3620bb8e2e7c91 to your computer and use it in GitHub Desktop.
Save cking/8555930a0c55fa831a3620bb8e2e7c91 to your computer and use it in GitHub Desktop.
Preview to full image rewrites
// ==UserScript==
// @name URL Rewrite
// @namespace Paars
// @match *://*/*
// @run-at document-start
// @grant none
// ==/UserScript==
const rewrites = [
{
name: "gfycat",
test: location => location.host === "thumbs.gfycat.com",
action: location => location.href = `https://giant.gfycat.com/${location.pathname.substr(1, location.pathname.indexOf("-") - 1)}.mp4`,
},
{
name: "tumblr",
test: location => location.host.match(/^\d+\.media\.tumblr\.com$/) && location.pathname.match(/_500\.(\w{3})$/),
action: location => location.href = location.href.replace(/_500\.(\w{3})$/, "_1280.$1")
}
]
for (let rewrite of rewrites) {
console.log("Checking rewrite for", rewrite.name)
if (rewrite.test(window.location)) {
console.log("succeeded!")
return rewrite.action(window.location)
} else {
console.log("failed...")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment