legege / searchboxsync

Update the search bar automatically from wherever you search
4 stars 2 forks source link

Create simple Sync Rule from existing Search Engine entry #10

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It would be great if this add-on could get the URL directly from the Search
Engine entry and create a new simple rule based off that.

It would be even better if these rules could optionally be created/removed
automatically any time a new Search Engine is added/deleted.  

There may need to be a persistent and direct association between Search
Engines and Sync Rules for this to work.  Issue #6 is another reason such
an association might need to exist.

Original issue reported on code.google.com by MALfunct...@gmail.com on 12 Dec 2008 at 9:03

GoogleCodeExporter commented 9 years ago
The sync rules should be automatically generated based on the search engine 
plugins.

Or, maybe it would be the best, that we need no sync rules. Anytime a search 
matching
the existing search engines is submitted, the keyword is put into the searchbox.

Original comment by ith...@sohu.com on 1 Apr 2009 at 7:26

GoogleCodeExporter commented 9 years ago
Yeah, that's the idea behind this plugin.  The question is how.  Sync Rules or 
no
Sync Rules?

How about both?  Perhaps it ought to be able to handle requests that exactly 
match a
registered Search Engine URL based on the existing Search Engines (without 
using Sync
Rules at all).  Then if there is no match, it could fall back to using 
user-defined
Sync Rules.

Original comment by MALfunct...@gmail.com on 1 Apr 2009 at 8:28

GoogleCodeExporter commented 9 years ago
I have nearly finished a userChrome.js script to do synchronization for all 
submits
matching the installed search engines. It seems working well. 

Original comment by ith...@sohu.com on 3 Apr 2009 at 10:37

GoogleCodeExporter commented 9 years ago
Have you considered providing a patch to add this functionality in SearchBox 
Sync?

Original comment by legege on 3 Apr 2009 at 10:50

GoogleCodeExporter commented 9 years ago

Original comment by legege on 3 Apr 2009 at 10:51

GoogleCodeExporter commented 9 years ago
That will be OK after I finish testing. My script supports both GET and POST 
type
search engine, and all charsets(defined in the search engine). It perfectly 
satisfies
my own requests, including issue 11. :)

Original comment by ith...@sohu.com on 3 Apr 2009 at 11:04

GoogleCodeExporter commented 9 years ago
Hello legege, 

I have finished my script. You can integrate it into your extension if it is 
needed.
Its features:
1. No sync rules needed. All searches matching installed search engines will be
synced to search bar, including both currentEngine and searchTerms.
2. support for all charsets.
3. support for POST type search.
4. Synchronization only happens when submitting a search, not when switching 
tabs.

Original comment by ith...@sohu.com on 3 Apr 2009 at 2:51

Attachments:

GoogleCodeExporter commented 9 years ago
ith, your script sounds very promising, but I can't get it to work.  I 
installed it
as a Greasemonkey script, but it doesn't appear to have any effect.  I even 
tried
changing the "include" to *, but that didn't work either.  Using Firefox 3.0.8.

Original comment by MALfunct...@gmail.com on 3 Apr 2009 at 3:18

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Sorry MALfunction84, it is not a GM script, but a userChrome.js script. And it 
still
has some bug for POST type search.

Original comment by ith...@sohu.com on 3 Apr 2009 at 3:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago

Original comment by ith...@sohu.com on 3 Apr 2009 at 3:59

Attachments:

GoogleCodeExporter commented 9 years ago
Ah, I misunderstood.  It's working great now!  There were two situations where 
I had
to re-create my search engines to get it to work, but both situations appear to
involve HTTP redirects.

In the first, the search engine was requesting on http, but it was being 
redirected
to https.  It didn't work until I changed my search engine to use https by 
default.

In the second, I was using a Google CSE.  CSE's URLs are not very consistent, 
and the
old ones redirect to the new ones, so I had to remove the search engine and 
re-create
it with https://addons.mozilla.org/en-US/firefox/addon/3682 to get it to work 
with
this script correctly.

Is there any way to account for redirects?

