Sort by first message button

Adds a "Sort by first message" button to the button group at the top of subforum pages

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Sort by first message button
// @namespace    incelerated
// @version      0.2
// @description  Adds a "Sort by first message" button to the button group at the top of subforum pages
// @author       incelerated
// @match        https://incels.is/forums/*
// @grant        none
// ==/UserScript==

$("document").ready(function(){

    var url = window.location.href;
	var forumName = url.split("/")[4];
	var buttonHTML = "";

    //if it's already sorted by first message make the button sort by last message
    if(url.indexOf("order=post_date&direction=desc") != -1){
        buttonHTML = `
			<a href="/forums/` + forumName + `/" class="button--link button"><span class="button-text">
			Sort by last message
			</span></a>
		`;
    }
	else{
		buttonHTML = `
			<a href="/forums/` + forumName + `/?order=post_date&direction=desc" class="button--link button"><span class="button-text">
			Sort by first message
			</span></a>
		`;
	}

	var btn = $(buttonHTML);
	$(".p-body-pageContent .block-outer .buttonGroup").prepend(btn);

});