Jump to content

Recommended Posts

Posted (edited)

I work with JavaScript, SQL, CSS very often.
When I use these technologies in AutoIt, there is often a need to improve such code.
 

For example, for JavaScript used inside AutoIt, you first need to turn the JavaScript code embedded in AutoIt into pure JavaScript code.
Which is not always simple.

For example try to manually ...

  Reveal hidden contents

Today I was determined to simplify this task for myself.

Here is the result:

;~ https://www.autoitscript.com/forum/topic/209665-descripterforstringau3/
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>

#cs
                "var myelement = arguments[0];" & @CRLF & _
                "return GetPropertyValue(myelement);" & @CR & _ ; some comment
                "" & @LF & _
                "function GetPropertyValue(element) {" & _
                "   var search = '" & $sCSSProperty & "';" & _
                "   var propertyname = '';" & _
                "   for (let i = 0; i < element.style.length; i++) {" & _
                "      propertyname = element.style.item(i);" & _
                "      if (propertyname == search) {return element.style.getPropertyValue(propertyname);}" & _
                "   }" & _
                "   return '';" & _
                "}"

            "           td, th {                                                        " & @CRLF & _
            "               padding: 5px !important;                                    " & @CRLF & _
            "               margin: 5px !important;                                     " & @CRLF & _
            "           }                                                               " & @CRLF & _
            "                                                                           " & @CRLF & _
            "           .page-content {margin: 0px !important;}                         " & @CRLF & _
            "                                                                           " & @CRLF & _
            "           iframe {height: 1300px  !important;}                            " & @CRLF & _
            "                                                                           " & @CRLF & _
            "           * {                                                             " & @CRLF & _
            "               line-height: 1 !important;                                  " & @CRLF & _
            "               margin: 0px !important;                                     " & @CRLF & _
            "               background-color: white !important;                         " & @CRLF & _
            "               font-family: 'Times New Roman', Times, serif !important;    " & @CRLF & _
            "               font-size: 10px !important;                                 " & @CRLF & _
            "               font-weight: normal !important;                             " & @CRLF & _
            "           }                                                               " & @CRLF & _
            "                                                                           " & @CRLF & _
            "           tbody.ui-table-tbody span {                                     " & @CRLF & _
            "               line-height: 20px !important;                               " & @CRLF & _
            "           }                                                               " & @CRLF & _
            "                                                                           " & @CRLF & _
            "           div.kafelekPodmiotu p-panel div,                                " & @CRLF & _
            "           div.ui-panel-0,                                                 " & @CRLF & _
            "           .ui-tabview-panels {                                            " & @CRLF & _
            "               padding: 4px !important;                                    " & @CRLF & _
            "               margin-top: 2px !important;                                 " & @CRLF & _
            "           }                                                               " & @CRLF & _
            "                                                                           " & @CRLF & _
            "           div.ui-tabview-panels app-show-more-info-box div.container,     " & @CRLF & _
            "           div.ui-tabview-panels p-messages div.ng-star-inserted,          " & @CRLF & _
            "           div.header-info,                                                " & @CRLF & _
            "           app-header,                                                     " & @CRLF & _
            "           div.sidebar-wrapper,                                            " & @CRLF & _
            "           div.sidebar-menu,                                               " & @CRLF & _
            "           section.ng-scope,                                               " & @CRLF & _
            "           div.page-viewbar,                                               " & @CRLF & _
            "           div.page-container > app-sidebar,                               " & @CRLF & _
            "           div.buttons,                                                    " & @CRLF & _
            "           app-footer,                                                     " & @CRLF & _
            "           i[ng-class='::item.icon'],                                      " & @CRLF & _
            "           td.actions-col i,                                               " & @CRLF & _
            "           p-messages div.ui-messages-warn span.ui-messages-icon,          " & @CRLF & _
            "           div.footer-inner {                                              " & @CRLF & _
            "               display: none;                                              " & @CRLF & _
            "           }                                                               " & @CRLF & _
            "                                                                           " & @CRLF & _
            "           #ui-panel-0,                                                    " & @CRLF & _
            "           #ui-panel-0 #ui-panel-0-content,                                " & @CRLF & _
            "           #ui-panel-0-content div.ui-panel-content,                       " & @CRLF & _
            "           #ui-panel-0-content div.ui-panel-content p-table {              " & @CRLF & _
            "               margin: 0px !important;                                     " & @CRLF & _
            "           }                                                               " & @CRLF & _
            "                                                                           " & @CRLF & _
            ""


            "SELECT" & @CRLF & _
            "   [testing_error]" & @CRLF & _
            "FROM" & @CRLF & _
            "   [database].dbo.[sprawy]" & @CRLF & _
            ""
#ce

_Main()
Func _Main()
    Local $s_Data = FileRead(@ScriptFullPath)
    $s_Data = StringRegExpReplace($s_Data, '(?is)(.+#CS.?\R)(.*?)(#CE.+)', '$2')
    ClipPut($s_Data)
    MsgBox(0, @ScriptLineNumber & ' BEFORE', $s_Data)
    deSripterForString(Default)
    MsgBox(0, @ScriptLineNumber & ' AFTER', ClipGet())
