Command Chain Recipes
-
@luetage any errors in the console? Does it work when you execute it through the console?
-
@pafflick
No, nothing in the console.edit: figured it out, the copied text just doesn’t show up in the clipboard history program but is still being copied.
-
I see many recipes that work on either current URL or selected text - I'm wondering if it's possible to use the context menu for images, to work on the URL of the image? Does anyone know if that's possible, or do I have to open the image in a new tab first and then work on the tab URL?
-
@tuexss There is no command to open image in new tab as part of a command chain. And if there was one, you would need to select the image first. You also can’t work on the image URL in the context menu. What is it you try to achieve exactly? You could always write a bookmarklet as part of the command chain to get the URL of the image and either process it directly or open in a new tab to work from there. But yeah, no idea what you’re trying to do.
-
@luetage I'm trying to search for an image in three reverse image search engines in parallel. Currently I have an item in the context menu "Search for image" in google search, but other search engines I have to open manually, and it's an annoying mindless task. So I thought command chains would be perfect for that.
-
@tuexss And the engines search when you feed them the image url? That should be doable. E.g.:
- hover image
- trigger command chain
- first command is a bookmark which triggers javascript code to get the image url for the image under the cursor
- copy the url
- paste url either in address field or by creating a temporary fake input field
- select the url
- then three commands to search with selection, the image reverse engines have to be part of your search engine list
The only tricky thing is writing the bookmarklet, but it’s not too bad.
-
@luetage ah ok, so bookmarklets are the trick to get this. didn't think of that, nice.
-
@tuexss Well, tell me whether you need help with this down the line.
-
@luetage hmm, it always opens "chrome-extension://mpognobbkildjkofajifpdfhcoklimli/" which seems to be the url of the context menu, and not of the image or the webpage I'm on.
so here's what I done so far:
- created a new command chain
- added a trigger for the command chain to the image context menu
- cobbled this together to start testing with one search provider:
javascript:$("img").mouseover(function(e){window.open("https://www.google.com/searchbyimage?&image_url="+$('<a/>').attr('href',e.target.src)[0].href);});
- created a bookmark for this script
I'm a bit confused about whether mouseover is the right way to retrieve, or if I have some context based on the origin of the trigger.
Also I'm confused which action to select in the command chain: Open Link in New Tab? I can't open a bookmark it seems. Tried adding the javascript as a paramter to Open Link, but then it opens the chrome-extension URL with the javascript attached to it.
-
@tuexss You have to »open link in current tab« for the bookmarklet to run on the current page. And mouseover is the right approach in my opinion, but you might have to create a loop to search the image source in the parent/child nodes. The bookmarklet itself shouldn’t open the tab, or you won’t be able to search 3 different engines at the same time.
-
@luetage ok, that works fine with current tab. but
.mouseover
triggers on any img that I move mouse over after activating the context menu item..click
requires another click on the image. I'm wondering what the DOM state is at the time when I open the context menu and if I can use that to identify the img. Because otherwise I could just go with a bookmarklet to do the whole job. -
@tuexss I wouldn’t do it with a context menu, because when the chain triggers you won’t be over the image, but over the menu. Trigger it from quick commands, or create a dedicated keyboard shortcut.
And yes, you have to stop execution of the function after finding the source. I’ll take a look at this later, this shouldn’t be too hard.
-
@luetage I see why key command makes more sense, but I have no luck triggering the command chain via key commands, nothing happens.
-
@tuexss Try this:
Reverse Image Search
- Open Link in Current Tab
Parameter:javascript:(()=>{function i(e){if(e.target.tagName==="IMG"){document.removeEventListener("mousemove",i);let u=e.target.getAttribute("src");if(u){const a=document.createElement("a");if(u.startsWith("..")){u=window.location.origin+u.slice(2)}a.innerText=u;console.info(`reverse image search ${ u }`);a.style.opacity="0";a.style.fontSize="0em";document.body.appendChild(a);const r=document.createRange();r.selectNodeContents(a);window.getSelection().addRange(r)}}}window.getSelection().removeAllRanges();document.addEventListener("mousemove",i);setTimeout(()=>document.removeEventListener("mousemove",i),1900);history.replaceState({},"",location.href)})();
- Delay
Parameter:2000
- Search Selection with Engine
Parameter:select engine
- Delay
Parameter:500
- Previous Tab (Recent)
- Search Selection with Engine
Parameter:select engine
- Delay
Parameter:500
- Previous Tab (Recent)
- Search Selection with Engine
Parameter:select engine
The javascript listens for mouse movement. This means you can use this from context menu, if you want (shortcut or qc might still be more comfortable). During a span of 2 seconds you will have to move the mouse inside or over an image tag, which has to contain a
src
attribute with a link to the image. Should this be successful, your image will be searched in the engines of your choice. In case no src is found the javascript aborts, but the command chain will still continue, so there might be some jumping around because of the »previous tab« commands. - Open Link in Current Tab
-
@luetage Thanks, that works. Small questions: Is it possible to open Search Selection with Engine in Background tab instead? Or can I use Open Link in Background Tab and manually combine the search engine url with current selection?
-
@tuexss No, opening »search selection with engine« in a background tab isn’t possible. I’ve already inquired about this feature and it’s not likely to be implemented. »Open link in background tab« requires you to hardcode a link. Since the link is the variable, this is not possible. Likewise doing everything in the bookmarklet isn’t possible, since
window.open
opens in a new tab.I just made a new version of the bookmarklet, which can handle certain internal links, where the
src
attribute starts with 2 dots (e.g.../path/to/image
) omitting the base uri. There are likely other edge cases, the goal should be to make it work wherever the original »search for image« context menu entry is working too. -
@luetage awesome, thanks for all your help. I learned a lot about command chains.
-
@luetage said in Command Chain Recipes:
No, opening »search selection with engine« in a background tab isn’t possible.
Actually, it is possible with "Search Selection with Engine...", but it has to be enabled in Settings > Search:
Page Selection Search in BackgroundHaven't tested it with this particular command chain that you've created, but it respected the setting when I tested it in another chain.
-
@pafflick That’s a good find. But I have 3 other chains which search with selection and they are supposed to open in a new tab (active). So that’s no general solution.
-
@luetage Yes, that's a global setting - affecting all searches of selected text, but I thought I should mention that there's at least this option.