Sort by first message button

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

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

});