Add Button

Button Extend!

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Add Button
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Button Extend!
// @author       Апатия
// @license      MIT
// @match        https://zelenka.guru/forums/*
// @match        https://lolz.live/forums/*
// @match        https://lolz.guru/forums/*
// @match        https://zelenka.guru/threads/*
// @match        https://lolz.live/threads/*
// @match        https://lolz.guru/threads/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
// @supportURL   https://zelenka.guru/
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @grant        GM_listValues
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

function addButton() {
    var dropdown = document.querySelector('.fr-dropdown-list');
    var tippyPopper = document.querySelector('.tippy-popper');

    if (dropdown && tippyPopper) {
        if (!dropdown.querySelector('[data-cmd="newButton"]')) {
            var newLi = document.createElement('li');
            var newButton = document.createElement('a');
            newButton.classList.add('fr-command');
            newButton.setAttribute('data-cmd', 'newButton');
            newButton.style.whiteSpace = 'pre';

            var icon = document.createElement('i');
            icon.classList.add('fal', 'fa-circle', 'fa-fw');
            icon.setAttribute('aria-hidden', 'true');

            newButton.appendChild(icon);
            newButton.appendChild(document.createTextNode('  Кнопка'));

            newLi.appendChild(newButton);

            dropdown.appendChild(newLi);

            newButton.addEventListener('click', function() {
               alertExec()
            });
        }
    }
}



function alertExec() {
    removeXenForoAlert()
    document.querySelector('#lztInsert-1').click();
    var formHtml = `
                            <form id="xenforoFormButton" autocomplete="off" onsubmit="event.preventDefault();">
                                <label for="linkInput">Ссылка:</label>
                                <input type="text" id="linkInput" class="textCtrl" placeholder="Введите ссылку" /><br/>
                                <label for="textInput">Текст:</label>
                                <input type="text" id="textInput" class="textCtrl" placeholder="Введите текст" /><br/>
                                <button type="submit" class="button primary Overas">Вставить</button>
                            </form>
                        `;
                XenForo.alert(`${formHtml}`, 'Вставить кнопку');
                        document.querySelector('.button.primary.Overas').addEventListener('click', function() {
                        var link = document.querySelector('#linkInput').value;
                        var text = document.querySelector('#textInput').value;
                        addButtonToParagraph(link, text);
                        Array.from(document.querySelectorAll('.close.OverlayCloser')).pop().click();
});
}


function addButtonToParagraph(link, text) {
  const paragraph = Array.from(document.querySelectorAll(".fr-element.fr-view.fr-element-scroll-visible p")).pop();
  if (paragraph) {
    if (!link.startsWith('https://')) {
        link = 'https://' + link;
    }

    paragraph.innerHTML += `[button="${link}"]${text}[/button]`;
  }
}

function removeXenForoAlert() {
    var alertBox = document.querySelector('#xenforoFormButton');
    if (alertBox) {
        alertBox.remove();
    }
}



var observer = new MutationObserver(function(mutationsList, observer) {
    var openButton = document.querySelector('#lztInsert-1');

    if (openButton) {
        openButton.addEventListener('click', function() {
            setTimeout(addButton, 100);
        });

        observer.disconnect();
    }
});

observer.observe(document.body, { childList: true, subtree: true });

})();