From 1c8b55cd121e230e8723aff7a332fbf603e1a015 Mon Sep 17 00:00:00 2001 From: Nikolay Bryskin Date: Thu, 24 Nov 2022 22:06:54 +0200 Subject: [PATCH] [twitter] Fix reply auto-input in Twitter --- extensions/src/webln.js | 6 +++++- frontend/src/lib/utils.js | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/src/webln.js b/extensions/src/webln.js index b6966b95..b6949505 100644 --- a/extensions/src/webln.js +++ b/extensions/src/webln.js @@ -29,8 +29,12 @@ if (!window.donate4funPageScriptLoaded) { async function emulateKeypresses(selector, content) { const element = selector === ':focus' ? document.activeElement : document.querySelector(selector); - // Thanks to https://github.com/keepassxreboot/keepassxc-browser/blob/d7e34662637b869500e8bb6344cdd642c2fb079b/keepassxc-browser/content/keepassxc-browser.js#L659-L663 // This code is here because if call it from content script warnings will occur "Permission denied to access property X". (YouTube overrides event handles and tries to access event attributes) + // This works on Chrome + const dataTransfer = new DataTransfer(); + dataTransfer.setData("text/plain", content); + element.dispatchEvent(new ClipboardEvent('paste', { bubbles: true, clipboardData: dataTransfer, data: null })); + // And this works on Firefox element.dispatchEvent(new InputEvent('beforeinput', {bubbles: true, inputType: "insertText", data: content})); element.dispatchEvent(new InputEvent('input', {bubbles: true, inputType: "insertText", data: content})); element.dispatchEvent(new Event('change', {bubbles: true})); diff --git a/frontend/src/lib/utils.js b/frontend/src/lib/utils.js index 27a027cf..f2696b9e 100644 --- a/frontend/src/lib/utils.js +++ b/frontend/src/lib/utils.js @@ -1,4 +1,5 @@ import { readable, writable, get } from 'svelte/store'; +import cLog from "$lib/log.js"; export const webOrigin = writable(globalThis.location.origin); export const isExtension = !globalThis.location.origin.startsWith('http');