// ==UserScript== // @name Mastodon Auto-Redirect To Home Instance // @namespace Violentmonkey Scripts // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @run-at document-start // @noframes // @license MIT // @version 3.14 // @author CoopCoding // @description 16/08/2024, 9:48:10 am // @match *://grapheneos.social/* // @match *://mastodon.matrix.org/* // @match *://chaosfem.tw/* // @match *://mastodon.neilzone.co.uk/* // @match *://mastodon.archive.org/* // @match *://alpaca.gold/* // @match *://follow.coryd.dev/* // @match *://mamot.fr/* // @match *://soc.kvet.ch/* // @match *://toot.community/* // @match *://mastodon.top/* // @match *://toot.whatever.cz/* // @match *://martianbase.net/* // @match *://mastodon.macstories.net/* // @match *://rustedneuron.com/* // @match *://botsin.space/* // @match *://notacult.social/* // @match *://fedi.computernewb.com/* // @match *://social.vmbrasseur.com/* // @match *://posts.rat.pictures/* // @match *://nondeterministic.computer/* // @match *://breakpoint.cafe/* // @match *://social.tchncs.de/* // @match *://corteximplant.com/* // @match *://mastodon.oysta.au/* // @match *://social.data.coop/* // @match *://vt.social/* // @match *://mastodon.gamedev.place/* // @match *://mastodon.sdf.org/* // @match *://merveilles.town/* // @match *://tauri.earth/* // @match *://front-end.social/* // @match *://allthingstech.social/* // @match *://x0r.be/* // @match *://anticapitalist.party/* // @match *://apobangpo.space/* // @match *://appdot.net/* // @match *://archaeo.social/* // @match *://artsculture.media/* // @match *://astrodon.social/* // @match *://attractive.space/* // @match *://bark.lgbt/* // @match *://beach.city/* // @match *://beige.party/* // @match *://berserker.town/* // @match *://bikesare.cool/* // @match *://birds.town/* // @match *://bitbang.social/* // @match *://blacktwitter.io/* // @match *://blobfox.coffee/* // @match *://body.social/* // @match *://bookstodon.com/* // @match *://bookwor.ms/* // @match *://brands.town/* // @match *://catcatnya.com/* // @match *://chatsubo.bar/* // @match *://chitter.xyz/* // @match *://climatejustice.social/* // @match *://cloudisland.nz/* // @match *://convo.casa/* // @match *://cooler.mom/* // @match *://cosmos.social/* // @match *://cryptodon.lol/* // @match *://cuddly.space/* // @match *://cupoftea.social/* // @match *://cute.is/* // @match *://cutie.city/* // @match *://cyberplace.social/* // @match *://dads.cool/* // @match *://deadinsi.de/* // @match *://defcon.social/* // @match *://demoncore.info/* // @match *://dice.camp/* // @match *://digitalcourage.social/* // @match *://digitaldarkage.cc/* // @match *://disabled.social/* // @match *://discuss.systems/* // @match *://dolphin.town/* // @match *://drupal.community/* // @match *://earthstream.social/* // @match *://ecoevo.social/* // @match *://econtwitter.net/* // @match *://eightpoint.app/* // @match *://emacs.ch/* // @match *://equestria.social/* // @match *://fandom.ink/* // @match *://fediscience.org/* // @match *://federated.press/* // @match *://finsup.site/* // @match *://finsup.social/* // @match *://flipboard.social/* // @match *://flipping.rocks/* // @match *://mastodon.floe.earth/* // @match *://fluffy.family/* // @match *://fosstodon.org/* // @match *://freeradical.zone/* // @match *://friend.camp/* // @match *://functional.cafe/* // @match *://social.funnyna.me/* // @match *://fur.lgbt/* // @match *://g33ks.coffee/* // @match *://gamedev.lgbt/* // @match *://gamepad.club/* // @match *://geekdom.social/* // @match *://genealysis.social/* // @match *://ghost.cafe/* // @match *://girlcock.club/* // @match *://glaceon.social/* // @match *://glammr.us/* // @match *://goblin.camp/* // @match *://hachyderm.io/* // @match *://hackers.town/* // @match *://handmade.social/* // @match *://harrystyl.es/* // @match *://hci.social/* // @match *://hcommons.social/* // @match *://hellyeah.social/* // @match *://hispagatos.space/* // @match *://history.lol/* // @match *://historians.social/* // @match *://ibite.lol/* // @match *://icosahedron.website/* // @match *://idlethumbs.social/* // @match *://im-in.space/* // @match *://inaccessible.ac/* // @match *://indieauthors.social/* // @match *://indieweb.social/* // @match *://infosec.exchange/* // @match *://interfaith.masto.host/* // @match *://ioc.exchange/* // @match *://ischool.social/* // @match *://jorts.horse/* // @match *://journa.host/* // @match *://k8s.social/* // @match *://kind.social/* // @match *://kinky.business/* // @match *://kitch.win/* // @match *://kitty.town/* // @match *://kosmos.social/* // @match *://kpop.social/* // @match *://laserdisc.party/* // @match *://layer8.space/* // @match *://legal.social/* // @match *://lesbianschool.com/* // @match *://liker.social/* // @match *://linernotes.club/* // @match *://livester.net/* // @match *://lgbt.io/* // @match *://lgbtqplus.social/* // @match *://lonely.town/* // @match *://lor.sh/* // @match *://magnificentbeardsfan.club/* // @match *://mapstodon.space/* // @match *://mas.to/* // @match *://masto.ai/* // @match *://masto.social/* // @match *://mastodon.art/* // @match *://mastodon.beer/* // @match *://mastodon.bot/* // @match *://mastodon.cloud/* // @match *://mastodon.design/* // @match *://mastodon.education/* // @match *://mastodon.energy/* // @match *://mastodon.green/* // @match *://mastodon.online/* // @match *://mastodon.radio/* // @match *://mastodon.sandwich.net/* // @match *://mastodon.world/* // @match *://mastodonbooks.net/* // @match *://mastodong.lol/* // @match *://mathtod.online/* // @match *://mathstodon.xyz/* // @match *://me.dm/* // @match *://med-mastodon.com/* // @match *://mefi.social/* // @match *://meow.social/* // @match *://mellified.men/* // @match *://metalhead.club/* // @match *://mograph.social/* // @match *://monocles.social/* // @match *://moth.social/* // @match *://mountains.social/* // @match *://mozilla.social/* // @match *://mstdn.business/* // @match *://mstdn.games/* // @match *://mstdn.io/* // @match *://mstdn.plus/* // @match *://mstdn.science/* // @match *://mstdn.social/* // @match *://musicworld.social/* // @match *://nerdculture.de/* // @match *://neurodifferent.me/* // @match *://neuromatch.social/* // @match *://newsie.social/* // @match *://noc.social/* // @match *://nullthe.net/* // @match *://occult.camp/* // @match *://octodon.social/* // @match *://ohai.social/* // @match *://oldbytes.space/* // @match *://oval.cc/* // @match *://parasocial.network/* // @match *://parody.town/* // @match *://peoplemaking.games/* // @match *://photog.social/* // @match *://phpc.social/* // @match *://plush.city/* // @match *://pool.social/* // @match *://social.privacytools.io/* // @match *://publicsquare.global/* // @match *://qaf.men/* // @match *://queer.cool/* // @match *://queer.garden/* // @match *://queer.party/* // @match *://rage.love/* // @match *://raggedfeathers.com/* // @match *://rail.chat/* // @match *://raphus.social/* // @match *://raru.re/* // @match *://ravenation.club/* // @match *://retro.pizza/* // @match *://retro.social/* // @match *://retrochat.online/* // @match *://retro-gaiden.com/* // @match *://ridetrans.it/* // @match *://romancelandia.club/* // @match *://ruby.social/* // @match *://ruhr.social/* // @match *://saturation.social/* // @match *://savageworlds.social/* // @match *://scholar.social/* // @match *://scicomm.xyz/* // @match *://sciencemastodon.com/* // @match *://sciences.social/* // @match *://seeds.social/* // @match *://seo.chat/* // @match *://seocommunity.social/* // @match *://shakedown.social/* // @match *://sinblr.com/* // @match *://skastodon.com/* // @match *://smores.town/* // @match *://snowmans.land/* // @match *://social.bbc/* // @match *://social.coop/* // @match *://social.lol/* // @match *://socialturtle.eu/* // @match *://solarsystem.social/* // @match *://sonomu.club/* // @match *://spacelase.rs/* // @match *://spacey.space/* // @match *://spore.social/* // @match *://stoat.zone/* // @match *://strangeobject.space/* // @match *://stranger.social/* // @match *://sunbeam.city/* // @match *://sunny.garden/* // @match *://switter.at/* // @match *://tabletop.social/* // @match *://tech.lgbt/* // @match *://techhub.social/* // @match *://tenforward.social/* // @match *://telescope.garden/* // @match *://theres.life/* // @match *://thicc.horse/* // @match *://toad.social/* // @match *://toki.social/* // @match *://toot.bike/* // @match *://toot.blue/* // @match *://toot.cafe/* // @match *://toot.io/* // @match *://tooot.im/* // @match *://toque.town/* // @match *://towns.gay/* // @match *://transforthe.win/* // @match *://transportation.social/* // @match *://trivia.town/* // @match *://tsukihi.me/* // @match *://tweesecake.social/* // @match *://twit.social/* // @match *://types.pl/* // @match *://urbanists.social/* // @match *://unbound.social/* // @match *://union.place/* // @match *://universeodon.com/* // @match *://uwu.town/* // @match *://veganism.social/* // @match *://vis.social/* // @match *://vivaldi.net/* // @match *://social.vivaldi.net/* // @match *://vmst.io/* // @match *://w3c.social/* // @match *://wandering.shop/* // @match *://wehavecookies.social/* // @match *://weirder.earth/* // @match *://weirdo.network/* // @match *://weremember.social/* // @match *://wetdry.world/* // @match *://wobbl.xyz/* // @match *://writing.exchange/* // @match *://xoxo.zone/* // @match *://yesterweb.org/* // @match *://social.yesterweb.org/* // @match *://zeal.center/* // @match *://zeroes.ca/* // @match *://zirk.us/* // @match *://aus.social/* // @match *://mastodon.au/* // @match *://social.chinwag.org/* // @match *://theblower.au/* // @match *://tyrol.social/* // @match *://mastodon.com.br/* // @match *://masto.donte.com.br/* // @match *://mstdn.ca/* // @match *://mastodonapp.ca/* // @match *://thecanadian.social/* // @match *://oceanplayground.social/* // @match *://ottawa.place/* // @match *://mastodont.cat/* // @match *://chilemasto.casa/* // @match *://mastodon.cl/* // @match *://bgme.me/* // @match *://mastodon.shenenfa.cn/* // @match *://mastodon.cr/* // @match *://expressional.social/* // @match *://norrebro.space/* // @match *://est.social/* // @match *://masr.social/* // @match *://mastodontti.fi/* // @match *://mstdn.fr/* // @match *://piaille.fr/* // @match *://gayfr.social/* // @match *://toulouse.social/* // @match *://cultur.social/* // @match *://kanoa.de/* // @match *://muenchen.social/* // @match *://oberpfalz.social/* // @match *://toot.koeln/* // @match *://social.saarland/* // @match *://dresden.network/* // @match *://machteburch.social/* // @match *://bonn.social/* // @match *://darmstadt.social/* // @match *://norden.social/* // @match *://wue.social/* // @match *://augsburg.social/* // @match *://brandenburg.social/* // @match *://nrw.social/* // @match *://osna.social/* // @match *://social.cologne/* // @match *://mastodon.hongkongers.net/* // @match *://mastodon.ie/* // @match *://mastodon.uno/* // @match *://pan.rent/* // @match *://mstdn.jp/* // @match *://mastodos.com/* // @match *://mastodon.tokyo/* // @match *://matitodon.com/* // @match *://mastodon.mg/* // @match *://mstdn.mx/* // @match *://mastodon.nl/* // @match *://mastonederland.nl/* // @match *://toot.re/* // @match *://nederland.online/* // @match *://mastodon.frl/* // @match *://tukkers.online/* // @match *://nwb.social/* // @match *://hsnl.social/* // @match *://social.edu.nl/* // @match *://social.overheid.nl/* // @match *://mastodon.nz/* // @match *://mastodon.nzoss.nz/* // @match *://snabelen.no/* // @match *://fribygda.no/* // @match *://oslo.town/* // @match *://mastodon.babb.no/* // @match *://tutoteket.no/* // @match *://mikrobloggen.no/* // @match *://kjas.no/* // @match *://samenet.social/* // @match *://paktodon.asia/* // @match *://pol.social/* // @match *://101010.pl/* // @match *://masto.pt/* // @match *://mastodon.ml/* // @match *://mastodon.scot/* // @match *://glasgow.social/* // @match *://toot.si/* // @match *://fediverse.co.za/* // @match *://jmm.kr/* // @match *://twingyeo.kr/* // @match *://mstdn.es/* // @match *://tkz.one/* // @match *://mastodon.se/* // @match *://mastodon.nu/* // @match *://fikaverse.club/* // @match *://vattenkylaren.se/* // @match *://swiss.social/* // @match *://mastodon.com.tr/* // @match *://soc.ua-fediland.de/* // @match *://mastodon.vn.ua/* // @match *://social.kyiv.dcomm.net.ua/* // @match *://mastodon.me.uk/* // @match *://mastodon.org.uk/* // @match *://mastodonapp.uk/* // @match *://mcr.wtf/* // @match *://blop.social/* // @match *://triangletoot.party/* // @match *://sfba.social/* // @match *://social.seattle.wa.us/* // @match *://theatl.social/* // @match *://crabland.social/* // @match *://okla.social/* // @match *://nycity.social/* // @match *://masto.nyc/* // @match *://dmv.community/* // @match *://az.social/* // @match *://cityofchicago.live/* // @match *://nutmeg.social/* // @match *://better.boston/* // @match *://toot.boston/* // @match *://bostonmusic.online/* // @match *://hoosier.social/* // @match *://kcmo.social/* // @match *://nashtodon.com/* // @match *://denvr.social/* // @match *://mastodon.uy/* // @match *://mastodon.social/* // @match *://toot.wales/* // @match *://fediverse.party/* // @match *://lugnasad.eu/* // @match *://oulipo.social/* // @match *://tusk.schoollibraries.net/* // @match *://mastodon.oeru.org/* // @match *://oeru.org/* // @match *://akademienl.social/* // @match *://sotl.social/* // @match *://koreadon.com/* // @match *://feedbeat.me/* // @match *://piano.masto.host/* // @match *://metalverse.social/* // @match *://drumstodon.net/* // @match *://musician.social/* // @match *://rollenspiel.social/* // @match *://radiosocial.de/* // @match *://hamradio.tel/* // @match *://pl.nudie.social/* // @match *://prf.me/* // @match *://makerspace.social/* // @match *://3dp.chat/* // @match *://gametoots.de/* // @match *://mastodon.triggerphra.se/* // @match *://podvibes.co/* // @match *://aircrew.rocks/* // @match *://bahn.social/* // @match *://toot.pizza/* // @match *://vkl.world/* // @match *://mastodon.fedi.bzh/* // @match *://fairy.id/* // @match *://gomastodon.cz/* // @match *://e.fo/* // @match *://mastodo.fi/* // @match *://librosphere.fr/* // @match *://electricrequiem.com/* // @match *://xn--lofll-1sat.is/* // @match *://best-friends.chat/* // @match *://occitania.social/* // @match *://wspanialy.eu/* // @match *://mk.phreedom.club/* // @match *://mastodon.sk/* // @match *://mastodon.in.th/* // @match *://jam.xwx.moe/* // @match *://fedi.garden/* // @match *://neovibe.app/* // @match *://qdon.space/* // @match *://bne.social/* // @match *://krems.social/* // @match *://fedi.at/* // @match *://sbg-social.at/* // @match *://aut.social/* // @match *://wokka.be/* // @match *://mastodon-belgium.be/* // @match *://witter.cz/* // @match *://mastodon.bayern/* // @match *://ruhrpott.social/* // @match *://fulda.social/* // @match *://berlin.social/* // @match *://fem.social/* // @match *://friendica.a-zwenkau.de/* // @match *://harz.social/* // @match *://rheinneckar.social/* // @match *://moessingen.social/* // @match *://cas.social/* // @match *://im.allmendenetz.de/* // @match *://toot.berlin/* // @match *://kowelenz.social/* // @match *://foxyhole.io/* // @match *://mastodon.holeyfox.co/* // @match *://malaga.social/* // @match *://mastodon.free-solutions.org/* // @match *://mastodon.tn/* // @match *://lviv.social/* // @match *://bath.social/* // @match *://socialclub.nyc/* // @match *://social.tulsa.ok.us/* // @match *://gardenstate.social/* // @match *://techlover.eu/* // @match *://devschile.social/* // @match *://gnulinux.social/* // @match *://technodon.org/* // @match *://toot.works/* // @match *://dotnet.social/* // @match *://jvm.social/* // @match *://greenhill.zone/* // @match *://toot.cat/* // @match *://sauropods.win/* // @match *://fedisabled.social/* // @match *://medibubble.org/* // @match *://bungle.online/* // @match *://mastodol.jp/* // @match *://elizur.me/* // @match *://babka.social/* // @match *://1689.social/* // @match *://elonsucks.org/* // @match *://venera.social/* // @match *://misskey.de/* // @match *://social.sp-codes.de/* // @match *://masto.bike/* // @match *://blueplanet.social/* // @match *://en.osm.town/* // @match *://swiss-chaos.social/* // @match *://mastodon.mit.edu/* // @match *://mastodon.librelabucm.org/* // @match *://mastodon.acc.sunet.se/* // @match *://social.sunet.se/* // @match *://social.mpdl.mpg.de/* // @match *://wisskomm.social/* // @match *://social.up.edu.ph/* // @match *://4bear.com/* // @match *://indiepocalypse.social/* // @match *://is.nota.live/* // @match *://lgbtqia.space/* // @match *://meemu.org/* // @match *://pipou.academy/* // @match *://poweredbygay.social/* // @match *://connectop.us/* // @match *://blackqueer.life/* // @match *://wavebird.party/* // @match *://furry.engineer/* // @match *://pawb.fun/* // @match *://pounced-on.me/* // @match *://pony.social/* // @match *://derg.social/* // @match *://krefeld.life/* // @match *://mastodon.opencloud.lu/* // @match *://iztasocial.site/* // @match *://openbiblio.social/* // @match *://ausglam.space/* // @match *://floss.social/* // @match *://linuxrocks.online/* // @match *://digipres.club/* // @match *://colorid.es/* // @match *://tooting.ch/* // @match *://libretooth.gr/* // @match *://mastodon.cc/* // @match *://feuerwehr.social/* // @match *://mastodon.gougere.fr/* // @match *://stereodon.social/* // @match *://solarpunk.moe/* // @match *://leftist.network/* // @match *://pcgamer.social/* // @match *://poliverso.org/* // @match *://cmdr.social/* // @match *://recht.social/* // @match *://medic.cafe/* // @match *://graz.social/* // @match *://brettspiel.space/* // @match *://podcasts.social/* // @match *://beo.social/* // @match *://greennuclear.online/* // @match *://indiehackers.social/* // @match *://musicians.today/* // @match *://kalmar.social/* // @match *://blasmusik.social/* // @match *://social.bau-ha.us/* // @match *://poliversity.it/* // @match *://onlycosplays.social/* // @match *://mastodon.eus/* // @match *://xarxa.cloud/* // @match *://frankfurt.social/* // @match *://nahe.social/* // @match *://veterinary.education/* // @match *://bardown.space/* // @match *://dz.social/* // @match *://astronomy.city/* // @match *://mastodon.africa/* // @match *://ribeiro.social/* // @downloadURL none // ==/UserScript== // List of instances taken from: https://coxy.co/mastodon/ and https://fediverse.party/en/portal/servers/ let mastodonHomeInstanceHost = GM_getValue("mastodonHomeInstanceHost") function promptForMastodonInstance(){ let promptVal = prompt("Enter your home mastodon instance url you want to auto-redirect to.") try{ if(!promptVal.startsWith("https://") && !promptVal.startsWith("http://")){ promptVal = "https://" + promptVal.trim() } let u = new URL(promptVal.trim()) GM_setValue("mastodonHomeInstanceHost", u.host) }catch(err){ alert("Not a valid url.") } } if(!mastodonHomeInstanceHost || !URL.canParse(`http://${mastodonHomeInstanceHost}`)) { promptForMastodonInstance() } else { if(window.location.host !== mastodonHomeInstanceHost){ var url = new URL(window.location.href) var host = url.host var pathName = url.pathname url.host = mastodonHomeInstanceHost var urlPaths = pathName.split("/") var isProfileOrPostPage = urlPaths[1].startsWith("@") if(isProfileOrPostPage){ var isPostUrl = urlPaths[2] && urlPaths[2].length > 0 && Number.isInteger(parseInt(urlPaths[2])) var secondForwardSlashIndex = pathName.indexOf("/", 1) if(isPostUrl){ // url.pathname = pathName.slice(0, secondForwardSlashIndex) + "@" + host + pathName.slice(secondForwardSlashIndex) // Need to use this cause the post id is sometimes different when viewed on a different instance. ¯\_(ツ)_/¯ url.href = `https://${mastodonHomeInstanceHost}/authorize_interaction?uri=${encodeURIComponent(window.location.href)}` } else { url.pathname = urlPaths[1] + "@" + host } // console.log(url.href) window.location.href = url.href } } } GM_registerMenuCommand('Change Your Mastodon Home Instance', promptForMastodonInstance)