Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Opera Search fixer


  • Please log in to reply
36 replies to this topic
Zippo
  • Members
  • 56 posts
  • Last active: Jan 24 2009 05:18 AM
  • Joined: 21 Apr 2006
Edit: Entirely reworked. Read below for details.


I love the Opera web browser, but it does have a couple of quirks.

One is searching from the address bar. I run Opera with as few panels showing as I can get away with so that I have more screen for the pages. So I use the address bar to search by typing the g, a space and the search string. That takes me to Google with the search already done.

But every now and then I forget to add the g and space. At this point, Opera takes my nicely formatted search string, removes all the spaces (so I can't just copy & paste :roll: ) and sends me to an error page.

It doesn't take very long for that to get old.

So a little script to fix that. Hope someone else finds it useful :)

#SingleInstance, Ignore 

Gosub, MenuTray 

SetTitleMatchMode, 3 
SetTimer, FilterSpaces, 300 ;Use timers to make it easier to use multiple filters at one time 
SetTimer, FilterSpaces, Off 
SetTimer, FilterPeriods, 300 
SetTimer, FilterPeriods, Off 
SetTimer, FilterIllegals, 300 
SetTimer, FilterIllegals, Off 
SendMode, Play ;Set all Sends to act like SendPlay 
Hotkey, IfWinActive, ahk_class OpWindow ;Set hotkey to work only when Opera is active 
Hotkey, $Enter, WeFix 
Hotkey, IfWinActive, ahk_class OpWindow ;Set hotkey to work only when Opera is active (Yes, for every hotkey) 
Hotkey, $NumPadEnter, WeFix 
Fixed := 0 ;This will keep track of what threads have finished so the clean-up routine will know when it is safe to restore clipboard, etc... 
Return 




;--- *** Main Program *** --- 

WeFix: 
WinGetActiveTitle, CurrentTitle 
if CurrentTitle = Compose message - Opera ;Filter out the Opera 'Compose E-mail' page 
  { 
    Send, {Enter} 
    Gosub, MenuSuspend 
    WinWaitNotActive, Compose message - Opera 
    Gosub, MenuSuspend 
    CurrentTitle := 
    Return 
  } 


if CurrentTitle = Blank page - Opera 
  { 
    ClipSaved := ClipboardAll ;Back-up the Clipboard 
    Clipboard := ;and empty it 
    Send, {LCtrl Down}a{LCtrl Up}{LCtrl Down}c{LCtrl Up}{Enter}{Tab} ;Copy to Clipboard what was entered into the address bar (if anything) 
  } 
Else  
  { 
    ControlGetFocus, ControlCheck, A ;Need to filter so that the Enter key doesn't disrupt normal browser activities 
      if ControlCheck = OperaWindowClass1 ;Most normal Opera controls are of this class... 
        { 
          Send, {Enter} 
          Return 
        } 
  } 


if CurrentTitle != Blank page - Opera 
  { 
    ClipSaved := ClipboardAll ;Back-up the Clipboard 
    Clipboard := ;and empty it 
    Send, {Enter}{LCtrl Down}l{LCtrl Up}{LCtrl Down}c{LCtrl Up} ;Copy to Clipboard what was entered into the address bar (if anything) 

  if Clipboard = 
    { 
      Fixed := 3 
      Gosub, CleanUp 
      Return 
    }
  Else
    {
      Send, {F9}
    }
  } 

Address = %Clipboard% ;Copy what was in address bar into a Var to work on 

StringLower, AddressCaseLower, Address ;Convert it to lower-case, just to be on the safe side 
StringMid, GotG, AddressCaseLower, 1, 2 ;Check if user included the g at the beginning... 
if GotG = g%A_Space% 
  { 
    Fixed := 3 
    Gosub, CleanUp ;the g was there, nothing we need to do 
    Return 
  } 




ifInString, Address, %A_Space% ;A URL shouldn't contain spaces... Opera will try to fix it 
  { 
    if FilterSpace = 1 ;User elected to not have Opera fix it... go directly to Google 
      { 
        Goto, FixIt 
        Return 
      
      } 
    Else 
      { 
        SpacesTimer := A_TickCount 
        SetTimer, FilterSpaces, On 
      } 
  } 
      
Else 
  { 
    Fixed++ 
  } 



ifNotInString, Address, . ;URLs always contain at least 1 period... 
  { 
    PeriodsTimer := A_TickCount 
    SetTimer, FilterPeriods, On 
  } 
Else 
  { 
    Fixed++ 
  } 




if FilterIllegal = 1 ;Characters like '!' and '\' aren't allowed in URLs 
  { 
    IllegalsTimer := A_TickCount 
    SetTimer, FilterIllegals, On 
  } 
