Jump to content

AutoIt Forum CodeGrabber - New(er)!


Spiff59
 Share

Recommended Posts

Broken!!! The internal HTML of forum pages has changed considerably with the new version of IP Board installed July 8th. Since this script relies upon that HTML, it is presently not working.

An application for easing the two-way transfer, testing, and maintenance of AutoIt code between these forums and ScITE.

This is my first thread in this forum, and my first script ever involving Internet Explorer. The tough part (for me, so far,) was: ensuring it pulled the source from the correct IE tab when there may be multiple instances of IE (each possibly with multiple tabs), and, getting it to skip over code snippets that may be scrolled off-screen and only grab the first one that is actually in view.

Installation:

* Compile the script

* Place the script into it's own work directory where you will also store forum code snippets

* A "program options" dialog will display the first time you execute the program. An icon to launch the program will also be placed into the quicklaunch bar.

(You may need to enable, or adjust the width of, your quick-launch bar in order for the icon to be visible)

Basic operation:

* If the current or last IE window accessed is an Autoit Forum "read", a "capture" prompt allows you to grab the first code example you're viewing on-screen, name it logically, and then launch it in ScITE.

* If the current or last IE window accessed is an Autoit Forum "reply" or "edit", a "paste" prompt lets you select the correct source from your work directory, pre-formats it with appropriate code/codebox/autoit tags, and automatically pastes it into your forum reply.

* If there is no open Autoit Forum IE window, the script launches a "maintenance" window. An icon also exists in both the "capture" and "paste" dialogs allowing you to launch the "maintenance" window.

* From the "maintenance" window you can jump directly to previously accessed online Forum topics, or, you can browse, edit and delete topics and code snippets from your work folder. There is also a "program options" windows for setting basic program variables.

Note:

* The first line of a code snippet must be visible on-screen for that block to be eligible for the capture function.

