this post was submitted on 26 Jun 2023
11 points (100.0% liked)

/kbin meta

4 readers
1 users here now

Magazine dedicated to discussions about the kbin itself. Provide feedback, ask questions, suggest improvements, and engage in conversations related to the platform organization, policies, features, and community dynamics. ---- * Roadmap 2023 * m/kbinDevlog * m/kbinDesign

founded 2 years ago
 

I know there have been a few of these posted recently, but I modified a few of the ones I found to add one additional feature: If the page you are on is already the remote version, but for the wrong local instance, to still update that to your preferred local instance.

Much easier to explain what I mean with examples so here's some:
https://lemmy.world/c/technology -> https://kbin.social/m/technology@lemmy.world
https://lemmy.world/c/asklemmy@lemmy.ml -> https://kbin.social/m/asklemmy@lemmy.ml

The first they all do, the second is the feature I added.

Here's the code, just manually create a bookmark and enter this as the URL, with whatever you want as the name. Then go to a page for a community you want to see in your local instance and click the bookmark, and it should take you to that local version of that page.

It's set up to take you to kbin.social versions of page, but you can change that by editing the home_instance_domain and the home_instance_char.

javascript:(function(){
var home_instance_domain = 'kbin.social';
var home_instance_char = '/m/';
var prefix = 'https://';

var url = new URL(document.URL);
var base_url = url.hostname;
var path_name = url.pathname;
path_name = path_name.replace(/\/\w\//, home_instance_char);
if (path_name.includes(home_instance_domain)) {
  path_name = path_name.replace(/@.+/, '');
  new_url = prefix + home_instance_domain + path_name;
} else if (path_name.includes('@')) {
  new_url = prefix + home_instance_domain + path_name;
} else {
  new_url = prefix + home_instance_domain + path_name + "@" + base_url;
}
console.log(new_url);
window.location.href=new_url;
})();

Edited to also handle being on the federated version of you home instance, like this:
https://lemmy.world/c/privacy@kbin.social -> https://kbin.social/m/privacy

you are viewing a single comment's thread
view the rest of the comments
[–] somethingcat@forum.fail 2 points 1 year ago

Firefox 114.0.1 Archlinux