PasteImage

全网粘贴图片为图床链接

Versione datata 21/07/2022. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         PasteImage
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  全网粘贴图片为图床链接
// @author       Polygon
// @match        *://*/*
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAAAXNSR0IArs4c6QAADv1JREFUeF7tnWfsLkUVxn/4wQiWIFFBsYViABOIUkRFgxJRRLFEEKPYKCJWFAyiUYlRgmCJBQsizQISo0RBAQXBSpFmTRRIBAxESvhgix8wD+wfX+69/7vvzp6Znd19Jnlzb3LnnDnnN/vc993Z2TMb4GYCJrAqgQ3MxgRMYHUCFoivDhNYDwELxJeHCVggvgZMII2Av0HSuNlqJgQskJlMtNNMI2CBpHGz1UwIWCAzmWinmUbAAknjZquZELBAZjLRTjONgAWSxs1WMyFggcxkop1mGgELJI2brWZCwAKZyUQ7zTQCFkgaN1vNhIAFMpOJdpppBCyQNG62mgmBMQjkkcCWC58tmr/PZIomleb1wA2A/lz53FVzhrUKZHdgT+AVwDY1A3RsvQn8CfgucAHw097egh3UJ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0lECWp5ySHBWxsLArMgxUnoIeAJ+Z6ztGWzZACWYlN21IklKi9W205+9/HQUB7qySMsHc7UtKuQSArcWsXsKpRaJPapinJ2Gb0BG4DLmiq44Tuyk0lU5NAFnPQStfKJ+eB86ncbBdHQEUDtTK18onzHOCpVoEspqZqKVsufLZo/h6Qvl0UJnA9cAOgP1c+IdVHcuUxBoHkyt1+TaCVgAXSisgd5kzAApnz7Dv3VgIWSCsid5gzAQtkzrPv3FsJWCCtiNxhzgQskDnPvnNvJWCBtCJyhzkTsEDmPPvOvZWABdKKyB3mTMACmfPsO/dWAhZIKyJ3mDMBC2TOs+/cWwlYIK2I3GHOBCyQOc++c28lYIG0InKHOROwQOY8+869lYAF0orIHeZM4H9dhnvniYwwoQAAAABJRU5ErkJggg==
// @grant        GM_xmlhttpRequest
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';
    const notification = (function() {
        'use strict';
        GM_addStyle(`
            #notification {
                box-sizing: border-box;
                position: fixed;
                left: calc(50% - 365.65px / 2);
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: center;
                height: 50px;
                background-color: #ff7675;
                border-radius: 50px;
                padding: 0 0px 0px 20px;
                top: -50px;
                transition: top .5s ease-out;
                z-index: 9999999999;
                font-family: Arial;
            }
            #notification .content {
                display: flex;
                align-items: center;
                justify-content: center;
                color: white;
                font-size: 25px;
            }
            #notification .closeBox {
                margin: 0 10px;
                transform: rotate(90deg);
                cursor: pointer;
            }
            #notification .closeBox .progress {
                margin: 0 10px;
                cursor: pointer;
            }
            #notification .closeBox .progress .circle {
                stroke-dasharray: 100;
                animation: progressOffset 0s linear;
            }
            @keyframes progressOffset {
                from {
                    stroke-dashoffset: 100;
                }
                to {
                    stroke-dashoffset: 0;
                }
            }
        `)
        return {
            open(info, timeout, autoClose=true) {
                let eles = document.querySelectorAll('#notification')
                for (let i=0;i<eles.length;i++) {
                    this.close(eles[i])
                }
                this.box = document.createElement('div')
                this.box.setAttribute('id', 'notification')
                this.box.innerHTML = `
                    <div class="content"></div>
                    <svg class="closeBox" width="40" height="40">
                        <g class="close" style="stroke: white; stroke-width: 2; stroke-linecap: round;">
                            <line x1="13" y1="13" x2="27" y2="27"/>
                            <line x1="13" y1="27" x2="27" y2="13"/>
                        </g>
                        <g class="progress" fill="transparent" stroke-width="3">
                            <circle class="background" cx="20" cy="20" r="16" stroke="rgba(255,255,255,0.15)"/>
                            <circle class="circle" cx="20" cy="20" r="16" stroke="rgba(255,255,255,1)"/>
                        </g>
                    </svg>
                    `
                document.body.appendChild(this.box)
                this.box.querySelector('.content').innerHTML = info
                let width = getComputedStyle(this.box).width
                this.box.style.left = `clac(50%-${width}/2)`
                this.box.querySelector('.closeBox .progress .circle').style['animation-duration'] = `${timeout}s`
                this.box.style.top = '100px'
                this.box.querySelector('.closeBox .progress').addEventListener('click', () => {
                    console.log('you close...')
                    this.close()
                    console.log('you clear...')
                })
                if (autoClose) {
                    setTimeout(() => {
                        console.log('timeout close...')
                        this.close()
                        console.log('timeout clear ...')
                    }, timeout * 1000)
                }
            },
            close(ele=null) {
                if (!ele) {ele=this.box}
                ele.style['transition-duration'] = '.23s'
                ele.style['transition-timing-function'] = 'eaer-out'
                ele.style.top = '-50px'
                setTimeout(() => {
                    try {
                        document.body.removeChild(this.box)
                    } catch {
                        console.log('clear')
                    }
                }, 233)
            }
        }
    })()
    document.addEventListener('paste', function(event) {
    var items = (event.clipboardData && event.clipboardData.items) || [];
    var file = null;
    function insertText(obj, str) {
        obj.focus()
        if(document.selection) {
            var sel = document.selection.createRange();
            sel.text = str;
        } else if(typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
            var startPos = obj.selectionStart,
                endPos = obj.selectionEnd,
                cursorPos = startPos,
                tmpStr = obj.value;
            obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
            cursorPos += str.length;
            obj.selectionStart = obj.selectionEnd = cursorPos;
        } else {
            obj.value += str;
        }
    }
    if (items && items.length) {
        for (var i = 0; i < items.length; i++) {
            if (items[i].type.indexOf('image') !== -1) {
                notification.open('upload image...', 1)
                let fileObj = items[i].getAsFile();
                console.log(fileObj)
                // https://www.cnblogs.com/hg-hsd/p/5999472.html
                var form = new FormData()
                form.append("image", fileObj)
                console.log(form)
                GM_xmlhttpRequest({
                    method: 'POST',
                    url: 'https://yh-pic.ihcloud.net/api/jd.php',
                    responseType: 'json',
                    data: form,
                    onload: function (res) {
                        let imgURL = res.response.data.url
                        console.log(imgURL)
                        navigator.clipboard.writeText(imgURL)
                        insertText(document.activeElement, imgURL)
                        notification.open('success~', 1)

                    }

                })
                break;
            }
        }
    }
});
})();