Greasy Fork is available in English.

U2编辑框增强

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

Verze ze dne 02. 01. 2019. Zobrazit nejnovější verzi.

// ==UserScript==
// @name U2编辑框增强
// @version 1.0.0
// @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
    );
})()