Original comment by MALfunct...@gmail.com on 3 Apr 2009 at 5:57

GoogleCodeExporter commented 9 years ago
Probably, the redirection only happens when you search from the searchbar and 
not
from the search engine web form. Thus no redirection could be detected in my 
script
when you search from the web form. So just adjust the installed search engines 
to
correct parameters. OSE 1.5RC1 can help you much in adjusting the search engine
properties. See
http://maltekraus.de/blog/firefox/organize-search-engines/organize-search-engine
s-15-release-candidate-1-116.html

Original comment by ith...@sohu.com on 4 Apr 2009 at 6:35

GoogleCodeExporter commented 9 years ago
I understand why it wouldn't work if I had done the search from a web form: the
requested URL obviously wouldn't match that of any registered engine.  (I've 
used OSE
before, but I kept running into an issue where the search engine dropdown would
occasionally blank out until I restarted Firefox.  I couldn't track down why it
happened.)

Actually, I was using keyword-based search from the address bar when it was
redirecting.  Sorry, that was one detail I left out.  My understanding is that
keyword search invokes the corresponding searchbar search, but I can't figure 
out why
that would not trigger your script to change the active search engine.  Is 
there any
way to make it work for redirected keyword searches from the address bar?

Original comment by MALfunct...@gmail.com on 5 Apr 2009 at 3:35

GoogleCodeExporter commented 9 years ago
Copy your search engine plugin here, I may do a test with it.

Original comment by ith...@sohu.com on 5 Apr 2009 at 5:45

GoogleCodeExporter commented 9 years ago
Search Bar works: Yes (redirects)
Syncs from Web Form Search: No
Syncs from Address Bar Keyword Search: No

<SearchPlugin xmlns="http://www.mozilla.org/2006/browser/search/"
xmlns:os="http://a9.com/-/spec/opensearch/1.1/">
<os:ShortName>Java APIs</os:ShortName>
<os:InputEncoding>UTF-8</os:InputEncoding>
<os:Image width="16"
height="16">data:image/x-icon;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAEBAQEBAQE
BAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wB
DAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE
BAQEBAQH/wAARCAAQABADAREAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAgYICv/EAB8QAAMAAwE
AAgMAAAAAAAAAAAQFBgIDBwEACBIUFf/EABkBAAIDAQAAAAAAAAAAAAAAAAQHAgMFBv/EACIRAAMBAQA
CAgIDAQAAAAAAAAIDBAEFEhMGEQAVBxQhQv/aAAwDAQACEQMRAD8A3Y9aviOZQDyzDmzq49dsTArZ8An
WB+8zonyybW5smm3UTrSTwJ7cdhTv8gz/AOBOCtHPi5jkD4EQB07d50L6xQdJK8MBIb46ZtYCg8j3N9a
hI8JzfEvWrDPwLx8d6T4j8fX8o+QQ8V3TRx0Uja+noULJ/ol50FXSpGaUDWV3ReiNk/K5+On/AGHSbJF
tM2P961D60XLrp3EoPoj49cyMt1mypwIW5bfNWod6YQy1q9oO7VgQkIQ5E7EOc6ZvYM0GKzBQ5ZnuBDy
MxuDW6/kyWPMDOkCf9r37zMYZF69zc+16nd1PqLSNXr8GGTBPfza/k7gw/F/nHf8AjnPnpmTw6h5RLqw
fM2QpXNtYPAtC5fQxY9Aeilc8vQ/tbZFLPE6deTD939nWmB8iFy/mvWvXk35qcJerxZXjKUJ0vvWSex5
0+m5k93aC79i0ZO5woS+fmKvyyGWLnOGJFCN8afxAOX6rP2V/J1FXkijk2j66fpWLZLel9YT89gew3oK
XOkDdHzY2ffqYvxV9IqcNOzLpFqSFqqkFuCJeW+QbiiJ4GPiDRZiv8LB8DzfP8P6uc5oGb/m9nZT/AFO
Xd8qhK9BtKfzayOTVz6/cAmOdRu8hoHa1CNAKuG8klLCDlkCszNm9OIe0BS7euh3aI4YbOXzd42yX2yu
XPE3aNgniWwU+laVHz5H0G0ytaq+qhuetIYmf2421J120jbe251YrPHU1kRMpYzwwvY1p7S4ViAikTWA
AOf8AW4Hj/9k=</os:Image>
<SearchForm>http://www.google.com/coop/cse?cx=008127576120486981591:mx3lri8eyr0<
/SearchForm>
<os:Url type="text/html" method="GET"
template="http://www.google.com/cse?cx=008127576120486981591:mx3lri8eyr0&ie=UTF-
8&sa=Search&cof=L:http://joannapenabickley.typepad.com/on/images/java_logo.gif;L
H:100;S:http://www.google.com/coop/cse?cx=008127576120486981591:mx3lri8eyr0;&q={
searchTerms}">
</os:Url>
</SearchPlugin>

