// ==UserScript==
// @name           DSOlastChange
// @namespace      DSOlastChange
// @description    Mit dem DSO-Client spielen
// @author         Roni - 31.01.2026
// @grant          none
// @version        2.5 (edited)
// @include        https://www.thesettlersonline.com.br/*
// @include        https://www.thesettlersonline.com/*
// @include        https://www.thesettlersonline.net/*
// @include        https://www.thesettlersonline.fr/*
// @include        https://www.thesettlersonline.cz/*
// @include        https://www.diesiedleronline.de/*
// @include        https://www.thesettlersonline.gr/*
// @include        https://www.thesettlersonline.it/*
// @include        https://www.juego-thesettlersonline.com/*
// @include        https://www.thesettlersonline.nl/*
// @include        https://www.thesettlersonline.pl/*
// @include        https://www.thesettlersonline.ro/*
// @include        https://www.thesettlersonline.ru/*
// @include        https://www.thesettlersonline.es/*
// ==/UserScript==

(function() {
    var li1 = document.createElement ('li');
        li1.className = "promotion first ";
    //    li1.className = "active main ";
    li1.innerHTML =  '<span></span><a id="clbutton" href="https://dso-karten.com/" alt="Zu den Taktikkarten" title="Zu den Taktikkarten" target="_blank"><img src="https://forum.thesettlersonline.pl/images/settlers/editor/createlink.png" width="16" height="16" align="center" valign="center"></img> Taktikkarten <img src="https://forum.thesettlersonline.pl/images/settlers/statusicon/forum_link-16.png" width="16" height="16" align="center" valign="center"></img></font></b></a>';
    document.querySelector("#menu ul").appendChild(li1);


    var li2 = document.createElement ('li');
    li2.className = "active main ";
    li2.innerHTML =  '<span></span><a id="clbutton" href="https://www.hagenbusch.de/forum" alt="Zum Forum Lostsettler" title="Zum Forum Lostsettler" target="_blank"><img src="https://forum.thesettlersonline.pl/images/settlers/editor/createlink.png" width="16" height="16" align="center" valign="center"></img> Forum lostsettler <img src="https://forum.thesettlersonline.pl/images/settlers/statusicon/forum_link-16.png" width="16" height="16" align="center" valign="center"></img></font></b></a>';
    document.querySelector("#menu ul").appendChild(li2);


    var li3 = document.createElement ('li');
    li3.className = "active main ";
    li3.innerHTML =  '<span></span><a id="clbutton" href="https://www.sammlerworld.de" alt="Sammlerworld" title="Zum Client Install" target="_blank"><img src="https://forum.thesettlersonline.pl/images/settlers/editor/createlink.png" width="16" height="16" align="center" valign="center"></img> Client install <img src="https://forum.thesettlersonline.pl/images/settlers/statusicon/forum_link-16.png" width="16" height="16" align="center" valign="center"></img></font></b></a>';
    document.querySelector("#menu ul").appendChild(li3);


    var li4 = document.createElement ('li');
    li4.className = "promotion first ";
    li4.innerHTML = '<span></span><a id="clplay" href="#" alt="Spielen Sie mit dem DSO-Client" title="Spiele mit Client"><img src="https://tso-pl-ssl.cdn.ubi.com/sites/default/themes/siedler/images/community/news/forward.png" width="10" height="20" align="center" valign="center"></img><b>&nbsp Spiele mit Client &nbsp<img src="https://tso-pl-ssl.cdn.ubi.com/sites/default/themes/siedler/images/community/news/backward.png" width="10" height="20" align="center" valign="center"></img></font></b></a>';
if(document.querySelector(".jsInstance-logout") == null)
  return;
       document.querySelector("#menu ul").appendChild(li4);


var url = new URL(window.location.href);
    document.getElementById("clplay").onmouseover = function() {document.getElementById("clplay").style.color = "#ffffff"};
    document.getElementById("clplay").onmouseout = function() {document.getElementById("clplay").style.color = "#000000"};
    document.getElementById("clplay").addEventListener("click", async () => {
    var playNowUrl = (/playNowforwardUrl = "(.+)";/g.exec(document.body.innerHTML))[1];
    if (!playNowUrl) {
        alert("something went wrong playNowforwardUrl");
        return;
    }
    var request = await fetch(url.origin + playNowUrl, {
            method: 'GET',
            credentials: 'include',
            redirect: 'manual'
        });
    var body = await request.text();
    var tso = (/return "(.*)"/g.exec(body))[1];
    window.location.href = "tso://"+tso+"&baseUri="+encodeURIComponent(url.origin);
    return;
    window.location.href = "tso://"+tso+"&baseUri="+url.origin;
    return;
  });
})();