Else 
  { 
    Fixed++ 
  } 


Gosub, CleanUp 
Return 




;--- If user elected to wait for error if URL contains spaces, timer will run this routine 

FilterSpaces: 
WinGetActiveTitle, NewTitle 
TimeRunning := A_TickCount-PeriodsTimer 

if TimeRunning > 5000 
  { 
    SetTimer, FilterSpaces, Off 
    Fixed++ ;We timed out 
    Gosub, CleanUp 
    Return 
  } 


If NewTitle = Error - Opera 
  { 
    SetTimer, FilterIllegals, Off 
    SetTimer, FilterSpaces, Off 
    SetTimer, FilterPeriods, Off 
    Goto, FixIt 
  } 
NewTitle := 
Return 





;--- This will run regardless, looking for URLs without periods... 

FilterPeriods: 
WinGetActiveTitle, NewTitle 
TimeRunning := A_TickCount-PeriodsTimer 

if TimeRunning > 5000 
  { 
    SetTimer, FilterPeriods, Off 
    Fixed++ ;We timed out 
    Gosub, CleanUp 
    Return 
  } 


If NewTitle = Error - Opera 
  { 
    SetTimer, FilterIllegals, Off 
    SetTimer, FilterSpaces, Off 
    SetTimer, FilterPeriods, Off 
    Goto, FixIt 
  } 
NewTitle := 
Return 




;--- If user elected to filter Illegal characters, timer will run this routine 

FilterIllegals: 
WinGetActiveTitle, NewTitle 
TimeRunning := A_TickCount-IllegalsTimer 

if TimeRunning > 5000 
  { 
    SetTimer, FilterIllegals, Off 
    Fixed++ ;We timed out 
    Gosub, CleanUp 
    Return 
  } 


If NewTitle = Illegal URL - Opera 
  { 
    SetTimer, FilterIllegals, Off 
    SetTimer, FilterSpaces, Off 
    SetTimer, FilterPeriods, Off 
    Goto, FixIt 
  } 
NewTitle := 
Return 




;----------------- 

FixIt: 
Thread, Priority, 1 ;Set the thread priority higher than the timed threads to prevent interruptions (just in case) 
Send, {LCtrl Down}l{LCtrl Up}{Backspace}g%A_Space% 

SendRaw, %Address% ;Use SendRaw so %Address% is sent exactly as it was typed 

Send, {Enter}{F9} 
Fixed := 3 
Gosub, CleanUp 
Thread, Priority, 0 
Return 

;----------------- 





CleanUp: ;Resore the Clipboard and clean up 
if Fixed < 3 ;Wait for all timed routines to finish. If the URL needed fixed, this will be 3 regardless 
  { 
    Return 
  } 
Thread, Priority, 1 ;Set the thread priority higher than the timed threads to prevent interruptions (just in case) 
Clipboard := ClipSaved 
ClipSaved := 
ControlCheck := 
AddressCaseLower := 
Address := 
ControlCheck := 
CurrentTitle := 
NewTitle := 
Fixed := 0 
TimeRunning := 
IllegalsTimer := 
PeriodsTimer := 
SpacesTimer := 
Thread, Priority, 0 
Return 


;--- *** /Main Program *** --- 




;--- Tray Menu setup 

MenuTray: 

IniRead, FilterSpace, OSF.ini, Filters, FilterSpace 
if FilterSpace = Error 
  { 
    NoIni := 1 
    FilterSpace := 0 ;If set to 1, all space will be automatically filtered (sent to Google) 
  } 
IniRead, FilterIllegal, OSF.ini, Filters, FilterIllegal 
if FilterIllegal = Error 
  { 
    NoIni := 1 
    FilterIllegal := 1 ;If set to 0, the Illegal URL page will not trigger a Google search 
  } 

Menu, Tray, NoStandard 
Menu, SpaceSubmenu, add, &All, MenuFilterSpace 
Menu, SpaceSubmenu, add, &Wait, MenuFilterSpace 
if FilterSpace = 1 
  { 
    Menu, SpaceSubmenu, Check, &All 
  } 
Else 
  { 
    Menu, SpaceSubmenu, Check, &Wait 
  } 
Menu, tray, add, Filter &Spaces, :SpaceSubmenu 

Menu, IllegalSubmenu, add, &On, MenuFilterIllegal 
Menu, IllegalSubmenu, add, O&ff, MenuFilterIllegal 
if FilterIllegal = 1 
  { 
    Menu, IllegalSubmenu, Check, &On 
  } 
Else 
  { 
    Menu, IllegalSubmenu, Check, O&ff 
  } 