-----

I thought an address bar keyword search directly invoked the URL in the search
engine.  Does your script sync against the response's URL rather than the 
request's?

Side note: CSE is weird because the web form on the main page is different from 
the
web form on the result page.  I haven't found a way to register an engine that 
syncs
with both web forms.  The search engine above syncs with neither web form 
because it
was created manually, not from the page.

Original comment by MALfunct...@gmail.com on 6 Apr 2009 at 1:10

GoogleCodeExporter commented 9 years ago
Hello MALfunction84,

There's no redirection happenning for Google custom search. In fact, if a 
redirection
happens, a new http request will be submitted and then captured by my script. 
Your
problem roots in that Google custom search has two differenct search urls. When
you're on the page
http://www.google.com/coop/cse?cx=008127576120486981591%3Amx3lri8eyr0, the 
search
will be submitted with the url
http://www.google.com/cse?cx=008127576120486981591%3Amx3lri8eyr0; while when 
you're
on the page http://www.google.com/cse?cx=008127576120486981591%3Amx3lri8eyr0,
searches will be submitted with the url
http://www.google.com/custom?cx=008127576120486981591%3Amx3lri8eyr0. I suggest 
that
you could adjust the engine url to the latter one("custom"), which may be more
frequently used. You cannot register an engine to sync with two differenct 
search
urls. You need to install two search engines instead.

Side note: How an engine is identified by my script? Only the left part of the 
first
"?" mark is compared, so if you have installed two or more google custom search
engines all with the "custom" adddrsses, the searches will be identified as all 
from
the first one.

Original comment by ith...@sohu.com on 6 Apr 2009 at 2:32

GoogleCodeExporter commented 9 years ago
I figured it was something like that.  Thanks for looking into that for me.  I 
still
don't understand why the keyword search from the address bar was not working 
for that
CSE entry, though.  Shouldn't the request URL for a keyword search match the 
search
engine's URL exactly?

Original comment by MALfunct...@gmail.com on 6 Apr 2009 at 4:01

GoogleCodeExporter commented 9 years ago
There seems something going wrong with the template url provided in your 
comment #17.
It even cannot work a search on my machine.

The reason for why a keyword search is not identified could probably be that, 
in my
script I assume there's at most one "?" mark in the template url.

Original comment by ith...@sohu.com on 6 Apr 2009 at 4:22

GoogleCodeExporter commented 9 years ago
ith,
Thanks again for this great UserScript and for helping me understand how to get 
it
working.  It's still working great, but I've noticed that it is causing an 
error on
my browser (Firefox 3.0.10):
"isElementVisible it not defined"

This is happening in the init function (line 19):
    if (isElementVisible(this._searchbar)) {

Even after changing the line to the following...
    if (isElementVisible && isElementVisible(this._searchbar)) {
...it's still generating that error.  Can you help me out one last time?

Original comment by MALfunct...@gmail.com on 21 May 2009 at 8:35

GoogleCodeExporter commented 9 years ago
The error occurs when an alert or confirm box appears.  It may come up in other
situations too.

Original comment by MALfunct...@gmail.com on 22 May 2009 at 1:45