Greasy Fork

来自缓存

Greasy Fork is available in English.

U2编辑框增强

给U2的编辑框加上点按钮儿

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name U2编辑框增强
// @version 1.0.1
// @description 给U2的编辑框加上点按钮儿
// @namespace Violentmonkey Scripts
// @match https://u2.dmhy.org/upload.php*
// @match https://u2.dmhy.org/edit.php?id=*
// @grant none
// ==/UserScript==
(() => {
    const editArea = document.querySelector('#descr');
    const createButton = (buttonName) => {
        const btnContainer = document.createElement('td');
        const btnInput = document.createElement('input');
        btnContainer.className = 'embedded';
        btnInput.value = buttonName.toUpperCase();
        btnInput.style.fontSize = '11px';
        btnInput.style.marginRight = '3px';
        btnInput.className = 'codebuttons';
        btnInput.type = 'button';
        btnContainer.appendChild(btnInput);
        btnInput.addEventListener('click', (e) => {
            e.preventDefault();
            insertTag(editArea, [`[${buttonName}]`, `[/${buttonName}]`]);
        });
        return btnContainer;
    }
    const insertTag = (element, tag) => {
        const start = element.selectionStart;
        const end = element.selectionEnd;
        element.value = element.value.slice(0, start) + tag[0] + element.value.slice(start, end) + tag[1] + element.value.slice(end);
    }
    
    
    const lastTableDataCell = 
        location.href.includes('edit.php') 
        ? document.querySelector('#compose > table > tbody > tr:nth-child(7) > td.rowfollow > table > tbody > tr:nth-child(1) > td > table > tbody > tr > td:nth-child(6)')
        : document.querySelector('#compose > table > tbody > tr:nth-child(35) > td.rowfollow > table > tbody > tr:nth-child(1) > td > table > tbody > tr > td:nth-child(6)');

    const spoilerBtnContainer = createButton('spoiler');
    lastTableDataCell.parentNode.insertBefore(
        spoilerBtnContainer,
        lastTableDataCell.nextSibling
    );
    const mediaInfoBtnContainer = createButton('mediainfo');
    spoilerBtnContainer.parentNode.insertBefore(
        mediaInfoBtnContainer,
        spoilerBtnContainer.nextSibling
    );
})()