Sort by first message button

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

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);

});