marklieberman / foxygestures

Mouse gestures for Firefox
GNU General Public License v3.0
190 stars 20 forks source link

Suggestion: Paste and Go #143

Open Chewbugga opened 7 years ago

Chewbugga commented 7 years ago

It's basically a function I've known from Opera since forever and been able to replicate via FireGestures. It simply pastes the current clipboard content into the address bar and executes. In terms of keyboard shortcuts Ctrl+L / Ctrl+V / RETURN

Any solutions and/or suggestions greatly appreciated! Great Addon, huge potential!

ganego commented 7 years ago

Came here for the same reason. Back in FireGestures you could use "readFromClipboard();" in a custom script but I guess this function was provided by FireGestures.

EDIT 1: Seems it might be possible: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Interact_with_the_clipboard#Reading_from_the_clipboard But the extension need the clipboardRead permission too, that it does not have right now: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/permissions

marklieberman commented 7 years ago

The Web Extensions APIs for clipboards are kinda incomplete. Its doable but in a really lousy way that requires injecting a textbox into the DOM, pasting the clipboard into it, and reading the value back. (Exposing whatever URL/content was in your clipboard to the website in your tab.) Basically the reverse of Copy URL to Clipboard. You cannot do it yet though because I'd have to request clipboardRead permission in manifest.json.

ganego commented 7 years ago

Yes what I have right now is the following, and I also set the clipboardRead permisson in the manifest and loaded the addon into my nightly with disabled signature checking.

// Create a text area with the value we want to copy.
let textarea = document.createElement("textarea");

// Style textarea to make it fairly invisible.
// Copy doesn't work when display: none.
textarea.style.maxHeight = '2em';
textarea.style.maxWidth = '2em';
textarea.style.position = 'fixed';
textarea.style.top = 0;
textarea.style.left = 0;
textarea.style.padding = 0;
textarea.style.border = 'none';
textarea.style.outline = 'none';
textarea.style.boxShadow = 'none';
textarea.style.background = 'transparent';

textarea.contentEditable="true";

// Append the textarea, copy its value, then remove it.
document.body.appendChild(textarea);
textarea.select();
//textarea.focus()
document.execCommand("Paste");
console.log(textarea.value);
console.log(textarea.textContent);
//textarea.remove();

Little problem: It does not work. console.log() will be triggered but prints two empty lines.

marklieberman commented 7 years ago

Even weirder... here is a version of the script that works but only once. If I use "Load temporary addon" I can paste whatever was in my clipboard before the addon was loaded. But it only works once, then never again until the addon is reloaded.

executeInBackground(() => {
    // Create a text area with the value we want to copy.
    let textarea = document.createElement("textarea");
    textarea.contentEditable = true;
    document.body.appendChild(textarea);
    textarea.select();
    document.execCommand("paste");
    console.log(textarea.value);
    textarea.parentNode.removeChild(textarea);
});
ganego commented 7 years ago

I can somewhat reproduce this, it worked twice but I had to restart FF and load the foxygestures options or so. This is definitely not working as it should

marklieberman commented 6 years ago

clipboard.readText and clipboard.writeText appear to have landed in FF63 so it may be worth revisiting this issue soon.