I thought this might be a time-saver for those who enjoy trying out forum code, or answering forum questions (as I do, when I'm able). I had found it tedious trying to:

* accurately rubberband code examples

* perform manual cuts and pastes

* manually switch between, or launch, IE and ScITE windows

* manually create, name, and keep track of, temporary or test .au3 files

* remember where to find topics of interest or code I'd previoisly viewed online

The script does not remain running after called. It perfoms it's short task and terminates.

I do hope for some help, comments, criticisms, suggestions.

Tested on Windows XP Pro SP3 with IE7 and IE8. Attachment below...

Version 0.50 - 2009-04-17 - Working version

Version 0.51 - 2009-04-18 - Added topic sub-title to inserted comment. Added basic shell.application.windows() error test.

Version 0.52 - 2009-04-18 - Fixed paste bug! Added "OPEN" option to "File exists" capture prompt

Version 0.53 - 2009-04-18 - Fixed undeclared variable error. Fixed ShellWindows error. Added "Fast Reply" functionality.

Version 0.54 - 2009-04-20 - Added test to handle custom or "branded" Internet Explorer titles

Version 0.55 - 2009-04-21 - Added: work folder maintenance routine, "edit post" functionality, scite launch toggle, and more.

(V 0.55 changes the script's file naming convention, all saves from previous versions should be manually deleted)

Version 0.56 - 2009-04-21 - Handle code blocks in signature. Adjust auto-size listview spacing. Handle IE-closed exception.

Version 0.57 - 2009-04-22 - Handle dupe Wintitles. Add "OPEN" to paste dialog. Correct focus issue introduced in v 0.56.

Version 0.58 - 2009-04-23 - Added options dialog (with .ini file). Correct bug regarding folder creation when topic title ends in a period.

Version 0.59 - 2009-04-24 - Correct subscript crash after deleting last topic via file maintenance window.

Version 0.60 - 2009-04-26 - Retain topic number after "Preview Post" clicked.

Version 0.61 - 2009-04-26 - Enable launching forum topics from File Maintenance window. Some cleanup.

Version 0.62 - 2009-04-27 - (RC1?) If necessary, place cursor in textarea (at end of text) prior to paste.

Version 0.63 - 2009-04-28 - Added 2 more special characters to StringregExpReplace to prevent folder creation errors.

Version 0.64 - 2009-05-13 - Was sometimes truncating first byte during paste.

Version 0.65 - 2009-06-18 - Added ability to browse and edit all offline topics and files. Adjusted window positon to account for taskbar height. Other misc. changes.

Version 0.66 - 2009-06-19 - A few forum posts are returning "style=" in front of "class=" in the code/autoit div. This caused the on-screen highlighting to partially fail. Corrected.

Version 0.67 - 2009-06-22 - Fixed timing issue with javascript. Completed the delete function at file level. Fixed expanding codebox display bug introduced in v0.66.

Version 0.68 - 2009-06-22 - Crap! Fixed new v0.67 looping bug when launching IE forum topic.

Version 0.69 - 2009-06-23 - Bypass "Fast Reply" logic if user not logged in.

Version 0.70 - 2009-06-30 - Increase zero-padding of post number to maintain listview sort order when cutting from threads with over 100 posts. Minor correction to temporary comment insertion logic.

Just a code snippet I use for testing this script. Ignore me! (or test grabbing this code block yourself!)

Speak("I am talking, like Stephen Haaking.") ; it sounds better misspelled!
Func Speak($Text)
    Local $o_speech = ObjCreate("SAPI.SpVoice")
    With $o_speech 
        .Rate=1.1
        .Volume=100
        .Speak ($Text)
    EndWith
EndFunc
(A couple hundred downloads have been erased since I'm always changing this thing...)

CodeGrabber.au3

Edited by Spiff59
Link to comment
Share on other sites

  • 2 weeks later...

There's not a lot of resemblance between the attachment above and the one I'd posted in this thread initially.

This is the first script in a year here that I thought was original enough, and possibly useful enough, to park in this forum.

Another random code snippet I'm using for testing (ignore).

$filesize = 2048204812
$filesize_str = _BytesConvert($filesize)
MsgBox(0,"",$filesize_str)
Exit
;------------------------------------------------------------------------------
Func _BytesConvert($bytes)
    Local $x, $bytes_suffix[5] = ["B","KB","MB","GB","TB"] 
    For $x = 0 to 5
        If $bytes > 1023 Then
            $bytes /= 1024
        Else
            ExitLoop
        EndIf
    Next
    $Bytes = Int($Bytes * 100) / 100
    Return Round($bytes, 2) & $bytes_suffix[$x]
EndFunc
Edited by Spiff59
Link to comment
Share on other sites

...

Another random code snippet I'm using for testing (ignore).

$filesize = 2048204812
$filesize_str = _BytesConvert($filesize)
MsgBox(0,"",$filesize_str)
Exit
;------------------------------------------------------------------------------
Func _BytesConvert($bytes)
    Local $x, $bytes_suffix[5] = ["B","KB","MB","GB","TB"] 
    For $x = 0 to 5
        If $bytes > 1023 Then
            $bytes /= 1024
        Else
            ExitLoop
        EndIf
    Next
;   Return StringFormat("%.2f", $bytes) & $bytes_suffix[$x]
    Return Round($bytes, 2) & $bytes_suffix[$x]
EndFunc
What if
$filesize =  1024 * 1024 -1

Shouldn't 0.99 MB be returned?

Regarding other stuff... I'm not hanging much, but I did run the code and got few errors of type Variable used without being declared.

Link to comment
Share on other sites

Great script!

I have compiled it and it works beautifully.

Two little things i noticed (but i can live with them)

1. You can't automatically paste in a "Fast Reply" (it still looks for a 'code' section)

2. If i do a "Add Reply" i have to activate the cursor in the reply text box before a paste will happen

Link to comment
Share on other sites

Regarding other stuff... I'm not hanging much, but I did run the code and got few errors of type Variable used without being declared.

Since that sort of error would have jumped out at me the first time I ran the script, I'd have to assume you compiled it with the 'MustDeclareVars' option enabled?

Edit: I looked into it further, and did find an abend occured due to two undeclared variables. This happened only when the script was run when there were no exisitng occurances of Internet Explorer. Will post that fix with the others. Thank you.

Great script!

I have compiled it and it works beautifully.

Two little things i noticed (but i can live with them)

1. You can't automatically paste in a "Fast Reply" (it still looks for a 'code' section)

2. If i do a "Add Reply" i have to activate the cursor in the reply text box before a paste will happen

Thanks for testing the thing, famaes!

An extra set of eyes does wonders. Implementing your "#1" brought up a more consistant way of detecting all 3 "reply" types. So, I'll have that worked into the script soon. Giving the inputbox focus, with the cursor at the end of any exisitng text ought to be cake too, I just don't now how yet. Thank you for your input.

Edit: Pasting to "Fast Reply" in addition to "Reply" and "Add Reply" is tougher than I thought. I dumped the source HTML for the page prior to, and after, opening the fast reply inputbox. The HTML is identical. I'm guessing the javascript that controls the fast reply box is storing a varaiable on the server that indicates the status of the box, open or hidden. Maybe there's a way to query that JS variable?

I've fixed the only known bugs (so far) in V 0.53 above.

Edit: Shellwindow.document.getElementById('qr_open').style.display did the trick for testing the status of the Fast reply window. Version 0.53 above should now go into 'paste' mode for a Fast Reply. I still need to figure the easy way to park the cursor at the end of the text in the inputbox, in case you haven't already manually brought the inptbox into focus.

Edited by Spiff59
Link to comment
Share on other sites

If I run this (chopped out of your script):

$o_IE = ObjCreate("InterNetExplorer.Application")
$IE_Name = String($o_IE.name); Get browser name
ConsoleWrite($IE_Name & @CRLF)
$o_IE.quit

$Window = WinList()
For $x = 1 to $Window[0][0]
    ConsoleWrite($Window[$x][0] & @CRLF)
Next

I get this:

Windows Internet Explorer
...
AutoIt Forums -> Replying in AutoIt Forum CodeGrabber - New! - Microsoft Internet Explorer
...

So obviously it will never work for me in current shape.

Link to comment
Share on other sites

I get this:

Windows Internet Explorer
...
AutoIt Forums -> Replying in AutoIt Forum CodeGrabber - New! - Microsoft Internet Explorer
...
I found this on Microsoft How to Change the Internet Explorer Window Title

which indicates there is a registry entry (HKCU\Software\Microsoft\Internet Explorer\Main\Window Title) that, if it exists, it's value will override the default value.

I could add a RegRead to the script and handle that. What troubles me is that the article states this registry key applies to Internet Explorer only through version 6. So I'm looking to see if there is another key somewhere that would apply to IE versions 7 or 8.

Are you running v6 or earlier?

I could also simply split the string at the space before the last "-" character to get a string that would match those returned by the ShellWindows() collection, but I'm not sure how well that would hold up in practice.

Edited by Spiff59
Link to comment
Share on other sites

I plugged in a registy value for that key and it did override the title even in IE 7.

I have no idea how any of those COM or DOM objects behave in other browsers.

I did just update the script to use the custom window title for matching, if one exists.

Edit: Big changes in v 0.55. An edit function for maintaining the work folder is the biggest addition (click the icon)..

Edited by Spiff59
Link to comment
Share on other sites

Great script!

I have compiled it and it works beautifully.

Two little things i noticed (but i can live with them)

2. If i do a "Add Reply" i have to activate the cursor in the reply text box before a paste will happen

I got around to figuring out how to park the cursor in the textarea (only if it's not already there).

I've also changed the way the script behaves, so that launching it when there are no IE (or AutoIt forum) windows gives you an opportunity to go into the "File Maintenance" mode. I think I've beat on this enough to pretty much call it version 1.00, although I'm considering a file browse dialog here and there to add a little more flexibility.

I do find this a great timesaver when I'm bopping around the forums trying out code, or occasionally trying to fix code.

Try it out now, if you don't like it, just delete the work folder you put the executable in, and the icon it adds to the quicklaunch bar. Comments, criticisms greatly appreciated.

Link to comment
Share on other sites

I tested the script, but it gives an error when run. (compiled and not)

Here it is :

E:\AutoIt3Forum\codekeep\CodeGrabber.au3 (88) : ==> Object referenced outside a "With" statement.:

If String($o_IE.getElementById('qr_open').style.display) = "0" Then $Mode = 4

If String($o_IE.getElementById('qr_open')^ ERROR

Link to comment
Share on other sites

I tested the script, but it gives an error when run. (compiled and not)

Here it is :

E:\AutoIt3Forum\codekeep\CodeGrabber.au3 (88) : ==> Object referenced outside a "With" statement.:

If String($o_IE.getElementById('qr_open').style.display) = "0" Then $Mode = 4

If String($o_IE.getElementById('qr_open')^ ERROR

You could add this to line 87 of the script and post what you get for Spiff59 to see:

Local $oElementById = $o_IE.getElementById('qr_open')
            If IsObj($oElementById) Then
                Local $oElementByIdStyle = $oElementById.style
                If IsObj($oElementByIdStyle) Then
                    Local $sDisplayProperty = $oElementByIdStyle.display
                    ConsoleWrite("> Display property: " & $sDisplayProperty & @CRLF)
                Else
                    ConsoleWrite("! Retrieving style failed" & @CRLF)
                EndIf
            Else
                ConsoleWrite("! getElementById failed" & @CRLF)
            EndIf
ConsoleWrite("--------------------------------" & @CRLF & @CRLF)
Link to comment
Share on other sites

I tested the script, but it gives an error when run. (compiled and not)

Here it is :

E:\AutoIt3Forum\codekeep\CodeGrabber.au3 (88) : ==> Object referenced outside a "With" statement.:

If String($o_IE.getElementById('qr_open').style.display) = "0" Then $Mode = 4

If String($o_IE.getElementById('qr_open')^ ERROR

I can't seem to recreate your error. I assume it happens during a "Fast Reply"?

Trancexx's suggestion at trapping the error could provide more info.

What browser version are you running?

Link to comment
Share on other sites

I can't seem to recreate your error. I assume it happens during a "Fast Reply"?

Trancexx's suggestion at trapping the error could provide more info.

What browser version are you running?

Well after reinstalling my virtual machine i can't reproduce the error any more.

It seems to work now.

Don't know what happened before.

Sorry for the inconvenience.

Thank you for the effort any way.

Link to comment
Share on other sites

  • 1 month later...

If the windows taskbar is not the default size then it covers your message boxes.

Ah, that's one I hadn't considered!

I ought to be able to determine the bottom of the window and subtract that from the bottom of the screen so that I can offset my popup window accordingly. Thanks.

Edit:

Ok, I've changed it in ver .65 to auto-adjust the placement of the popup windows to account for the height of the taskbar. So, they shouldn't end up behind anything and inaccessable. I also put in the beginnings of the ability to edit and delete at the file level, rather than just the topic level, A few other small changes were made as well.

Edited by Spiff59
Link to comment
Share on other sites

Well after reinstalling my virtual machine i can't reproduce the error any more.

It seems to work now.

Don't know what happened before.

Sorry for the inconvenience.

Thank you for the effort any way.

I have the same problem with IE8 :

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Franck\AutoIt_Code\CodeGrabber.au3"

! getElementById failed

--------------------------------

C:\Franck\AutoIt_Code\CodeGrabber.au3 (115) : ==> Object referenced outside a "With" statement.:

If String($o_IE.getElementById('qr_open').style.display) = "0" Then $Mode = 4

If String($o_IE.getElementById('qr_open')^ ERROR

->08:40:36 AutoIT3.exe ended.rc:1

Link to comment
Share on other sites

I have the same problem with IE8 :

>Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Franck\AutoIt_Code\CodeGrabber.au3"

! getElementById failed

--------------------------------

C:\Franck\AutoIt_Code\CodeGrabber.au3 (115) : ==> Object referenced outside a "With" statement.:

If String($o_IE.getElementById('qr_open').style.display) = "0" Then $Mode = 4

If String($o_IE.getElementById('qr_open')^ ERROR

->08:40:36 AutoIT3.exe ended.rc:1

I've been unable to recreate that error that Famaes encountered at one time, and that afterward you experienced. Until now.

I had a download running in the background that was choking my internet, and at the same time was playing around in the forums. I tried grabbing some code off a post and I got the same error. It appears if the webpage is loaded sufficiently to be recognized as an Autoit Forum page, but hasn't loaded enough to be able to check the status of the "Fast Reply" javascript (qr_open), then you get the error. That issue should be corrected in ver 0.67. I also completed the edit-by-file functions, and fixed a bug I'd just introduced in the last version that caused a scrollable codebox to expand on-screen when highlighted. I'm about out of ideas to do to the script, maybe I'll do a cleanup on it internally and call it v1.00 pretty soon.

Edit: Duh! Just found a second method of creating this error. I'm rarely here when I'm not logged in, so I never noticed that when you're logged out, there is no "Fast Reply" button, and no "Fast Reply" script. It is difficult to read a value from a script that doesn't exist :D Version 0.69 bypasses the "Fast Reply" logic if you're not logged-in.

Edited by Spiff59
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...