Last active
February 22, 2024 01:30
-
-
Save titangene/eb1b3cc44dcad4a9da82411b114fc941 to your computer and use it in GitHub Desktop.
redirect Facebook, YouTube, GitHub, Medium
This file contains hidden or 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
(() => { | |
const redirectMatchers = [ | |
{ | |
matcher: () => location.host.includes('slideshare.net'), | |
action: redirectSlideShare | |
}, | |
{ | |
matcher: () => location.host.includes('facebook'), | |
action: redirectFacebook | |
}, | |
{ | |
matcher: () => location.host.includes('youtube'), | |
action: redirectYouTube | |
}, | |
{ | |
matcher: () => location.host.includes('github'), | |
action: redirectGitHub | |
}, | |
{ | |
matcher: function isMediumLike() { | |
const selector = 'meta[property="og:site_name"][content="Medium"]'; | |
const metaElement = document.head.querySelector(selector); | |
return !!metaElement; | |
}, | |
action: redirectMedium | |
} | |
]; | |
for (const { matcher, action } of redirectMatchers) { | |
const isMatch = matcher(); | |
if (isMatch) { | |
action(); | |
break; | |
} | |
} | |
/* redirect Facebook mobile page <--> desktop page */ | |
function redirectFacebook() { | |
if (location.host === 'm.facebook.com') { | |
location.href = 'https://www.facebook.com' + location.pathname + location.search; | |
} else if (location.host === 'www.facebook.com') { | |
location.href = 'https://m.facebook.com' + location.pathname + location.search; | |
} | |
} | |
/* redirect YouTube Shorts --> normal vedio page */ | |
function redirectYouTube() { | |
const vedioId = location.pathname.split('/').at(-1); | |
location.href = `${location.origin}/watch?v=${vedioId}`; | |
} | |
/* redirect GitHub page <--> GitHub repo page */ | |
function redirectGitHub() { | |
if (location.hostname === 'github.com') { | |
const [_, username, repo] = location.pathname.split('/'); | |
if (location.pathname.split('/')[2] === `${username}.github.io`) { | |
location.href = `https://${username}.github.io/`; | |
} else { | |
location.href = `https://${username}.github.io/${repo}`; | |
} | |
} else if (location.hostname.includes('github.io')) { | |
const username = location.host.split('.')[0]; | |
const repo = location.pathname === '/' | |
? location.host | |
: location.pathname.split('/')[1]; | |
location.href = `https://github.com/${username}/${repo}`; | |
} | |
} | |
/* redirect Medium --> scribe.rip */ | |
function redirectMedium() { | |
location.href = 'https://freedium.cfd/' + location.href + location.pathname; | |
/* location.href = 'https://readmedium.com/zh' + location.pathname; */ | |
/* location.href = 'https://scribe.rip' + location.pathname; */ | |
} | |
function redirectSlideShare() { | |
location.href = 'https://sssslide.com/' + location.href; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment