Would like alternative bookmarklet to search site.
-
Have used this Google based bookmarklet to search a specific site and have managed (with the help of a Donation Coder Forum member) to use another (such as Presearch for example) instead. It works fine on all other browsers (Edge, Firefox, Slimjet, Opera...) except for Vivaldi.
Any other options?
javascript:q=%22%22+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt(%22Search%20terms%20[leave%20selection%20and%20box%20blank%20to%20list%20all%20pages]%20...%22).replace(/\s\+/g,%22%252B%22);if(q!=null)location=%22http://www.google.com/search?q=%22+q.replace(/\s+/g,%22+%22)+%22+site:%22+location.hostname;void(0);
-
@danielson I can confirm it does work in Opera but not in Vivaldi. No clue as to why though. Feel free to report a bug but I wouldn't get my hopes up it will be fixed quickly, I don't think their priorities are on making bookmarklets work perfectly.
My JS skills are not good enough to figure out another way to do what you want here.
-
@danielson Bookmarklet works for me. Make sure to open it in the same tab. You are also posting on the wrong forum board, this belongs in help and support, itβs not a Vivaldi UI modification.
-
@luetage It works for you? That's weird... I tried different variants, replacing the
%22
with"
and so on. -
@pathduck Yes, starts a google search with selection.
- Copy bookmarklet
- Select something
- Paste bookmarklet in address field and open in same tab.
-
@luetage Hmmm.... it works for me if I remove the regex replace part
EDIT: It does work if I just paste it into the URLbar. But as a bookmarklet, Vivaldi stupidly replaces
\
with/
so the regex fails:replace(//s+/g,%22+%22)
-
@pathduck lol, good find
Might be worth a bugreport. -
@luetage Yeah, I guess... Bookmarklets in Vivaldi has always been kind of buggy. They should improve it, some people (me included) still rely on some of them, although mine are a lot simpler than this one.
There's a lot of URL encoding in this, making it really hard to figure out. It should be reduced to the bare minimum to work first. It probably doesn't even need that regex...
Bookmarklets should always be posted as code blocks to avoid wrapping causing even more
%20
's in the code.Bare minimum with regex (won't work as bookmarklet):
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search%20terms").replace(/\s\+/g,"+");if(q!=null)location="http://www.google.com/search?q="+q.replace(/\s\+/g,"+")+"+site:"+location.hostname;
Without regex, should work except for edge cases like strings containing
+
where you want the plus to actually be in the search query:javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search%20terms");if(q!=null)location="http://www.google.com/search?q="+q+"+site:"+location.hostname;
Doesn't really need the
void(0)
at the end, maybe it's there for weird JS compatibility reasons?And I really have no idea why it needs that
""
at the start, do you @luetage ? -
@pathduck Itβs funny youβd think I could code. What gave you that impression? Iβm just faking it.
Lets say itβs an empty string to warm up the code, raising body temperature and increasing blood flow.
-
@luetage Oh, I thought you were one of those JavaScript
NinjasMonkeys -
@pathduck Donβt you dare animal shaming me, you
-
@luetage We can still be fwends
Bug reported as
VB-80551
-
@pathduck -finally!
It's not just in my head!
-
@luetage - not sure why this should be posted elsewhere since it is after all a "tweak" of sorts isn't it?
- not sure i understand your tip about opening tab...
-
Oh and I figured out what the
""
at the start is good for, after a lot of head-scratching. It's a "hack" to force the value ofq
to a string, as apparentlygetSelection()
returns a bloody Object. Thansk for being your weird old self, JavaScript...https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection
So the same could be accomplished by simply:
q=window.getSelection().toString();
-
@pathduck said in Would like alternative bookmarklet to search site.:
q=window.getSelection().toString();
Can you lay out the full JS now "Master"?!
Please!!
-
@danielson Yeah this is the basic working bookmarklet code without all the (IMO) unnecessary URL-encoding and without the regex that breaks in Vivaldi:
javascript:q=window.getSelection().toString();if(!q)q=prompt("Search%20terms");if(q!=null)location="https://www.google.com/search?q="+q+"+site:"+location.hostname;
I find when it comes to bookmarklets, following the KISS principle is essential.
-
@pathduck - you're the dude man!!
Just tried it with Presearch and it works flabergastingly well!
Thanks a bunch!
Will post at DonationCoder Forum - you might want to visit there if ever looking for a job...
-
@danielson Glad to hear that. It's a useful little bookmarklet, might even keep it around now that I understand what it does
I did find the thread on the DonationCoder forum, the other user said it worked for them in V 2.9 - but that's because the regex replace bug wasn't there then. It seems to have been introduced later, maybe in 3.0.
But it should work just fine without the replace function anyway
Hopefully V team will fix the bug as well. -
Well, at least it can be of use to you!
Have been using the Google based one for years now. Discovered it once upon a time, on a site called Fark.
Just nice to be able to use something now, that doesn't have Alphabet's nose involved. At least, i like to think it's not...