ricksouth / ntms.link

A basic URL shortener using Github Pages, a catch-all 404 page, plain JS and a JSON file.

Home Page:https://ntms.link/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

https://ntms.link/

A basic URL shortener.

It gets the URLS to shorten from a JSON file:
 https://github.com/ricksouth/ntms.link/blob/main/urls/shortened_urls.json

{
	"github" : "https://github.com/ricksouth",
	"curseforge" : "https://curseforge.com/members/serilum/projects",
	"modrinth" : "https://modrinth.com/user/serilum"
}

 
Which a basic JavaScript turns into a new URL: (via a catch-all 404 page)
 https://github.com/ricksouth/ntms.link/blob/main/assets/js/script.js

document.addEventListener('DOMContentLoaded', function() {
	var url = document.URL + "";
	url = url.replaceAll("?p=/", "");

	loadJSON('/urls/shortened_urls.json',
		function(data) {
			var from = url.split("link/")[1]

			if (from in data) {
				var to = data[from];

				window.location.replace(to);
				return;
			}

			window.location.replace("https://github.com/ricksouth/ntms.link");
		},
		function(xhr) { }
	);
}, false);

 
These URLS are now shortened via Github Pages:

Anything else will link back to this repository:

That's it! šŸ¤·

About

A basic URL shortener using Github Pages, a catch-all 404 page, plain JS and a JSON file.

https://ntms.link/

License:MIT License


Languages

Language:HTML 74.8%Language:JavaScript 25.2%