-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFediverse_Home.user.js
More file actions
55 lines (49 loc) · 1.54 KB
/
Copy pathFediverse_Home.user.js
File metadata and controls
55 lines (49 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// ==UserScript==
// @name Fediverse@Home
// @namespace https://github.com/noccu
// @match *://*/*
// @run-at document-start
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @version 1.1.0
// @author noccu
// @description Open Fediverse remote profiles on your local instance. Currently supports Misskey & Mastodon.
// ==/UserScript==
// const SUPPORTED_PLAFORMS = ["misskey_app", "mastodon"]
var HOME
function check() {
// Are we on a fedi instance? (Slightly less dumb ver.)
switch (true) {
case document.querySelector("meta[name^=app]")?.content == "Misskey":
case document.getElementById("mastodon") !== undefined:
break
default:
return
}
// We are
HOME = GM_getValue("fediHome")
if (HOME && HOME == location.origin) {
return
}
GM_registerMenuCommand("Set as home instance", setHome)
GM_registerMenuCommand("Open on home instance", takeHome)
}
function setHome() {
if (HOME) {
var newHome = confirm(`Replace ${HOME} as home instance?`)
}
if (!newHome) { return }
GM_setValue("fediHome", location.origin)
console.log(`Home instance set to: ${location.origin}`)
}
function takeHome() {
if (!location.pathname.startsWith("/@")) return
if (!HOME) {
alert("No home instance set.")
return
}
let user = location.pathname.substring(1)
window.location = `${HOME}/${user}@${location.host}`
}
window.addEventListener("DOMContentLoaded", check)