MastodonRTScript

try to take over the world!

Από την 28/05/2019. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         MastodonRTScript
// @version      0.52
// @description  try to take over the world!
// @author       GensouSakuya
// @require      https://code.jquery.com/jquery-3.1.1.min.js
// @match        https://nebula.moe/*
// @namespace https://greasyfork.org/users/194737
// ==/UserScript==

//↑↑@match的意思是匹配特定的实例域名,需要增加新的实例则另起一行填入url即可
//例如 // @match         https://acg.mn/*
(
    function() {

        var rtButtonHtml = '<div class="compose-form__publish-button-wrapper" style="margin-right:16px"><button class="button button--block" id="rtButton" style="padding: 0px 16px; height: 36px; line-height: 36px;">转嘟!</button></div>';

        var buttonHtml = '<button aria-pressed="false" title="转发" class="status__action-bar-button star-icon icon-button" tabindex="0" style="font-size: 18px; width: 23.1429px; height: 23.1429px; line-height: 18px;"><span style="font-weight: bold;">RT</span></button>'

        $(document).on('DOMNodeInserted', injectAdditionalDownloadButtons);


        function injectAdditionalDownloadButtons(event)
        {
            if(event.target.localName == 'article')
            {
                injectRTButton(event.target);
            }
        }
        function injectRTButton(target) {
            var parentdiv = $(target).find('.status__action-bar');
            //var id = target.attributes["data-id"].value;
            var html = buttonHtml;//downloadButton.replace("########",id);
            var button = $(html).insertAfter($(parentdiv).children('.star-icon'));
            ////

            //var replybtn = $(parentdiv).find("[title]:eq(0)");
            //console.log(replybtn);
            ////
            $(button).off("click").on("click",function () {
                retootClick(this);
            });
        }

        var tootBtn;

        function retootClick(btn){
            //console.log(btn);
            var replybtn = $(btn).parent().find("[title]:eq(0)");
            replybtn.click();
            var tootbtn = $(btn).parent().find("[title]:eq(1)");
            tootBtn = tootbtn;

            var cwBtn = $(".compose-form__buttons-wrapper").find("button:eq(3)");
            if(cwBtn.hasClass("active"))
            {
                cwBtn.click();
            }
            var textarea = $(".compose-form__autosuggest-wrapper").find("textarea");
            textarea.val("RT ");
            displayRTbtn();
        }

        var sendBtn;

        function RTbtnClick(){
            var textarea = $(".compose-form__autosuggest-wrapper").find("textarea");
            var msg = textarea.val();
            $(".reply-indicator").find("button").click()
            textarea.val(msg);
            tootBtn.click();
            setTimeout(sendBtn.click(),800);
            removeRTbtn();
        }

        function displayRTbtn(){
            if($("#rtButton").length==0)
            {
                sendBtn = $(".compose-form__publish").find("button");
                $(rtButtonHtml).insertBefore($(".compose-form__publish").find(".compose-form__publish-button-wrapper"));
                $('#rtButton').off("click").on("click",RTbtnClick);
            }
            else
            {
                $("#rtButton").css("display","block");
            }
        }

        function removeRTbtn(){
                $("#rtButton").css("display","none");
        }
    }()
)