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

/kbin meta

110 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/[email protected]
https://lemmy.world/c/[email protected] -> https://kbin.social/m/[email protected]

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/[email protected] -> https://kbin.social/m/privacy

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 2 points 2 years ago (1 children)

Just out of curiosity, on what browser? I tested Firefox and Chrome and both worked.

[โ€“] [email protected] 2 points 2 years ago

Firefox 114.0.1 Archlinux