ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
315 stars 35 forks source link

How to use Bookmarklets with Context Menu? #690

Closed runningcheese closed 2 months ago

runningcheese commented 3 months ago

492

There is a same issue 2 years ago.
Has this problem been resolved now? Are there any browser restrictions? Thank you!

ssborbis commented 3 months ago

What is your bookmarklet code? I just tested a basic script with both the popup menu and the context menu and it seems to be working.

runningcheese commented 3 months ago

javascript:outText='';for(i=0;i<document.images.length;i++){if(outText.indexOf(document.images[i].src)==-1){outText+='<tr><td><img style=max-width:800px src='+document.images[i].src+'></td><td>'+document.images[i].naturalWidth+'x'+document.images[i].naturalHeight+'</td></tr><p>'}};if(outText!=''){imgWindow=window.open('','imgWin');imgWindow.document.write('<table style=margin:auto border=1 cellpadding=10><tr><th>Image</th><th>Size</th></tr><p>'+outText+'</table><p>');imgWindow.document.close()}else{alert('No Images!')}

try this code, thanks! @ssborbis

ssborbis commented 2 months ago

It's failing because of CORS. A workaround would be to open the new tab to the current location, then wipe the old HTML before writing the new HTML


outText='';
for (i=0;i<document.images.length;i++){
    if (outText.indexOf(document.images[i].src)==-1) {
        outText+='<tr><td><img style=max-width:800px src='+document.images[i].src+'></td><td>'+document.images[i].naturalWidth+'x'+document.images[i].naturalHeight+'</td></tr><p>';
    }
}
if (outText != '') {
    imgWindow=window.open(window.location.href,'imgWin');
        imgWindow.document.innerHTML = null;
    imgWindow.document.write('<table style=margin:auto border=1 cellpadding=10><tr><th>Image</th><th>Size</th></tr><p>'+outText+'</table><p>');imgWindow.document.close();
} else{
    alert('No Images!');
}
runningcheese commented 2 months ago

thanks for your info, but try this extension:https://addons.mozilla.org/en-US/firefox/addon/bookmarklets-context-menu it works well, any alternative solution? @ssborbis

ssborbis commented 2 months ago

I have a possible workaround going into the master branch if you want to test. You'll need to enable the advanced setting scriptsUseBlobs : true

runningcheese commented 2 months ago

hi @ssborbis, I just downloaded the master branch file you mentioned, and reload it from browser, and i am sure the advanced setting scriptsUseBlobs : true is on, but the test didn't go through on chrome.

in the end, when will this new feature be pushed to the new version?

ssborbis commented 2 months ago

It appears that the test code you provided is working in chromium without the need for the additional setting. I get the same results whether the setting is enabled or not.

Firefox, however, required the new setting enabled to avoid CORS issues. Are you testing using the code you provided to test with, or some other bookmarklet code?

ssborbis commented 2 months ago

If you'd been testing with scripts that contain searchTerms, they would have been failing. Try the latest code in the master branch

runningcheese commented 2 months ago

@ssborbis Unfortunately, The new version still not working. I tested it with the simplest code javascript:alert('hi'); I have to select text before I can run it, what i hope for is that running it from the context menu.

ssborbis commented 2 months ago

Ok, I think the failure was due to needing to select text first. The latest push has a fix for that.

(edit) I only tested using the contextual layout option. Let me know what your context menu settings are.

runningcheese commented 2 months ago

@ssborbis Finally! It works now. That's exactly what I hope for. When will the new version to be released? I can't wait any longer!

runningcheese commented 2 months ago

@ssborbis A big thanks for your update!!! In the latest version, chrome and edge are working fine, but in firefox, some bookmarklets will only display a new tab, and the function cannot be executed. try this code, doesn't work in firefox:

javascript:outText='';for(i=0;i<document.images.length;i++){if(outText.indexOf(document.images[i].src)==-1){outText+='<tr><td><img style=max-width:800px src='+document.images[i].src+'></td><td>'+document.images[i].naturalWidth+'x'+document.images[i].naturalHeight+'</td></tr><p>'}};if(outText!=''){imgWindow=window.open('','imgWin');imgWindow.document.write('<table style=margin:auto border=1 cellpadding=10><tr><th>Image</th><th>Size</th></tr><p>'+outText+'</table><p>');imgWindow.document.close()}else{alert('No Images!')}

runningcheese commented 2 months ago

Update: After set "scriptsUseBlobs": true, everything works fine now!