Menu, tray, add, Filter &Illegal URLs, :IllegalSubmenu 

Menu, Tray, Add 
Menu, Tray, Add, S&uspend Hokeys, MenuSuspend 
Menu, Tray, Add, E&xit, MenuExit 
Return 



MenuFilterSpace: 
if A_ThisMenuItem = &Wait 
  { 
    Menu, SpaceSubmenu, UnCheck, &All 
    Menu, SpaceSubmenu, Check, &Wait 
    FilterSpace := 0 
  } 
Else 
  { 
    Menu, SpaceSubmenu, Check, &All 
    Menu, SpaceSubmenu, UnCheck, &Wait 
    FilterSpace := 1 
  } 

if NoIni != 1 
  { 
    IniWrite, %FilterSpace%, OSF.ini, Filters, FilterSpace 
  } 
Return 


MenuFilterIllegal: 
if A_ThisMenuItem = O&ff 
  { 
    Menu, IllegalSubmenu, Check, O&ff 
    Menu, IllegalSubmenu, UnCheck, &On 
    FilterIllegal := 0 
  } 
Else 
  { 
    Menu, IllegalSubmenu, UnCheck, O&ff 
    Menu, IllegalSubmenu, Check, &On 
    FilterIllegal := 1 
  } 

if NoIni != 1 
  { 
    IniWrite, %FilterIllegal%, OSF.ini, Filters, FilterIllegal 
  } 
Return 


MenuSuspend: 
if IsSuspended = 1 
  { 
    IsSuspended := 0 
    Suspend, Off 
    Menu, Tray, ToggleCheck, S&uspend Hokeys 
  } 
Else 
  { 
    IsSuspended := 1 
    Suspend, On 
    Menu, Tray, ToggleCheck, S&uspend Hokeys 
  } 
Return 

MenuExit: 
ExitApp


Since most of the major problems seem to be worked out, I've re-written the script.

In this version, you can change how it handles spaces and illegal characters through the Tray menu. It keeps track of the changes via an .ini file, but will run fine without it (just will not save your settings). The compiled version below will not work without the .ini file and will create one.

It has been changed to use timers to filter for error pages so that it can check for different errors at (nearly) the same time. This will also make it easier to modifiy if needed.

The settings are simple: By default, if you enter any spaces in the URL as you are typing it into the address bar and press the Enter key, Opera will attempt to correct them and find the page. If you set the Filter Spaces option to All in this script, any URLs you enter that contain spaces will be sent to a Google search automatically. If set to Wait, the script will wait up to 5 seconds for Opera to display an error page... if that happens within 5 seconds, the search goes to Google, and if not the script times out and lets Opera handle it.

The Filter Illegal URLs option has two settings: On and Off. Pretty easy to figure out that one :D

For those that like compiled scripts, you can get the compiled version here (there is no password and the script can be decompiled using Exe2Ahk). If you just want the default .ini file for it, grab that here (place it in the same folder as the script).

I Love Bugs! Please post them :D

Have fun!
____________________

  • Guests
  • Last active:
  • Joined: --
Cool! This has always bothered me.

Tried it and it works nicely. Good job!

  • Guests
  • Last active:
  • Joined: --
Correction: it's working then it stops working. I'll play it some more to put my finger on the problem.

  • Guests
  • Last active:
  • Joined: --
Also, it interferes with normal usage. E.g. no pages are open and I open the mailtree panel and press enter on one of the folder. Instead of opening a folder the Go to Page dialog pops up, so more work needs to be done on the part which ensures enter is overridden only if the address bar is focused.

Zippo
  • Members
  • 56 posts
  • Last active: Jan 24 2009 05:18 AM
  • Joined: 21 Apr 2006

...Also, it interferes with normal usage


Edit: I see what you are saying (I don't use Opera's Mail feature, so I was confused). I see what I can do about that :)
____________________

Zippo
  • Members
  • 56 posts
  • Last active: Jan 24 2009 05:18 AM
  • Joined: 21 Apr 2006
Original script has been edited.

Thanks for the feedback :)
____________________

  • Guests
  • Last active:
  • Joined: --
Had to modify the script, because here the class of addressbar is OperaWindowClass2 most of the time, and sometimes OperaWindowClass1.

It's puzzling, but it's working now with my changes.

BTW, I use Opera Version 8.5, Build 7700 on Win2k.

  • Guests
  • Last active:
  • Joined: --
I checked the window class with adding an outputdebug command to the script and watching the actual window class in debugview.

  • Guests
  • Last active:
  • Joined: --
One possible improvement (which could be optional): if I type "linux kernel" into the address bar then http://www.linuxkernel.com/ is loaded.

