Jump to content

making app that deletes all non-nessisary WS


Recommended Posts

long story short: List every exception that you must use a white space after any kind of HTML, PHP, JS, CSS syntax.

Long story:

This was just built on top of another program a guy wrote earlier the key thing to look into is the Clear White spaces.. button at the top.

Mainly could use that button function to clear all non-nessisary white spaces form htm docs u make.

right now its hardcoded into txt files. also make sure the directory your

File.au3 is in is correct...mine is prob differant.

What are all the exceptions where you actually need white spaces in html/java/php/etc...

Right now it clears all white spaces the problem is...not all white spaces should be cleared... like for example <img src="'> u need the space after img.

so basically after you take all white spaces out you could search for the substring img inside the file and everything u find it add a " ". that would fix that problem but i am sure there are tons more...prob dealing with DIV ..and more.

This could make a nice little script that creates 2nd copy without spaces that you could actually have "live" to save on upload usage. while keeping the real version intact.

also i messed around with the Load button i made there...nothing big. Check dirctories though make sure none of mine are in by default.

#include "FIX THIS TO YOUR DIRECTORY where File.au3 is at"
;Generated with AutoBuilder 0.3
$ES_READONLY = 0x800;
$WS_DISABLED = 0x8000000;
$WS_VSCROLL = 0x200000;
$WS_HSCROLL = 0x100000;

$style = $ES_READONLY + $WS_VSCROLL + $WS_HSCROLL
Func _clear()

ControlClick ( "Small Notes", "", "Edit1", "Left", 1)
$temp = ControlGetText ( "Small Notes", "", "Edit1" )
While $temp <> "";not sure if right syntax
Send("{BS}")
$temp = StringTrimRight($temp, 1)
Wend
EndFunc

Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)

GuiCreate("Small Notes", 480,272,10,10,0x04CF0000)
$button_1 = GUISetControl("button", "Read", 340,230, 80,20)
$button_2 = GUISetControl("button", "Save", 220,230, 80,20)
$button_3 = GUISetControl("button", "Load", 340,210, 80,20)
$button_4 = GUISetControl("button", "clearspaces", 0,0, 0,0)
$edit_1 = GUISetControl("edit", "", 30,20, 410,180)
$date_1 = GUISetControl("date", "Date 1", 20,220, 190,20)

GuiShow()

While 1
sleep(100)
$msg = GuiMsg(0)
Select
Case $msg = -3
Exit

Case $msg = $button_1
;run("notepad.exe " & @scriptdir & "\temp.txt") ;;;; !!!!! THIS IS THE OLD WAY THIS ONE LINE
;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   THE CODE THAT PRINTS TXT FILE TO BOX


$file = FileOpen("temp.txt", 0)

;Check if file opened for reading OK
If $file = -1 Then
  MsgBox(0, "Error", "Unable to open file.")
  Exit
EndIf

$chars = FileRead($file, 1000000)
ControlGetText ( "Small Notes", "", "Edit1" )
$var = String($chars)
While $var <> ""
  $result = StringLeft($var, 1)
  $var = StringTrimLeft ( $var, 1)
  Send($result)
Wend


;;
FileClose($file)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;   END OF PRINT TXT TO BOX CODE
Case $msg = $button_3

$m = InputBox("Enter File", "Type the name of the file")
$chars = FileRead(@scriptdir &  "\" & $m, 1000000)
ControlFocus ( "Small Notes", "", "Edit1" )
$var = String($chars)
While $var <> ""
  $result = StringLeft($var, 1)
  $var = StringTrimLeft ( $var, 1)
  Send($result)
Wend

Case $msg =$button_4
$m = InputBox("Enter File to delete whitespaces", "Type the name of the file")
$w = InputBox("Enter name of nowhitespace file", "Type the name of the new file")
$chars = FileRead(@scriptdir &  "\" & $m, 1000000)
$var = String($chars)
$var = StringStripWS($var, 8 ) 
$newdoc = ""
MsgBox(0,"$var = ", $var)
MsgBox(0,"$newdoc =", $newdoc)
While $var <> ""
  $result = StringLeft($var, 1)
    if $result <> " " Then
      $newdoc = $newdoc & $result
    EndIf
  $var = StringTrimLeft ( $var, 1)
Wend
$temp =@scriptdir &  "\" & $w
_FileCreate($temp)

FileWrite($temp,$newdoc)



Case $msg = $button_2
$file = FileOpen("temp.txt", 1)

; Check if file opened for writing OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
$textleetcode = ControlGetText ( "Small Notes", "", "Edit1" )

;$timehour
;if @Hour <> 00 
;$timehour = 12  

$amORpm = "AM"; am by default
if @HOUR > 12 Then
$amORpm = "PM"; pm
Endif

$Hour = ""
Select
   Case @HOUR < 13
       $Hour = @HOUR

   Case Else
    $Hour = @HOUR - 12     
   
EndSelect


$time = String ("")
$time = $time &  @MON  & "/" & @MDAY & "/" & @YEAR & " at " &  $Hour & ":" & @MIN & " " &$amORpm



FileWrite($file, "This note was made on:" & $time & @CRLF & "-----------" & @CRLF & @CRLF)


FileWrite($file, $textleetcode & @CRLF &  @CRLF & "-----------" & @CRLF & @CRLF )
FileClose($file)

_clear()
;;;
Case $msg = $edit_1
;;;
Case $msg = $date_1
;;;
EndSelect
WEnd
Exit
Link to comment
Share on other sites

Removing extra spacing from HTML docs isn't going to save you that much. The file size isn't determined by the number of lines, but by the number of characters. I don't think you'd ever save more than 1 or 2 K except on larger documents, and even that isn't very much. For the sake of argument, I'll consider that you save 50 K on white space (that's about 50,000 characters.) Over any broadband, that only saves 2 seconds on uploading. If you're using a modem, you still only save 12 seconds. And that's with 50,000 whitespace characters, which I'm guessing is way over estimating.

If it helps at all, you might look at the RemoveWS call in AutoIt for some of its features.

Grammar fix

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

well, yeah its not much but still a script that does it ...even 2 secounds save is nice. THats like gaining 2 extra secounds on your life to spending drinking beer or somthing. every page load man after a few days you have a good minute beer time. Thats one less minute you would of had...well this assumes you don't drink your beer while the page loads.

Yeah i figured i'd delete all white spaces at first then go back and add 1 space after all tags that need 1 space....

the other choice was to seach for "< " then ignore all single spaces inside until ">".

This prob would be easier to code the problem is. what if someone types like this:

<img src = "somepic.jpg" >

You lose 2 white space savers here! instead if you do 1 space after every flagged name you would get this: <img src="somepic.jpg"> .

That my frineds is the differance of THREE extra spaces ...thats insane over time if you think about it. Say over the course of a year you load a million img calls like that. thats a fuckton less white spaces over the course of a year if u don't do it the easy way.

This is just for the img tag also... tons of other tags...

So like i said where do I find a list of tags t hat NEED white space in them. I was hopeing someone knew a sweet link that would list them out.

Link to comment
Share on other sites

In responce to your question, I'm not sure such a lists exists outside of a complete list of HTML tags that you could sift through. And I think it would be very hard to find a list of all the tags there are. But good luck in your search.

Also, you probably will have spend more time scripting this than you will ever save in 2 or 3 year's worth of time. It might just be faster in the long run if you wait the extra quarter second per page.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

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...