Greasy Fork

来自缓存

Greasy Fork is available in English.

Auto_Link_Quote_by_el9in

Auto Link Quote

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Auto_Link_Quote_by_el9in
// @namespace    Auto_Link_Quote_by_el9in
// @version      0.3
// @description  Auto Link Quote
// @author       el9in
// @match        https://zelenka.guru/*
// @match        https://lolz.guru/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=zelenka.guru
// @grant        unsafeWindow
// @license      el9in
// ==/UserScript==

(function() {
    'use strict';
    const button = document.querySelector('button.lzt-fe-se-sendMessageButton');
    const div = document.querySelector('div.fr-element.fr-view.fr-element-scroll-visible');
    if (button && div) {
        button.addEventListener('click', function() {
            if (div) {
                const elements = [];
                const childElements = div.children;
                for (var i = 0; i < childElements.length; i++) {
                    console.log(true,childElements[i]);
                    if (childElements[i].hasAttribute('data-source')) {
                        const element = childElements[i];
                        const dataSource = element.getAttribute('data-source');
                        const postId = dataSource.split(':')[1];
                        const outerHTML = element.outerHTML;
                        const paragraph = element.querySelector('p');
                        const innerText = paragraph.innerText;
                        const currentUrl = document.location.href;
                        const pageRegex = /page-(\d+)/;
                        const pageCommentRegex = /post_comment/;
                        const threadIdRegex = /threads\/(\d+)/;
                        const match = currentUrl.match(pageRegex);
                        const matchThread = currentUrl.match(threadIdRegex);
                        const matchComment = dataSource.match(pageCommentRegex);
                        if (match && matchComment) {
                            const pageNumber = match[1];
                            paragraph.innerText = `[URL=https://zelenka.guru/posts/comments/${postId.substr(1)}]` + innerText + `[/URL]`;
                        } else if (match && matchThread) {
                            const pageNumber = match[1];
                            const threadId = matchThread[1];
                            paragraph.innerText = `[URL=https://zelenka.guru/threads/${threadId}/page-${pageNumber}#post-${postId.substr(1)}]` + innerText + `[/URL]`;
                        } else if(matchThread) {
                            const threadId = matchThread[1];
                             paragraph.innerText = `[URL=https://zelenka.guru/threads/${threadId}/#post-${postId.substr(1)}]` + innerText + `[/URL]`;
                        }
                    }
                }
            }
        });
    }
})();