Pastebin Paste Auto Submit with Clipboard Permission

Automatically paste clipboard content and submit it on dpaste Pastebin, retrying if clipboard permission is denied.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pastebin Paste Auto Submit with Clipboard Permission
// @namespace    fiverr.com/web_coder_nsd
// @version      1.3
// @description  Automatically paste clipboard content and submit it on dpaste Pastebin, retrying if clipboard permission is denied.
// @author       NoushadBug
// @match        https://dpaste.org/?autopaste=true
// @icon         https://dpaste.org/static/favicon.png
// @grant        none
// @license MIT
// ==/UserScript==

(async function () {
    'use strict';

    async function handleClipboard() {
        try {
            // Request permission for clipboard read if not granted
            const permissionStatus = await navigator.permissions.query({ name: 'clipboard-read' });
            if (permissionStatus.state === 'denied') {
                console.warn('Clipboard read access is denied. Requesting access...');
                alert('Clipboard read access is required. Please allow it in your browser settings.');
                return; // Exit if access is denied
            }

            // Get clipboard content
            const clipboardText = await navigator.clipboard.readText();
            console.log('Clipboard content retrieved:', clipboardText);

            document.querySelector('[name="expires"]').value='2592000'

            // Find the textarea and set its value
            const textarea = document.querySelector('textarea');
            if (textarea) {
                textarea.value = clipboardText;
                console.log('Pasted clipboard content into the textarea.');
            } else {
                console.error('Textarea not found on the page.');
                return;
            }

            // Find and click the submit button
            const submitButton = document.querySelector('button[type="submit"]');
            if (submitButton) {
                submitButton.click();
                console.log('Clicked the submit button.');
            } else {
                console.error('Submit button not found on the page.');
            }
        } catch (error) {
            console.error('Error handling clipboard or interacting with the page:', error);
        }
    }

    // Trigger clipboard handling once the page loads
    window.addEventListener('load', async () => {
        try {
            await handleClipboard();
        } catch (error) {
            console.error('An error occurred while attempting to process the clipboard:', error);
        }
    });
})();