/* When not sourcing this file (together with my/any art collection),

*/

/*

function addAddArtButtons() {

/* 

 * Get the relevant DOM elements:

 * textArea as a tARgeT to append the art

 * formContainer to append the buttons to

 */

const textArea = document.getElementsByTagName("textarea")[0];

const formContainer = document.getElementsByTagName("form")[0];

/* 

 * Check if textArea and formContainer exist

 * to avoid messing with sites like "site" or "notifications"

 * which don't have a textArea or neither

 */

if (typeof textArea !== 'undefined' && typeof formContainer !== 'undefined') {

    /*

     * Add the buttons and dropdown menu

     */

    formContainer.innerHTML = formContainer.innerHTML

     + '<select id="artList" name="artList"></select>'

     + '<input id="addArtBtn" value="Add Art" type="button">'

     + '<input id="delArtBtn" value="Del Art" type="button">';

     /*

      * Get the dropdown...

      */

    const artList = document.getElementById("artList");

    /*

     * ..and populate it with art...

     */

    for (aPiece in art) {

      var listItem = document.createElement("option");

        listItem.textContent = aPiece;

        listItem.value = art[aPiece];

        artList.appendChild(listItem);

    }

    /*

     * ..and since they MIGHT be loaded anyway, the logos aswell

     */

    for (logo in logos) {

        var listItem = document.createElement("option");

          listItem.textContent = 'logo/' + logo;

          listItem.value = logos[logo] + '\n';

          /* listItem.style = "color: purple;"; */

          artList.appendChild(listItem);

    }

    /*

     * Get and define the behaviour of the buttons

     */

    const addArtBtn = document.getElementById("addArtBtn");

    addArtBtn.onclick = function() {

        /*

         * Get the textarea again because?!

         */

        const textArea = document.getElementsByTagName("textarea")[0];

        /*

         * Append the current selected art piece from the dropdown list,

         * as preformatted gemtext

         */

        textArea.value = textArea.value

         + '\n```\n'

         + artList.value

         + '```\n';

    }

    const delArtBtn = document.getElementById("delArtBtn");

    delArtBtn.onclick = function() {

        /*

         * Textarea, one more time

         */

        const textArea = document.getElementsByTagName("textarea")[0];

        /*

         * Replace the last occurence of a preformatted gemtext block

         * with nothing

         * Not going to explain the regex here, I am just glad it works!

         * Basically we look for at least one character

         * surrounded

         * but not followed by

         * and not containing

         * three backticks (```)

         */

        textArea.value = textArea.value.replace(/\n```\n((?!```\n)[\S\s])+\n```\n(?![\S\s]*\n```\n)/, "");

    } 

}

}

/*

*/

if (window.location != "https://midnight.pub/") {

window.onload = addAddArtButtons;

}

/*

Proxy Information
Original URL
gemini://she12.midnight.pub/addArt.js
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
445.566755 milliseconds
Gemini-to-HTML Time
1.441372 milliseconds

This content has been proxied by September (ba2dc).