tweetdeck paku tweet

Let's paku tui!

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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        tweetdeck paku tweet
// @namespace   https://tweetdeck.twitter.com/
// @description Let's paku tui!
// @version     0.9
// @grant       none
// @match     https://twitter.com/i/tweetdeck*
// ==/UserScript==

(function() {
    let FLAG = true;
    function pakuTweet(e) {
        // if (!confirm("パクツイしますか?")) return; // この行の先頭の//を消せばパクツイ前に確認する
        let parent = e.target.closest(".js-tweet");
        // parent.querySelector(".js-icon-favorite").click(); // この行の先頭の//を消せばふぁぼする
        let tweet = parent.querySelectorAll(".tweet-text")[0].innerHTML;
        tweet = tweet
            .replace(/<img class="emoji" draggable="false" alt="([^"]*)" src="([^"]*)">/g, "$1")
            .replace(/<a href="([^"]*)" target="_blank" class="url-ext"[^>]*>[^<]*<\/a>/g, "$1")
            .replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, "")
            .replace(/&amp;/g, "&")
            .replace(/&lt;/g, "<")
            .replace(/&gt;/g, ">");
        console.log(e.ctrlKey);
        if (e.ctrlKey) {
            let s = tweet.match(/\d+$/);
            if (s !== null) {
              tweet = tweet.replace(/\d+$/, parseInt(s)+1);
            } else {
              tweet = tweet + "2";
            }
        }
        let textarea = document.querySelector(".js-compose-text");
        if (textarea === null) {
            document.querySelector(".tweet-button").click();
            textarea = document.querySelector(".js-compose-text");
        }
        textarea.value = tweet;
        let event = document.createEvent("HTMLEvents");
        event.initEvent("change", false, false);
        textarea.dispatchEvent(event);
        if (!e.shiftKey) document.querySelector(".js-send-button").click();
    }

    function appendButton(node) {
        let target = node.querySelectorAll(".js-tweet-actions .tweet-action-item")[3];
        if (target === null || undefined) return;
        let src= document.createElement("li");
        src.className = "tweet-action-item pull-left margin-r--13 margin-l--1";
        let src_a = document.createElement("a");
        src_a.className = "tweet-action position-rel";
        src_a.href = "#";
        src_a.textContent = "(´・_・`)";
        src.appendChild(src_a);
        let item = target.parentNode.insertBefore(src, target);
        item.querySelector("a").addEventListener("click", pakuTweet);
    }

    while (FLAG) {
        if (document.querySelector(".application") !== null) {
            setTimeout(() => {}, 300);
            let observer = new MutationObserver((mutations) => {
                mutations.forEach((mutation) => {
                    mutation.addedNodes.forEach((node) => {
                        if (node.nodeType == node.ELEMENT_NODE && node.classList.contains('js-stream-item')) {
                            appendButton(node);
                        }
                    });
                });
            });
            observer.observe(document.body, {childList: true, subtree: true});
            FLAG = false;
        }
    }
})();