sis001 upload multiple file

upload multiple files

Verzia zo dňa 14.10.2023. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name         sis001 upload multiple file
// @namespace    https://github.com/fear1999/tampermonkey-scripts
// @version      0.4
// @description  upload multiple files
// @author       fear1999
// @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==

class MultiUpload {
    constructor() {
        this.configMultipleInput = this.configMultipleInput.bind(this)
        this.customInsertAttach = this.customInsertAttach.bind(this)
        this.replaceInput = this.replaceInput.bind(this)
        this.createFileList = this.createFileList.bind(this)
    }

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

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

    customInsertAttach(id) {
        let 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)
            this.replaceInput(currentInput, (newInput) => {
                newInput.files = this.createFileList(file)
            })
            this.origainalInsertAttach(currentId)
        })
    }

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

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


(new MultiUpload()).main()