Jump to content

Recommended Posts

Posted (edited)

My second addition for the night... and ever ;)

Not sure if this has been done... but i couldn't find it!

This script is designed to grab code from a forum you're looking at and drop it into a new SciTE tab. Currently, it is executed by a hotkey (Ctrl+"-"), and it will grab every Autoit code section that is not quoted on the page and enter them as seperate tabs in SciTE. It also will recognize a firefox window right now and do a little background work to get the code to SciTE.

I think the code may be a bit messy still (i'm still learning :whistle: ), but here are a few things I'm wondering about specifically:

1. The use of "Send" here and there? It seems that it might be a "messy" way to do things?

2. The "Select" statement. If I just use an "if" statement, it matches every single div tag. And if I put the "Case $oDiv.classname = "autoit"" line as the first case, it again matches every div tag instead of those I want... anyone know why???

Thanks for any new ideas!

#NoTrayIcon
#include <IE.au3>
Opt("WinTitleMatchMode", 4)

Global $CodeGrabberPaused
HotKeySet("#{PAUSE}", "TogglePause")
HotKeySet("#q", "Terminate")
HotKeySet("^-", "CodeGrabber")

While 1
    Sleep(100)
WEnd

Func TogglePause()
    $CodeGrabberPaused = NOT $CodeGrabberPaused
    While $CodeGrabberPaused
        sleep(100)
        ToolTip('CodeGrabber is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func CodeGrabber()
    $aSciteLocation = "C:\Program Files\AutoIt3\SciTE\scite.exe"
    $WebsiteCreated = False
    $qContinue = False
    Dim $aDivArray[10]

    $oTitle = WinGetTitle("active")
    If WinActive("classname=IEFrame") Then
        $oIE = _IEAttach("AutoIt")
        if $oIE = 0 Then
            MsgBox(0,"Error","Sorry, this window is not an AutoIt website")
        Else
            $qContinue = True
        EndIf
    ElseIf StringInStr($oTitle, "Firefox") Then
        Send("g")
        Send("^c")
        $aWebAddress = ClipGet()
        if StringInStr($aWebAddress, "autoit") Then
            $oIE = _IECreate($aWebAddress, 0, 0)
            $WebsiteCreated = True
            $qContinue = True
        Else
            MsgBox(0,"Error","Sorry, this window is not an AutoIt website")
        EndIf
    EndIf

    if $qContinue Then
        $oDivs = _IETagNameGetCollection($oIE, "div")
        $oCount = 1
        For $oDiv In $oDivs
            Select
                Case $oDiv.classname = "0"
                    ; do nothing
                Case $oDiv.classname = "autoit"
                    $aDivArray[$oCount] = $oDiv.innertext
                    $oCount = $oCount + 1
                Case Else
                    ; do nothing
            EndSelect
        Next

        If $WebsiteCreated Then
            _IEQuit($oIE)
        EndIf

        For $x = 1 to $oCount - 1
            if WinExists("classname=SciTEWindow") Then
                WinActivate("classname=SciTEWindow")
            Else
                run($aSciteLocation)
                WinActivate("classname=SciTEWindow")
            EndIf
            ClipPut($aDivArray[$x])
            WinWaitActive("classname=SciTEWindow")
            Send("^n")
            Send("^v")
        Next
    EndIf
EndFunc
Edited by fisofo
Posted

Something for you to look at.

From Scite in an au3 file press Ctrl+Alt+s

switch over to the forum highlight the code and press Ctrl+c and see what happens

Heh... let me guess, does the same thing? I tried it from IE and Firefox and it does not seem to be working... the snippet window came up the first time, and then errored and closed. Now I can't get it to open at all? I have the full SciTE installed, what could i be missing?

Well, hopefully mine will provide some value still by not having to open scite first (although who ever closes it?!?), plus it's one hotkey, not two... and there's no need to switch between apps!

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
  • Recently Browsing   0 members

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