sis001 upload multiple file

sis001 upload multiple files

Tính đến 12-10-2023. Xem phiên bản mới nhất.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         sis001 upload multiple file
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  sis001 upload multiple files
// @author       You
// @match        https://sis001.com/forum/post.php?action=newthread*
// @match        https://sis001.com/forum/post.php?action=edit*
// @match        https://sis001.com/forum/post.php?action=reply*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sis001.com
// @grant        none
// @license MIT
// ==/UserScript==

var origainalInsertAttach

function main() {
    configMultipleInput()
    origainalInsertAttach = this.insertAttach
    this.insertAttach = customInsertAttach
}

function configMultipleInput() {
    console.log('configMultipleInput')
    Array.from(
        document
        .getElementById('posteditor_bottom')
        .getElementsByTagName('input')
    ).forEach((ele) => {
        if (ele.name == 'attach[]') {
            replaceInput(ele, (newInput) => {
                newInput.setAttribute('multiple', 'multiple')
            })
        }
    })
}

function customInsertAttach(id) {
    try {
        console.log('customInsertAttach')
        var input = document.getElementById('attach_' + id)
        let files = input.files
        Array.from(files)
            .forEach((file, index) => {
                let currentId = id + index
                let currentInput = document.getElementById('attach_' + currentId)
                replaceInput(currentInput, (newInput) => {
                    newInput.files = createFileList(file)
                })
                origainalInsertAttach(currentId)
            })
    } catch (e) {
        console.log(e)
    }
}

function replaceInput(old, op) {
    let newInput = old.cloneNode()
    newInput.onchange = old.onchange
    op(newInput)
    old.parentElement.replaceChild(newInput, old)
    return newInput
}

function createFileList(file) {
    let newList = new DataTransfer()
    newList.items.add(file)
    return newList.files
}

main()