I never use this feature to go to a certain site, so the script could also monitor whether google is actually loaded and if not (error page or matching domain) then it would redirect the search to google.

Zippo
  • Members
  • 56 posts
  • Last active: Jan 24 2009 05:18 AM
  • Joined: 21 Apr 2006
I've found the problem. Thanks a million for pointing me in the right direction :)

Seems I overlooked something I should have caught right away (I'm good at that :oops: ).

If you have the 'Start Bar' toolbar checked (Tools>Appearance>Toolbars>Start Bar), the address bar will be class 3. Otherwise, class 2.

The address bar changes classes at least twice... once when you set the cursor in it, and again as soon as you hit Enter (here it goes one class lower, so if it is class 3, hitting Enter makes it class 2). That's why you sometimes return class 1. The script cacthes the Enter key and compares the class before it can change.

I'll change the script again to include OperaWindowClass2 as a possible address bar class. I can't find any reason not to... even with every available panel and toolbar enabled, the address bar still shows as class 3 wtih the 'Start Bar' enabled, and class 2 without it.

One possible improvement (which could be optional): if I type "linux kernel" into the address bar then http://www.linuxkernel.com/ is loaded.


I plan to make a simple GUI and .INI file for the script that will let you customize what/how it filters (illegal characters and such), but I needed an idea of how well it worked on other OS and with different skins/settings before I put any more into it. If anyone else wants to do it before I get around to it, feel free :)

For now, you can change this part of the code:
ifInString, Address, %A_Space% ;A URL shouldn't contain spaces... Opera will try to fix it 
  { 
    WinWaitActive, Error - Opera,, 5 ;Wait up to 5 seconds to see if we get the Opera Error page 
      if ErrorLevel = 0 
        { 
          SendPlay, {LCtrl Down}l{LCtrl Up}{Backspace}g %Address%{Enter} ;We did, so fix it and send it to Google 
          Gosub, RestoreClip 
          Return 
        } 
    Gosub, RestoreClip ;Opera found the page 
    Return 
  }

To:
ifInString, Address, %A_Space%
  {
     SendPlay, {LCtrl Down}l{LCtrl Up}{Backspace}g %Address%{Enter} 
     Gosub, RestoreClip 
     Return 
  }

... and it will send you to Google if the URL has any spaces in it.

Thanks again for the help :)

Edit: Original script updated
____________________

  • Guests
  • Last active:
  • Joined: --
Now, I get only class1 and class4, so the script still doesn't work.

This is really confusing. I haven't change anything in my Opera config since yesterday.

Posted Image

urlwolf
  • Members
  • 150 posts
  • Last active: Feb 26 2012 07:56 PM
  • Joined: 16 Mar 2006
THis is a very nice idea. The script doesn't seem to work for me, but I haven't tried really hard. What's it supposed to do? if you type -not g- word1 word2, is it supposed to add a g and then go to google directly?

Zippo
  • Members
  • 56 posts
  • Last active: Jan 24 2009 05:18 AM
  • Joined: 21 Apr 2006

Now, I get only class1 and class4, so the script still doesn't work.

This is really confusing. I haven't change anything in my Opera config since yesterday.


Very Many Thanks for the screenshot and all the debugging :)

After fighting with the class changes a few more hours, I finaly did what I should have did from the start :D

A big hold-up for me was that I wanted to make sure I didn't capture any information the user might enter on a web site (username/passwords and such). That lead to fighting with the address bar classes and all that. But stupid me already had the keyboard shortcut to copy only what was is in the address bar (Ctrl+L...Ctrl+C) :oops:

At any rate, it should be fixed now for any Opera set-up on any system (provided you haven't changed the Ctrl+L shortcut).

THis is a very nice idea. The script doesn't seem to work for me, but I haven't tried really hard. What's it supposed to do? if you type -not g- word1 word2, is it supposed to add a g and then go to google directly?


Yes, that is exactly what it is supposed to do :) Please let me know if you try it and have any problems... I'll fight with it more.

I'm planning on adding a few filter setups (space/illegal URL chars etc...) depending on how well it works for people with different setups/systems. Again, please post any problems you find.

Thanks :)

Edit: Original Script Updated
____________________

  • Guests
  • Last active:
  • Joined: --
It's working perfectly. I'll let you know if there is a problem.

Thanks for the hard work fixing it.

  • Guests
  • Last active:
  • Joined: --
There are still issues with opera mail. Start writing a new mail (ctrl+e), the cursor is in the To: field, press Enter, the Go to Page dialog appears.

The same thing happens if you tab into the message body field after ctrl+e and press enter there.