Jump to content

_Define()


AzKay
 Share

Recommended Posts

I was bored, So I made this. Enjoy.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Definition", 202, 242, 193, 115)
$Input1 = GUICtrlCreateInput("", 8, 8, 185, 21)
$Button1 = GUICtrlCreateButton("Define", 8, 32, 185, 17, 0)
$ListView1 = GUICtrlCreateEdit("", 8, 56, 185, 177, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$WS_HSCROLL,$WS_VSCROLL,$ES_READONLY))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetData($ListView1, "")
            $oRet = _Define(GUICtrlRead($Input1))
            If Not @error Then
                For $i = 1 To $oRet[0]
                    GUICtrlSetData($ListView1, $oRet[$i] & @CRLF, 1)
                Next
            Else
                GUICtrlSetData($ListView1, "No definition available" & @CRLF, 1)
            EndIf
    EndSwitch
WEnd

Func _Define($oWord)
    Local $oWordx, $oHTTP, $oWords
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("GET", "http://www.google.com/search?hl=en&q=define:" & $oWord, False)
    $oHTTP.Send()
    $oWords = StringRegExp($oHTTP.ResponseText, "<font size=-1><li>(.*?)<br>", 3)
    For $i = 0 To UBound($oWords) -1
        If $oWords[$i] <> "Web Images Groups News Froogle Local more» Advanced Search Preferences Language Tools AdvertisingPrograms - About Google ©2005 Google." Then
            $oWordx = $oWordx & $oWords[$i] & "#"
        EndIf
    Next
    $oWordx = StringTrimRight($oWordx, 1)
    $oWordx = StringReplace($oWordx, "'", "'")
    $oWordx = StringReplace($oWordx, "&amp;", "&")
    $oWordx = StringReplace($oWordx, "<li>", "")
    $oWordx = StringReplace($oWordx, "&quot;", '"')
    $oWordx = StringReplace($oWordx, "&gt;", ">")
    $oWordx = StringReplace($oWordx, "&lt;", "<")
    $oWordx = StringReplace($oWordx, "&ndash;", "-")
    $oWordx = StringReplace($oWordx, "&" & "#39;", "'")
    If $oWordx <> "" Then
        $oWordx = StringSplit($oWordx, "#")
        Return $oWordx
    Else
        SetError(1)
        Return -1
    EndIf
EndFunc

FEEDBACK PL0x.

Oh, And feel free to add in more special characters.

EDIT::

Better example added.

Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

That has an example;

#include <Array.au3>

$oWord = "Google"
$oWord = _Define($oWord)
_ArrayDisplay($oWord)
Neat!

Here's one you missed

$oWordx = StringReplace($oWordx, "'", "'");inverted comma

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Added x3

I think the browser is converting the characters so you don't see the code in the post, so this is what needs to be in the code

$oWordx = StringReplace($oWordx, "&" & "#39;", "'");

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I think the browser is converting the characters so you don't see the code in the post, so this is what needs to be in the code

$oWordx = StringReplace($oWordx, "&" & "#39;", "'");

Ah, Makes sense. x3
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

  • 1 month later...

This part was extremely useful for me:

Local $oWordx, $oHTTP, $oWords
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("GET", "http://www.google.com/search?hl=en&q=define:" & $oWord, False)
    $oHTTP.Send()
    $oWords = StringRegExp($oHTTP.ResponseText, "<font size=-1><li>(.*?)<br>", 3)

I use it all the time, it's awesome.

Besides that, I made a script a while ago that would give you the definition of a word when the user highlights it and presses a key combination using your script. Unfortunately, I had a problem with my hd and lost everything (thank jebus some of my 'important' scripts were here) but you can figure out how it worked :)

-edit-

Look: http://www.autoitscript.com/forum/index.php?showtopic=51987

Edited by Nahuel
Link to comment
Share on other sites

This part was extremely useful for me:

Local $oWordx, $oHTTP, $oWords
    $oHTTP = ObjCreate("Microsoft.XMLHTTP")
    $oHTTP.Open("GET", "http://www.google.com/search?hl=en&q=define:" & $oWord, False)
    $oHTTP.Send()
    $oWords = StringRegExp($oHTTP.ResponseText, "<font size=-1><li>(.*?)<br>", 3)

I use it all the time, it's awesome.

Besides that, I made a script a while ago that would give you the definition of a word when the user highlights it and presses a key combination using your script. Unfortunately, I had a problem with my hd and lost everything (thank jebus some of my 'important' scripts were here) but you can figure out how it worked :)

-edit-

Look: http://www.autoitscript.com/forum/index.php?showtopic=51987

Very nice :3
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...