Feeder - Paste Upload

User script for uploading files from the clipboard in Feeder chat.

Tính đến 30-12-2022. 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            Feeder - Paste Upload
// @name:ja         Feeder - 貼り付けてアップロード
// @description     User script for uploading files from the clipboard in Feeder chat.
// @description:ja  Feederチャットでクリップボードからファイルをアップロードするためのユーザースクリプトです。
// @version         2.0.3
// @icon            data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABQ/wQAUP8GAAAAAAAAAAAASv4qAD//dgBL/qoBUf+yAFD/jwBQ/koAUP8FAAAAAABQ/wQAUP8FAE/+AABQ/wUAAAAAAAAAAAAAAAAATP9wA1L/6x5k//8LV//+AE3+/gBP//8AUP//AFD/qwBQ/h4AAAAAAAAAAAAAAAAAT/+UAFD+gQBQ/1kATv+MAEj//hxj//+rxf//SIH//wBF//8ATv//AE/+/wBQ//8AUP+8AFD/XQBQ/3EAUP+NAE/+aQBP/3wAUP+uAE7+/wBH//8tb//+3uj//l+R//8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eder.info/*/
// @exclude         https://*.x-feeder.info/*/*/*
// @namespace       https://github.com/sqrtox/userscript-feeder-paste-upload
// @author          sqrtox
// @license         MIT
// @grant           unsafeWindow
// ==/UserScript==
"use strict";
(() => {
  // src/utils/ElementIds.ts
  var ElementIds = {
    DropzoneArea: "picture_drop_zone_area",
    OpenDropzoneAreaButton: "post_picture",
    ImageSizeSelect: "frame_size",
    PostFormSingle: "post_form_single",
    PostFormMultiline: "post_form_multi"
  };

  // src/utils/getElement.ts
  var getElement = (id) => {
    const element = document.getElementById(id);
    if (!element) {
      throw new Error(`Element with id "${id}" not found`);
    }
    return element;
  };

  // src/utils/ImageSizes.ts
  var ImageSizes = {
    Original: "0",
    Small: "1",
    Medium: "2",
    Large: "3",
    ExtraLarge: "4",
    Largest: "5"
  };

  // src/utils/openDropzoneArea.ts
  var openDropzoneArea = () => {
    const dropzoneArea = getElement(ElementIds.DropzoneArea);
    const dropzoneAreaIsHidden = !dropzoneArea.style.display || dropzoneArea.style.display === "none";
    if (dropzoneAreaIsHidden) {
      const openDropzoneAreaButton = getElement(ElementIds.OpenDropzoneAreaButton);
      openDropzoneAreaButton.click();
      const imageSizeSelect = getElement(ElementIds.ImageSizeSelect);
      imageSizeSelect.value = ImageSizes.Original;
    }
  };

  // src/utils/getDropzone.ts
  var getDropzone = () => {
    const dropzone = unsafeWindow.Dropzone.instances[0];
    if (!dropzone) {
      throw new Error("Dropzone instance not found");
    }
    return dropzone;
  };

  // src/utils/handlePaste.ts
  var handlePaste = ({ clipboardData }) => {
    if (!clipboardData) {
      return;
    }
    const file = clipboardData.files[0];
    if (!file) {
      return;
    }
    openDropzoneArea();
    const dropzone = getDropzone();
    dropzone.addFile(file);
  };

  // src/utils/applyHandlePaste.ts
  var applyHandlePaste = () => {
    const postFormSingle = getElement(ElementIds.PostFormSingle);
    const postFormMultiline = getElement(ElementIds.PostFormMultiline);
    postFormSingle.addEventListener("paste", handlePaste);
    postFormMultiline.addEventListener("paste", handlePaste);
  };

  // src/index.ts
  applyHandlePaste();
})();