benzBrake / FirefoxCustomize

Ryan 收集的 Firefox 个性化相关资源
150 stars 33 forks source link

AutoCopySelectionText.uc.js and timer #1

Closed Orriky closed 2 years ago

Orriky commented 2 years ago

Hi, I'd like you consider an improvement for this useful script. I'd prefer to copy the selected text only when the left mouse button is keep pressed for a specified time after you have selected your text. You can set time to zero if you want the script works as it does now.

Thanks

benzBrake commented 2 years ago

Done, I don't use this script, may be has bugs.

Orriky commented 2 years ago

Thanks!!!

It's wonderful. Maybe it has some bugs as you said, however it's already more useful to me.

Orriky commented 2 years ago

I'd like also the autocopy will be available even in the input boxes, urlbar etc

benzBrake commented 2 years ago

The next few days I intend to travel with my family. I will take a look in the next week.

benzBrake commented 2 years ago

Now available in the input boxes of webpages. I think auto copy it's not suitable for urlbar. So i've not Integrated within this script. I give you a demo sciprt for copy urlbar script as follow

if (location.href.startsWith('chrome://browser/content/browser.x')) {
    document.getElementById('urlbar-input').addEventListener('mouseup', function(e) {
        if (e.button == 0)  {
            var input = event.target;
            var gClipboardHelper = Components.classes['@mozilla.org/widget/clipboardhelper;1'].getService(Components.interfaces.nsIClipboardHelper);
            gClipboardHelper.copyString(input.value.substring(input.selectionStart, input.selectionEnd));
        }
    }, false);
}
Orriky commented 2 years ago

Thanks again, great work.

Are you interested in making this script work again? https://gist.github.com/Griever/709653 overwriteMiddleMousePaste.uc.js


// ==UserScript==
// @name           overwriteMiddleMousePaste.uc.js
// @namespace      http://d.hatena.ne.jp/Griever/
// @include        main
// ==/UserScript==

document.documentElement.addEventListener("click", function(event){
    if (event.button !== 1 || !gPrefService.getBoolPref('middlemouse.paste')) return;

    var localName = event.target.localName.toLowerCase();
    if ((localName === 'input' || localName === 'textarea' || localName === 'textbox') && 
            document.commandDispatcher.getControllerForCommand("cmd_paste") ){
        goDoCommand("cmd_paste");
        event.preventDefault();

}

Firefox doesn't overwrite the already selected text when you paste the clipboard content using middle click. That's annoying to me.

benzBrake commented 2 years ago

Nope, uc script can not modified web page directly, need to load in framscript, you can refer to AutoCopySelectionText.uc.js