Last active
May 11, 2024 16:15
-
-
Save yujinlin0224/e40b68374b7fc8e4549333a83b7cfbd1 to your computer and use it in GitHub Desktop.
Redirect mobile version of website to desktop version. Supports Facebook, Twitter, Wikipedia and more (in the future).
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 Redirect Mobile To Desktop | |
// @version 2.0 | |
// @namespace https://yurina.dev/ | |
// @downloadURL https://gist.github.com/yujinlin0224/e40b68374b7fc8e4549333a83b7cfbd1/raw/RedirectMobileToDesktop.user.js | |
// @updateURL https://gist.github.com/yujinlin0224/e40b68374b7fc8e4549333a83b7cfbd1/raw/RedirectMobileToDesktop.user.js | |
// @homepageURL https://github.com/yujinlin0224 | |
// @author yujinlin0224 | |
// @description Redirect mobile version of website to desktop version | |
// @match http*://m.facebook.com/* | |
// @match http*://mobile.twitter.com/* | |
// @match http*://*.m.wikipedia.org/* | |
// @match http*://m*.moegirl.org.cn/* | |
// @match http*://m.momoshop.com.tw/* | |
// ==/UserScript== | |
const websiteConverters = { | |
facebook(url) { | |
const source = /^m\.facebook\.com$/ | |
if (!source.test(url.host)) return null | |
const target = 'www.facebook.com' | |
url.host = url.host.replace(source, target) | |
return url.href | |
}, | |
twitter(url) { | |
const source = /^mobile\.(twitter|x)\.com$/ | |
if (!source.test(url.host)) return null | |
const target = 'twitter.com' | |
url.host = url.host.replace(source, target) | |
return url.href | |
}, | |
wikipedia(url) { | |
const source = /^([\w-]+).m.wikipedia.org$/ | |
if (!source.test(url.host)) return null | |
const target = '$1.wikipedia.org' | |
url.host = url.host.replace(source, target) | |
return url.href | |
}, | |
moegirlpedia(url) { | |
const source = /^m([\w-]+).moegirl.org.cn$/ | |
if (!source.test(url.host)) return null | |
const target = '$1.moegirl.org.cn' | |
url.host = url.host.replace(source, target) | |
return url.href | |
}, | |
momoshop(url) { | |
const source = /^m\.momoshop\.com\.tw$/ | |
if (!source.test(url.host)) return null | |
const target = 'www.momoshop.com.tw' | |
url.host = url.host.replace(source, target) | |
if (url.pathname === '/main.momo') { | |
url.pathname = '/main/Main.jsp' | |
} | |
if (url.pathname === '/search.momo') { | |
url.pathname = '/search/searchShop.jsp' | |
url.searchParams.set('keyword', url.searchParams.get('searchKeyword')) | |
url.searchParams.delete('searchKeyword') | |
url.searchParams.delete('couponSeq') | |
} | |
if (url.pathname === '/goods.momo') { | |
url.pathname = '/goods/GoodsDetail.jsp' | |
} | |
return url.href | |
}, | |
} | |
const url = new URL(location.href) | |
if (url.protocol !== 'https:') { | |
url.protocol = 'https:' | |
} | |
Object.entries(websiteConverters).forEach(([name, converter]) => { | |
const href = converter(url) | |
if (!href) return | |
console.log(`Redirecting ${name} mobile to desktop...`) | |
location.replace(href) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment