ChatGPT(GPT-4) が書いたもの。

javascript:(function() {
    function twitterUrlToHugoShortcode(url) {
        const urlParts = url.split("/");
        const userName = urlParts[3];
        const tweetId = urlParts[5];
        return `{{< tweet user="${userName}" id="${tweetId}" >}}`;
    }
    const url = window.location.href;
    navigator.clipboard.writeText(twitterUrlToHugoShortcode(url))
    .then(() => alert('Hugo shortcode has been copied to clipboard!'))
    .catch(err => alert('Failed to copy Hugo shortcode: ', err));
})();