THIS DOES NOT WORK YET, looking for someone to help make it work
it's super rough so far but anyone got ideas on why this doesn't work? basic idea of what I'm trying to do
- listen for paste events on compose and title boxes
- when paste event, check if there is a file
- if a file is present, assume it's an image,
- take the DataTransfer object
e.clipboardDataand create adropevent with it - dispatch an artificial event to the DragNDrop handler with clipboardData as the DataTransfer object `
I have tried sending the artificial event to both the hidden "RELEASE TO DROP" element and also its parent, neither seems to work.
also I would like the XPath selector to be a bit better but this works for now so either I'll do that later or you can let me know how to query elements by their text in XPath
// ==UserScript==
// @name cohost image paste
// @namespace http://tampermonkey.net/
// @version 0.1
// @description allow users to paste image into the compose box on cohost
// @author meadow wowperfect
// @match https://cohost.org/*/post/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=cohost.org
// @grant none
// ==/UserScript==
(function() {
'use strict';
const textareas = document.querySelectorAll('textarea')
textareas.forEach(t => {
t.addEventListener('paste', e => sendDropEvent(e))
})
function sendDropEvent(pasteEvent) {
const dropListener = document.evaluate('/html/body/div[1]/div/div/div/div[2]/div/div/div[2]/article/div/div/div', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue
console.log(dropListener)
const dataTransfer = pasteEvent.clipboardData
console.log('num files', dataTransfer.files.length)
if (dataTransfer.files.length < 1) return
pasteEvent.preventDefault()
const e = new DragEvent('drop', {dataTransfer})
dropListener.dispatchEvent(e)
}
})();POTENTIAL SOURCE OF BUG: I'm suspicious the issue is that I'm not creating the DragEventInit object correctly....






