aboutsummaryrefslogtreecommitdiffhomepage
path: root/append.html
blob: 51c8e97590402cbcf06c91dc2772c6f9dc61d4c1 (plain) (blame)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<div class="buttons">
	<button title="toggle theme"><svg><use href="res/feather.svg#moon"/></svg></button>	
	<button title="remove distractions"><svg><use href="res/feather.svg#eye-off"/></svg></button>	
	<button title="share on twitter or mastodon"><svg><use href="res/feather.svg#share-2"/></svg></button>	
	<button title="open print dialog"><svg><use href="res/feather.svg#printer"/></svg></button>	
	<button title="go to index"><svg><use href="res/feather.svg#home"/></svg></button>	
</div>

<div id="share" class="popover">
    <div>
        <ul>
            <li><a href="https://twitter.com" id="twitter">Share on Twitter</a></li>
            <li><a href="https://joinmastodon.org" id="mastodon">Share on Mastodon</a></li>
        </ul>
    </div>
</div>

<script>
	// haha i love this
	// thanks, me too
	const toggleScheme = () => {
		for (const rule of document.styleSheets[1].rules) {
			if (!rule.media || !rule.media.mediaText.includes("prefers-color-scheme"))
				continue
			if (rule.media.mediaText.includes("dark")) {
				rule.media.deleteMedium("(prefers-color-scheme: dark)");
				rule.media.appendMedium("(prefers-color-scheme: light)");
			} else {
				rule.media.deleteMedium("(prefers-color-scheme: light)");
				rule.media.appendMedium("(prefers-color-scheme: dark)");
			}
		}
	}

	let text = "V2tWa1YwNUhVa1pSYmxKYVYwVnZlVmxXWXpGaFYwbDZVMjVXWVZkRmJERlhhMlJXVUZFOVBRPT0=";

	(() => {
        const sharePopover = document.querySelector(".popover#share");

		const funcs = [
			() => toggleScheme(),
			() => document.querySelectorAll("nav, .buttons").forEach(e => e.remove()),
            () => sharePopover.style.display = "block", 
			() => window.print(),
			() => window.location.href = "/",
		]

        sharePopover.addEventListener("click", e => {
            sharePopover.style.display = "none";
        });

		document.querySelector("#twitter").href = `https://twitter.com/intent/tweet?text=${document.title}%0A${window.location.href}`;
        document.querySelector("#mastodon").onclick = e => {
            window.location.href = `https://${prompt("Enter your mastodon instance:", "mastodon.social")}/share?text=${document.title}%0A${window.location.href}`;
            e.preventDefault();
        }

		const buttons = document.querySelectorAll(".buttons button");
		for (let i = 0; i < buttons.length; i++)
			buttons[i].addEventListener("click", funcs[i]);

		setTimeout(() => {
			const links = document.querySelectorAll("a");
			for (let i = 0; i < links.length; i++) {
				if (links[i].getAttribute("href") == "mail") {
					for (let j = 0; j < 4; j++)
						text = atob(text);
					links[i].href = `mailto:${text}`;
				}
			}
		}, 1000);
	})();
</script>