Eventernote Twitterリンク追加

Eventernote のユーザーページにTwitterへのリンクを追加する

// ==UserScript==
// @name         Eventernote Twitterリンク追加
// @namespace    https://www.eventernote.com/
// @version      0.0.4
// @description  Eventernote のユーザーページにTwitterへのリンクを追加する
// @author       4y4m3
// @match        https://www.eventernote.com/users*
// @grant        GM_xmlhttpRequest
// @license      MIT
// ==/UserScript==

(function () {
    const f = document.querySelector('div.follow p');

    const mobileUrl = window.location.href;
    GM_xmlhttpRequest({
        method: "GET",
        url: mobileUrl,
        headers: {"User-Agent": "Mozilla/5.0 (Android 13; Mobile; rv:100.0) Gecko/20100101 Firefox/120.0"},
        onload: function(response){
            const parser = new DOMParser();
            const mobileDoc = parser.parseFromString(response.responseText, "text/html");
            const twitterLinkElement = mobileDoc.querySelector('p.twitter a');

            if(twitterLinkElement){
                const twitterUrl = twitterLinkElement.href;
                console.log(twitterUrl);
                const twitterId = twitterUrl.replace(/\/+$/, "").split('/').pop();
                f.outerHTML = '<p class="center">' + f.innerHTML + ' <a class="btn btn-large btn-primary" href="https://twitter.com/' + twitterId + '">@'+twitterId+'</a></p>';
            } else {
                console.log("Twitter URL not found.");
                const n = document.querySelector('.name1');
                const eventerId = n.innerText;
                f.outerHTML = '<p class="center">' + f.innerHTML + ' <a class="btn btn-large" href="https://twitter.com/' + eventerId + '">Twitter🔍</a></p>';
            }
        },
        onerror: function(error){
            console.error("Failed to fetch mobile page:",error);
        }
    })
})();