EndFunc   ;==>_Main

Func deSripterForString($s_Data = Default)
    Local $b_UseClipBoard = ($s_Data = Default)
    If $b_UseClipBoard Then $s_Data = ClipGet()

    #Region - ; check if first character is ' or "
    Local $s_Temp = StringRegExpReplace($s_Data, '[\s\R]','')
    Local Const $s_LeadingQuotationMark = StringLeft($s_Temp, 1)
    If Not StringRegExp($s_LeadingQuotationMark, '["'']', $STR_REGEXPMATCH) Then
        If $b_UseClipBoard Then Return SetError(@error, @extended, ClipPut(''))
        Return SetError(@error, @extended, '')
    EndIf
    #EndRegion - ; check if first character is ' or "

    $s_Data = @CRLF & $s_Data & @CRLF ; additional NEW LINE at start and end to make RegExpPattern easier
    Local $s_Pattern_Temp = StringReplace('(\R)(\s*?)(\")', '"', $s_LeadingQuotationMark)
    $s_Data = StringRegExpReplace($s_Data, $s_Pattern_Temp, '$1') ; strip leading quotes and spaces

    ; using $s_LeadingQuotationMark as quotation mark in next RegExpPattern
    Local $s_Pattern = StringReplace('(?i)([\"\s&_]*?(\s*?(@CRLF|@CR|@LF)[\"\s&_]*?|\s*?@CRLF[\"\s&_]*?|))(;\V+|)(\R)', '"', $s_LeadingQuotationMark)
    $s_Data = StringRegExpReplace($s_Data, $s_Pattern, '$5')

    $s_Data = StringStripWS($s_Data, $STR_STRIPTRAILING)

    If $b_UseClipBoard Then
        ClipPut($s_Data)
    Else
        Return $s_Data
    EndIf
EndFunc   ;==>deSripterForString


Have fun.
But if you found any issues ... please let me know.

 

EDIT:
2023/03/03 - new version
* added support for comment on the end of line
* better $s_LeadingQuotationMark handling
* striping WS $STR_STRIPTRAILING

EDIT:
2023/03/03 - new version
* better removal of leading whitespace

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Nice, I just started getting into SQLite with AutoIt, so I'll be checking this out some more soon. Any plans to make the reverse, or does that exist somewhere? Something to take an input like you deScripted examples or:

CREATE TRIGGER testing_modifiedDate
         AFTER UPDATE OF meowName
            ON testing
          WHEN new.meowName <> old.meowName
BEGIN
    UPDATE testing
       SET modifiedDate = datetime() 
     WHERE meowId = new.meowId;
END;

Into

"CREATE TRIGGER testing_modifiedDate" & @CRLF & _
"         AFTER UPDATE OF meowName" & @CRLF & _
"            ON testing" & @CRLF & _
"          WHEN new.meowName <> old.meowName" & @CRLF & _
"BEGIN" & @CRLF & _
"    UPDATE testing" & @CRLF & _
"       SET modifiedDate = datetime() " & @CRLF & _
"     WHERE meowId = new.meowId;" & @CRLF & _
"END;"

 

We ought not to misbehave, but we should look as though we could.

Posted

On this forum there is already script which you ask for.

It was made by me and then translated to lua by @Jos.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Found .

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 2/11/2023 at 11:12 PM, mistersquirrle said:

Nice, I just started getting into SQLite with AutoIt, so I'll be checking this out some more soon. Any plans to make the reverse, or does that exist somewhere? Something to take an input like you deScripted examples or:

CREATE TRIGGER testing_modifiedDate
         AFTER UPDATE OF meowName
            ON testing
          WHEN new.meowName <> old.meowName
BEGIN
    UPDATE testing
       SET modifiedDate = datetime() 
     WHERE meowId = new.meowId;
END;

Into

"CREATE TRIGGER testing_modifiedDate" & @CRLF & _
"         AFTER UPDATE OF meowName" & @CRLF & _
"            ON testing" & @CRLF & _
"          WHEN new.meowName <> old.meowName" & @CRLF & _
"BEGIN" & @CRLF & _
"    UPDATE testing" & @CRLF & _
"       SET modifiedDate = datetime() " & @CRLF & _
"     WHERE meowId = new.meowId;" & @CRLF & _
"END;"

 

Expand  

one more way:
in this post (https://www.autoitscript.com/forum/topic/204362-microsoft-edge-webview2-embed-web-code-in-your-native-application/?do=findComment&comment=1474817) there is also a small snippet, which I wrote some time ago, which does what you ask in a very simple way.
In short: copy the script you want to "embed" to clipboard, and then run that snippet of code. This "transforms" the listing that is on the clipboard into a function that returns that listing as-is in a string. The generated function is in turn placed on the clipboard.
now you can paste that function from the clipboard into your listing.
Hope it can be of use.

Edited by Gianni

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Posted

2023/03/03 - new version - in Opening Post
* added support for comment on the end of line
* better $s_LeadingQuotationMark handling
* striping WS $STR_STRIPTRAILING

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

2023/03/03 - new version
* better removal of leading whitespace

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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