Jump to content

Recommended Posts

Utility functions for color names and color value formats defined by the HTML and CSS specifications for use in documents on the Web.

What this UDF supports

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

This UDF supports the following methods of specifying RGB colors, and conversions between them:

  • Six-digit hexadecimal.
  • Three-digit hexadecimal.
  • Integer 3-element RGB array.
  • Percentage 3-element RGB array.
  • Varying selections of predefined color names.
WebColors.au3

#include-once
; #INDEX# =======================================================================================================================
; Title .........: WebColors
; AutoIt Version : 3.3.8++
; Language ......: English
; Description ...: Functions for converting html/css color codes. Ported from Python implementation by James Bennett, BitBucket
;                 for original code. [https://bitbucket.org/ubernostrum/webcolors/]
; Author(s) .....: Michael Mims (zorphnog)
;                 OHB <me at="" orangehairedboy="" dot="" com=""> (__WebColors_x UDF)
; ===============================================================================================================================
; #CURRENT# =====================================================================================================================
;_WebColors_HexToName
;_WebColors_HexToRGB
;_WebColors_HexToRGBPercent
;_WebColors_NameToHex
;_WebColors_NameToRGB
;_WebColors_NameToRGBPercent
;_WebColors_RGBToName
;_WebColors_RGBToHex
;_WebColors_RGBToRGBPercent
;_WebColors_RGBPercentToName
;_WebColors_RGBPercentToHex
;_WebColors_RGBPercentToRGB
; ===============================================================================================================================
; #INTERNAL_USE_ONLY# ===========================================================================================================
;__WebColors_Init
;__WebColors_InitCSS21
;__WebColors_InitCSS3
;__WebColors_InitHTML4
;__WebColors_IsValidRGB
;__WebColors_Normalize_Hex
;__WebColors_PercentToInt
;__WebColors_Reverse_Dict
;__WebColors_x
; ===============================================================================================================================
Global Const $__WC_HEX_COLOR_RE = "A#([a-fA-F0-9]{3}|[a-fA-F0-9]{6})z"
Global Const $__WC_SUPPORTED_SPECIFICATIONS[4] = ['html4', 'css2', 'css21', 'css3']
Global Const _
    $__WC_HTML4_NAMES_TO_HEX = "html4_ntoh", _
    $__WC_HTML4_HEX_TO_NAMES = "html4_hton", _
    $__WC_CSS2_NAMES_TO_HEX  = $__WC_HTML4_NAMES_TO_HEX, _
    $__WC_CSS2_HEX_TO_NAMES  = $__WC_HTML4_HEX_TO_NAMES, _
    $__WC_CSS21_NAMES_TO_HEX = "css21_ntoh", _
    $__WC_CSS21_HEX_TO_NAMES = "css21_hton", _
    $__WC_CSS3_NAMES_TO_HEX  = "css3_ntoh", _
    $__WC_CSS3_HEX_TO_NAMES  = "css3_hton"
Global $__WC_DICT_INITIALIZED = False, $__WC_xHashCollection = ObjCreate( "Scripting.Dictionary" )

; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToName
; Description ...: Convert a hexadecimal color value to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_HexToName($hex_value[, $spec = 'css3'])
; Parameters ....: $hex_value          - The hexadecimal color value.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name of the hexadecimal value
;                 Failure - Blank string, sets @error
;                 |1 - Specification not supported
;                 |2 - Hex value is not a valid hexadecimal color value
;                 |3 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToName($hex_value, $spec='css3')
    __WebColors_Init()
    Local $dict, $name, $normalized
    Switch StringLower($spec)
        Case $__WC_SUPPORTED_SPECIFICATIONS[0]
            $dict = $__WC_HTML4_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[1]
            $dict = $__WC_CSS2_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[2]
            $dict = $__WC_CSS21_HEX_TO_NAMES
        Case $__WC_SUPPORTED_SPECIFICATIONS[3]
            $dict = $__WC_CSS3_HEX_TO_NAMES
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    $normalized = __WebColors_Normalize_Hex($hex_value)
    If @error Then Return SetError(1 + @error, 0, "")  ; value is not valid hexadecimal color value
    $name = __WebColors_x($dict & "." & $normalized)
    If $name <> "" Then Return $name
    Return SetError(3, 0, "")                         ; hex_value has no defined color name
EndFunc   ;==>_WebColors_HexToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToRGB
; Description ...: Convert a hexadecimal color value to a 3-element array of RGB integers.
; Syntax ........: _WebColors_HexToRGB($hex_value)
; Parameters ....: $hex_value          - The hexadecimal color value.
; Return values .: Success - The RGB array of integer values
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToRGB($hex_value)
    Local $hex_digits, $rgb_value[3]
    $hex_digits = __WebColors_Normalize_Hex($hex_value)
    If @error Then Return SetError(@error, 0, "")     ; value is not valid hexadecimal color value
    $rgb_value[0] = Int('0x' & StringMid($hex_digits, 2, 2))
    $rgb_value[1] = Int('0x' & StringMid($hex_digits, 4, 2))
    $rgb_value[2] = Int('0x' & StringMid($hex_digits, 6, 2))
    Return $rgb_value
EndFunc   ;==>_WebColors_HexToRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_HexToRGBPercent
; Description ...: Convert a hexadecimal color value to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_HexToRGBPercent($hex_value)
; Parameters ....: $hex_value          - The hexadecimal color value.
; Return values .: Success - The RGB array of percentage values
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
;                 |2 - Internal error; RGB value array is invalid
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_HexToRGBPercent($hex_value)
    Local $rgb_value
    $rgb_value = _WebColors_HexToRGB($hex_value)
    If @error Then Return SetError(@error, 0, "")
    $rgb_percent = _WebColors_RGBToRGBPercent($rgb_value)
    If @error Then Return SetError(1 + @error, 0, "")
    Return $rgb_percent
EndFunc   ;==>_WebColors_HexToRGBPercent
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Init
; Description ...: Initializes the color dictionary.
; Syntax ........: __WebColors_Init()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Init()
    If Not $__WC_DICT_INITIALIZED Then
        __WebColors_InitHTML4()
        __WebColors_InitCSS21()
        __WebColors_InitCSS3()
        __WebColors_Reverse_Dict($__WC_HTML4_NAMES_TO_HEX, $__WC_HTML4_HEX_TO_NAMES)
        __WebColors_Reverse_Dict($__WC_CSS21_NAMES_TO_HEX, $__WC_CSS21_HEX_TO_NAMES)
        __WebColors_Reverse_Dict($__WC_CSS3_NAMES_TO_HEX, $__WC_CSS3_HEX_TO_NAMES)
        $__WC_DICT_INITIALIZED = True
    EndIf
EndFunc   ;==>__WebColors_Init
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitCSS21
; Description ...: Adds the CSS 2.1 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitCSS21()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitCSS21()
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.orange', '#ffa500')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_CSS21_NAMES_TO_HEX & '.yellow', '#ffff00')
EndFunc   ;==>__WebColors_InitCSS21
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitCSS3
; Description ...: Adds the CSS 3 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitCSS3()
; Parameters ....: None
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitCSS3()
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aliceblue', '#f0f8ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.antiquewhite', '#faebd7')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.aquamarine', '#7fffd4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.azure', '#f0ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.beige', '#f5f5dc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.bisque', '#ffe4c4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blanchedalmond', '#ffebcd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.blueviolet', '#8a2be2')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.brown', '#a52a2a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.burlywood', '#deb887')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cadetblue', '#5f9ea0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.chartreuse', '#7fff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.chocolate', '#d2691e')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.coral', '#ff7f50')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cornflowerblue', '#6495ed')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cornsilk', '#fff8dc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.crimson', '#dc143c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.cyan', '#00ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkblue', '#00008b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkcyan', '#008b8b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgoldenrod', '#b8860b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgray', '#a9a9a9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgrey', '#a9a9a9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkgreen', '#006400')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkkhaki', '#bdb76b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkmagenta', '#8b008b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkolivegreen', '#556b2f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkorange', '#ff8c00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkorchid', '#9932cc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkred', '#8b0000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darksalmon', '#e9967a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkseagreen', '#8fbc8f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslateblue', '#483d8b')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslategray', '#2f4f4f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkslategrey', '#2f4f4f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkturquoise', '#00ced1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.darkviolet', '#9400d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.deeppink', '#ff1493')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.deepskyblue', '#00bfff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dimgray', '#696969')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dimgrey', '#696969')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.dodgerblue', '#1e90ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.firebrick', '#b22222')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.floralwhite', '#fffaf0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.forestgreen', '#228b22')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gainsboro', '#dcdcdc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.ghostwhite', '#f8f8ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gold', '#ffd700')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.goldenrod', '#daa520')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.gray', '#808080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.greenyellow', '#adff2f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.honeydew', '#f0fff0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.hotpink', '#ff69b4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.indianred', '#cd5c5c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.indigo', '#4b0082')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.ivory', '#fffff0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.khaki', '#f0e68c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lavender', '#e6e6fa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lavenderblush', '#fff0f5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lawngreen', '#7cfc00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lemonchiffon', '#fffacd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightblue', '#add8e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightcoral', '#f08080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightcyan', '#e0ffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgoldenrodyellow', '#fafad2')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgray', '#d3d3d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgrey', '#d3d3d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightgreen', '#90ee90')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightpink', '#ffb6c1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightsalmon', '#ffa07a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightseagreen', '#20b2aa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightskyblue', '#87cefa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightslategray', '#778899')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightslategrey', '#778899')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightsteelblue', '#b0c4de')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lightyellow', '#ffffe0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.limegreen', '#32cd32')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.linen', '#faf0e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.magenta', '#ff00ff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumaquamarine', '#66cdaa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumblue', '#0000cd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumorchid', '#ba55d3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumpurple', '#9370d8')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumseagreen', '#3cb371')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumslateblue', '#7b68ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumspringgreen', '#00fa9a')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumturquoise', '#48d1cc')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mediumvioletred', '#c71585')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.midnightblue', '#191970')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mintcream', '#f5fffa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.mistyrose', '#ffe4e1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.moccasin', '#ffe4b5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.navajowhite', '#ffdead')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.oldlace', '#fdf5e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.olivedrab', '#6b8e23')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orange', '#ffa500')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orangered', '#ff4500')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.orchid', '#da70d6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palegoldenrod', '#eee8aa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palegreen', '#98fb98')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.paleturquoise', '#afeeee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.palevioletred', '#d87093')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.papayawhip', '#ffefd5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.peachpuff', '#ffdab9')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.peru', '#cd853f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.pink', '#ffc0cb')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.plum', '#dda0dd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.powderblue', '#b0e0e6')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.rosybrown', '#bc8f8f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.royalblue', '#4169e1')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.saddlebrown', '#8b4513')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.salmon', '#fa8072')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.sandybrown', '#f4a460')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.seagreen', '#2e8b57')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.seashell', '#fff5ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.sienna', '#a0522d')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.skyblue', '#87ceeb')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slateblue', '#6a5acd')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slategray', '#708090')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.slategrey', '#708090')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.snow', '#fffafa')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.springgreen', '#00ff7f')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.steelblue', '#4682b4')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.tan', '#d2b48c')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.thistle', '#d8bfd8')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.tomato', '#ff6347')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.turquoise', '#40e0d0')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.violet', '#ee82ee')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.wheat', '#f5deb3')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.whitesmoke', '#f5f5f5')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.yellow', '#ffff00')
    __WebColors_x($__WC_CSS3_NAMES_TO_HEX & '.yellowgreen', '#9acd32')
EndFunc   ;==>__WebColors_InitCSS3
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_InitHTML4
; Description ...: Adds the HTML 4 color specifications to the color dictionary.
; Syntax ........: __WebColors_InitHTML4()
; Parameters ....:
; Return values .: None
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_InitHTML4()
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.aqua', '#00ffff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.black', '#000000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.blue', '#0000ff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.fuchsia', '#ff00ff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.green', '#008000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.grey', '#808080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.lime', '#00ff00')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.maroon', '#800000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.navy', '#000080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.olive', '#808000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.purple', '#800080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.red', '#ff0000')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.silver', '#c0c0c0')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.teal', '#008080')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.white', '#ffffff')
    __WebColors_x($__WC_HTML4_NAMES_TO_HEX & '.yellow', '#ffff00')
EndFunc   ;==>__WebColors_InitHTML4
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_IsValidRGB
; Description ...: Determines whether a RGB array is valid.
; Syntax ........: __WebColors_IsValidRGB($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB values.
; Return values .: Success - True
;                 Failure - False, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_IsValidRGB($rgb_value)
    If Not IsArray($rgb_value) Then Return SetError(1, 0, False)
    If UBound($rgb_value) <> 3 Then Return SetError(2, 0, False)
    For $i=0 To 2
        If Number($rgb_value[$i]) > 255 Or Number($rgb_value[$i]) < 0 Then Return SetError(3, 0, False)
    Next
    Return True
EndFunc   ;==>__WebColors_IsValidRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToHex
; Description ...: Convert a color name to a normalized hexadecimal color value.
; Syntax ........: _WebColors_NameToHex($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The hex value of the color
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToHex($name, $spec='css3')
    __WebColors_Init()
    Local $dict, $hex_value
    Switch StringLower($spec)
        Case $__WC_SUPPORTED_SPECIFICATIONS[0]
            $dict = $__WC_HTML4_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[1]
            $dict = $__WC_CSS2_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[2]
            $dict = $__WC_CSS21_NAMES_TO_HEX
        Case $__WC_SUPPORTED_SPECIFICATIONS[3]
            $dict = $__WC_CSS3_NAMES_TO_HEX
        Case Else
            Return SetError(1, 0, "")
    EndSwitch
    $hex_value = __WebColors_x($dict & "." & $name)
    If $hex_value <> "" Then Return $hex_value
    Return SetError(2, 0, "")
EndFunc   ;==>_WebColors_NameToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToRGB
; Description ...: Convert a color name to a 3-element array of integers.
; Syntax ........: _WebColors_NameToRGB($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The RGB array of the integer values
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
;                 |3 - Internal error; Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToRGB($name, $spec='css3')
    __WebColors_Init()
    Local $hex_value, $rgb_value
    $hex_value = _WebColors_NameToHex($name, $spec)
    If @error Then Return SetError(@error, 0, "")
    $rgb_value = _WebColors_HexToRGB($hex_value)
    If @error Then Return SetError(2 + @error, 0, "")
    Return $rgb_value
EndFunc   ;==>_WebColors_NameToRGB
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_NameToRGBPercent
; Description ...: Convert a color name to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_NameToRGBPercent($name[, $spec = 'css3'])
; Parameters ....: $name                - Name of color to look up.
;                 $spec             - [optional] Specification list to use. Default is 'css3'.
; Return values .: Success - The RGB array of the percentage values
;                 Failure - Blank string, set @error
;                 |1 - Specification not supported
;                 |2 - Name is not defined as a named color in the specification
;                 |3 - Internal error; Hex value is not a valid hexadecimal color value
;                 |4 - Internal error; RGB value array is invalid
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_NameToRGBPercent($name, $spec='css3')
    __WebColors_Init()
    Local $rgb_value, $rgb_percent
    $rgb_value = _WebColors_NameToRGB($name, $spec)
    If @error Then Return SetError(@error, 0, "")
    $rgb_percent = _WebColors_RGBToRGBPercent($rgb_value)
    If @error Then SetError(4 + @error, 0, "")
    Return $rgb_percent
EndFunc   ;==>_WebColors_NameToRGBPercent
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Normalize_Hex
; Description ...: Normalize a hexadecimal color value to the following form and return the result: #[a-f0-9]{6}
; Syntax ........: __WebColors_Normalize_Hex($hex_value)
; Parameters ....: $hex_value          - A hexadecimal color value to normalize.
; Return values .: Success - The normalized hexadecimal color value
;                 Failure - Blank string, sets @error
;                 |1 - Hex value is not a valid hexadecimal color value
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Normalize_Hex($hex_value)
    Local $aReturn, $hex_digits
    $aReturn = StringRegExp($hex_value, $__WC_HEX_COLOR_RE, 3)
    If @error Then Return SetError(1, 0, "")
    $hex_digits = $aReturn[0]
    If StringLen($hex_digits) == 3 Then
        $hex_digits = StringMid($hex_digits, 1, 1) & StringMid($hex_digits, 1, 1) & StringMid($hex_digits, 2, 1) & _
            StringMid($hex_digits, 2, 1) & StringMid($hex_digits, 3, 1) & StringMid($hex_digits, 3, 1)
    EndIf
    Return StringFormat("#%s", StringLower($hex_digits))
EndFunc   ;==>__WebColors_Normalize_Hex
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_PercentToInt
; Description ...: Internal helper for converting a percentage value to an integer between 0 and 255 inclusive.
; Syntax ........: __WebColors_PercentToInt($percent)
; Parameters ....: $percent          - A percentage value.
; Return values .: The rounded integer value of the percentage of 255
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_PercentToInt($percent)
    Return Round(Number(StringTrimRight($percent, 1)) / 100.0 * 255)
EndFunc   ;==>__WebColors_PercentToInt

; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToName
; Description ...: Convert a 3-element array of integers to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_RGBToName($rgb_value[, $spec = 'css3'])
; Parameters ....: $rgb_value          - An array of RGB integer values.
;                 $spec             - [optional] A specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
;                 |4 - Specification not supported
;                 |5 - Internal error; Hex value is not a valid hexadecimal color value
;                 |6 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToName($rgb_value, $spec='css3')
    __WebColors_Init()
    Local $hex_value, $name
    $hex_value = _WebColors_RGBToHex($rgb_value)
    If @error Then Return SetError(@error, 0, "")
    $name = _WebColors_HexToName($hex_value, $spec)
    If @error Then Return SetError(3 + @error, 0, "")
    Return $name
EndFunc   ;==>_WebColors_RGBToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToHex
; Description ...: Convert a 3-element array of integers to a normalized hexadecimal value for that color.
; Syntax ........: _WebColors_RGBToHex($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB integer values.
; Return values .: Success - The normalized hex value
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToHex($rgb_value)
    If Not __WebColors_IsValidRGB($rgb_value) Then SetError(@error, 0, "")   ; rgb_value is invalid
    Return StringFormat("#%02x%02x%02x", Int($rgb_value[0]), Int($rgb_value[1]), Int($rgb_value[2]))
EndFunc   ;==>_WebColors_RGBToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBToRGBPercent
; Description ...:  Convert a 3-element array of RGB integers to a 3-element array of RGB percentages.
; Syntax ........: _WebColors_RGBToRGBPercent($rgb_value)
; Parameters ....: $rgb_value          - An array of RGB integer values.
; Return values .: Success - The 3-element array of RGB percentages
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBToRGBPercent($rgb_value)
    Local $rgb_percent[3]
    If Not __WebColors_IsValidRGB($rgb_value) Then SetError(@error, 0, "")   ; rgb_value is invalid
    For $i=0 To 2
        Switch Int($rgb_value[$i])
            Case 255
                $rgb_percent[$i] = "100%"
            Case 128
                $rgb_percent[$i] = "50%"
            Case 64
                $rgb_percent[$i] = "25%"
            Case 32
                $rgb_percent[$i] = "12.5%"
            Case 16
                $rgb_percent[$i] = "6.25%"
            Case 0
                $rgb_percent[$i] = "0%"
            Case Else
                $rgb_percent[$i] = StringFormat("%.02f%%", ($rgb_value[$i] / 255.0) * 100)
        EndSwitch
    Next
    Return $rgb_percent
EndFunc   ;==>_WebColors_RGBToRGBPercent
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToName
; Description ...:  Convert a 3-element array of percentages to its corresponding normalized color name, if any such name exists.
; Syntax ........: _WebColors_RGBPercentToName($rgb_percent[, $spec = 'css3'])
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
;                 $spec             - [optional] A specification list to use. Default is 'css3'.
; Return values .: Success - The normalized color name
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
;                 |4 - Specification not supported
;                 |5 - Internal error; Hex value is not a valid hexadecimal color value
;                 |6 - Name is not defined as a named color in the specification
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToName($rgb_percent, $spec='css3')
    __WebColors_Init()
    Local $rgb_value, $name
    $rgb_value = _WebColors_RGBPercentToRGB($rgb_percent)
    If @error Then Return SetError(@error, 0, "")
    $name = _WebColors_RGBToName($rgb_value, $spec)
    If @error Then Return SetError(@error)
    Return $name
EndFunc   ;==>_WebColors_RGBPercentToName
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToHex
; Description ...: Convert a 3-element array of percentages to a normalized hexadecimal color value for that color.
; Syntax ........: _WebColors_RGBPercentToHex($rgb_percent)
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
; Return values .: Success - The hexadecimal color value
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToHex($rgb_percent)
    Local $rgb_value, $hex_value
    $rgb_value = _WebColors_RGBPercentToRGB($rgb_percent)
    If @error Then Return SetError(@error, 0, "")
    $hex_value = _WebColors_RGBToHex($rgb_value)
    If @error Then Return SetError(@error, 0, "")
    Return $hex_value
EndFunc   ;==>_WebColors_RGBPercentToHex
; #FUNCTION# ====================================================================================================================
; Name ..........: _WebColors_RGBPercentToRGB
; Description ...: Convert a 3-element array of percentages to a 3-element array of integers.
; Syntax ........: _WebColors_RGBPercentToRGB($rgb_percent)
; Parameters ....: $rgb_percent      - An array of RGB percentage values.
; Return values .: Success - The 3-element array of RGB integers
;                 Failure - Blank string, sets @error
;                 |1 - RGB value is not an array
;                 |2 - RGB value array does not have 3 elements
;                 |3 - RGB array integer values not between 0 - 255 (inclusive)
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _WebColors_RGBPercentToRGB($rgb_percent)
    Local $rgb_value[3]
    If Not __WebColors_IsValidRGB($rgb_percent) Then Return SetError(@error, 0, "")
    For $i=0 To 2
        $rgb_value[$i] = __WebColors_PercentToInt($rgb_percent[$i])
    Next
    Return $rgb_value
EndFunc   ;==>_WebColors_RGBPercentToRGB
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name ..........: __WebColors_Reverse_Dict
; Description ...: Creates a reverse lookup dictionary.
; Syntax ........: __WebColors_Reverse_Dict($base_dict, $reverse_dict)
; Parameters ....: $base_dict          - A dictionary to reverse.
;                 $reverse_dict     - A dictionary to store the reversed dictionary.
; Return values .: Success - None
;                 Failure - -1, sets @error to 1
; Author ........: Michael Mims (zorphnog)
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func __WebColors_Reverse_Dict($base_dict, $reverse_dict)
    Local $items = __WebColors_x($base_dict)
    If IsObj($items) Then
        For $i In $items
            __WebColors_x($reverse_dict & "." & $items.item($i), $i)
        Next
    Else
        Return SetError(1, 0, -1)
    EndIf
EndFunc   ;==>__WebColors_Reverse_Dict
; #INTERNAL_USE_ONLY# ===========================================================================================================
; Name...........: __WebColors_x
; Description ...: Gets or sets a value in an Associative Array
; Syntax.........: SET: __WebColors_x( $sKey , $vValue )
;                 GET: __WebColors_x( $key )
; Parameters ....: $sKey - the key to set or get. Examples:
;                 __WebColors_x( 'foo' )           gets value of foo
;                 __WebColors_x( 'foo.bar' )       gets value of bar which is a key of foo
;                 $bar = "baz"
;                 __WebColors_x( 'foo.$bar' )     gets value of baz which is a key of foo (variables are expanded)
; Return values .: Success - When setting, return the value set. When getting, returns the requested value.
;                 Failure - Returns a 0
; Author ........: OHB <me at="" orangehairedboy="" dot="" com="">
; ===============================================================================================================================
Func __WebColors_x( $sKey = '' , $vValue = '' )
    $func = "get"
    If @NumParams <> 1 Then $func = "set"
    If $sKey == '' Then
        If $func == "get" Then
            Return $__WC_xHashCollection
        Else
            $__WC_xHashCollection.removeAll
            Return ''
        EndIf
    EndIf
    $parts = StringSplit( $sKey , "." )
    $last_key = $parts[$parts[0]]
    $cur = $__WC_xHashCollection
    For $x = 1 To $parts[0] - 1
        If Not $cur.exists( $parts[$x] ) Then
            If $func == "get" Then Return
            $cur.add( $parts[$x] , ObjCreate( "Scripting.Dictionary" ) )
        EndIf
        $cur = $cur.item( $parts[$x] )
    Next
    If IsPtr( $vValue ) Then $vValue = String( $vValue )
    If $func == "get" Then
        If Not $cur.exists( $last_key ) Then Return
        $item = $cur.item( $last_key )
        Return $item
    ElseIf Not $cur.exists( $last_key ) Then
        $cur.add( $last_key , $vValue )
    Else
        $cur.item( $last_key ) = $vValue
    EndIf
    Return $vValue
EndFunc

_WebColors_Test.au3

#include "WebColors.au3"
#include <array.au3>
Global $sLog = ""
$sLog &= __GetTestResult("_WebColors_NameToHex('white')", '#ffffff')
$sLog &= __GetTestResult("_WebColors_NameToHex('navy')", '#000080')
$sLog &= __GetTestResult("_WebColors_NameToHex('goldenrod')", '#daa520')
$sLog &= __GetTestResult("_WebColors_NameToHex('goldenrod', 'html4')", 2) ; Throws error; value not defined in html4 specifications
$sLog &= __GetTestResult("_WebColors_NameToRGB('white')", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_NameToRGB('navy')", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_NameToRGB('goldenrod')", '[218, 165, 32]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('white')", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('navy')", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_NameToRGBPercent('goldenrod')", '[85.49%, 64.71%, 12.5%]')
$sLog &= __GetTestResult("_WebColors_HexToName('#ffffff')", 'white')
$sLog &= __GetTestResult("_WebColors_HexToName('#fff')", 'white')
$sLog &= __GetTestResult("_WebColors_HexToName('#000080')", 'navy')
$sLog &= __GetTestResult("_WebColors_HexToName('#daa520')", 'goldenrod')
$sLog &= __GetTestResult("_WebColors_HexToName('#daa520', 'html4')", 3)   ; Throws error; value not defined in html4 specifications
$sLog &= __GetTestResult("_WebColors_HexToRGB('#fff')", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_HexToRGB('#000080')", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_HexToRGBPercent('#ffffff')", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_HexToRGBPercent('#000080')", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_RGBToName(_ArrayCreate(255, 255, 255))", 'white')
$sLog &= __GetTestResult("_WebColors_RGBToName(_ArrayCreate(0, 0, 128))", 'navy')
$sLog &= __GetTestResult("_WebColors_RGBToHex(_ArrayCreate(255, 255, 255))", '#ffffff')
$sLog &= __GetTestResult("_WebColors_RGBToHex(_ArrayCreate(0, 0, 128))", '#000080')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(255, 255, 255))", '[100%, 100%, 100%]')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(0, 0, 128))", '[0%, 0%, 50%]')
$sLog &= __GetTestResult("_WebColors_RGBToRGBPercent(_ArrayCreate(218, 165, 32))", '[85.49%, 64.71%, 12.5%]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('100%', '100%', '100%'))", 'white')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('0%', '0%', '50%'))", 'navy')
$sLog &= __GetTestResult("_WebColors_RGBPercentToName(_ArrayCreate('85.49%', '64.71%', '12.5%'))", 'goldenrod')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('100%', '100%', '100%'))", '#ffffff')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('0%', '0%', '50%'))", '#000080')
$sLog &= __GetTestResult("_WebColors_RGBPercentToHex(_ArrayCreate('85.49%', '64.71%', '12.5%'))", '#daa520')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('100%', '100%', '100%'))", '[255, 255, 255]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('0%', '0%', '50%'))", '[0, 0, 128]')
$sLog &= __GetTestResult("_WebColors_RGBPercentToRGB(_ArrayCreate('85.49%', '64.71%', '12.5%'))", '[218, 165, 32]')
ConsoleWrite($sLog)
Func __GetTestResult($sCommand, $sExpected = "")
    Local $sResult, $iError, $sPass
    $sResult = Execute($sCommand)
    $iError = @error
    $sPass = "!FAIL"
    Select
        Case $iError <> 0
            If $iError == $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => <error: %d="">n", $sPass, $sCommand, $iError)
        Case IsString($sResult)
            If $sResult = $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => %sn", $sPass, $sCommand, $sResult)
        Case IsArray($sResult)
            Local $sTemp = "[" & _ArrayToString($sResult, ", ") & "]"
            If $sTemp = $sExpected Then $sPass = "+PASS"
            Return StringFormat("%s   %-75s => %sn",$sPass, $sCommand, $sTemp)
    EndSelect
EndFunc

UDF + Test script:

WebColors.zip

Edited by zorphnog
Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Hermes
      Hi, I have a site that has the following elements below: 
      <div>More element here</div> <div>More element here</div> <div>More element here</div> When I do this in Auto It:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div") _WD_HighlightElement($sSession, $oSelectDiv, 1) I also tried to add [3], but it doesnt seems to work:
      Local $oSelectDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "div[3]") _WD_HighlightElement($sSession, $oSelectDiv, 1) It always highlight the first one, but I am trying to highlight the 3rd in the list. Is there anyway to select the 3rd div without having to add any class/id in the divs, and without using XPATH? The structure of the elements in that site were built that way.
    • By Pured
      I am looking to create a script which refreshes/reads a webpage every few seconds. My goal is to see if the page has changed, then I will send myself a notification that the webpage has been updated.
       
      However, rather than downloading the entire webpage every single time, is there a way to check when the webpage last updated?
       
      If not, is there away to partially download/read html source until a specific tag is hit?
       
      Goal: I would like to increase my poll rate and not excessively waste data.
    • By Mr_Microphone
      Alright, I may be an idiot.
      Three years ago, I wrote a program that pushed component information to a secure site via their API. I went back to add some attributes and (here's the idiot part) ended up losing the  source code and my modified code does not quite work. I have the compiled version that works minus the new attributes, so I know that their system has not changed. I stripped the larger program down from 3,000 lines to the part that is broken, but I am stumped. This was one of my first scripts, so it heavily leverages examples and isn't as pretty as I'd like it to be.
      Be gentle. 
      The program / script creates a new records as expected, but for some reason, I cannot access information in the response, which I need for a later step.
      I use Charles, a web debugging proxy tool so I can see the request and the response and both are as expected. Also, when I write to log file, the JSON reply is exactly what I expect and need, but when I try to do anything with the http body, it seems to be blank. 
      Here is the script minus  the URL and token:
      #include <Array.au3> #include <Curl.au3> #include <MsgBoxConstants.au3> #include <json.au3>  ; this was added as an alternate way to read the data Global $WM_serial_number = "WM20745001" Global $wm_component_status_id = "10" Global $wm_manufacturer ="Multi-Tech" Global $wm_model = "MTR-LAT1-B07" Global $cellular_carrier_id = "3" Global $iccid_esn = "89010303300012345678" Global $ip_address = "192.168.2.11" Global $NewIDNumber     Local $Curl = Curl_Easy_Init()     Local $Html = $Curl ; any number as identify     Local $Header = $Curl + 1 ; any number as identify     Local $HtmlFile = "cURL_Request.html"     Local $File = FileOpen($HtmlFile, 2 + 16)     Local $Slist = Curl_Slist_Append(0, "content-type: multipart/form-data; boundary=---011000010111000001101001")     $Slist = Curl_Slist_Append($Slist, "authorization: Token token=" & $Token)     Curl_Easy_Setopt($Curl, $CURLOPT_PROXY, "127.0.0.1") ; needed to use Charles web debugging proxy     Curl_Easy_Setopt($Curl, $CURLOPT_PROXYPORT, 8888) ; needed to use Charles     Curl_Easy_Setopt($Curl, $CURLOPT_HTTPHEADER, $Slist) ;     Curl_Easy_Setopt($Curl, $CURLOPT_URL, $Server & "wireless_module" & "s")     Curl_Easy_Setopt($Curl, $CURLOPT_SSL_VERIFYPEER, 0)     Curl_Easy_Setopt($Curl, $CURLOPT_TIMEOUT, 30)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $Html)     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEFUNCTION, Curl_FileWriteCallback())     Curl_Easy_Setopt($Curl, $CURLOPT_WRITEDATA, $File)     Local $HttpPost = ""     Local $LastItem = ""         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[serial_number]", $CURLFORM_COPYCONTENTS, $WM_serial_number, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[component_status_id]", $CURLFORM_COPYCONTENTS, $wm_component_status_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[manufacturer]", $CURLFORM_COPYCONTENTS, $wm_manufacturer, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[model]", $CURLFORM_COPYCONTENTS, $wm_model, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[cellular_carrier_id]", $CURLFORM_COPYCONTENTS, $cellular_carrier_id, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[iccid_esn]", $CURLFORM_COPYCONTENTS, $iccid_esn, $CURLFORM_END)         Curl_FormAdd($HttpPost, $LastItem, $CURLFORM_COPYNAME, "wireless_module" & "[ip_address]", $CURLFORM_COPYCONTENTS, $ip_address, $CURLFORM_END)         ; submit         Curl_Easy_Setopt($Curl, $CURLOPT_HTTPPOST, $HttpPost)         Local $Code = Curl_Easy_Perform($Curl)         If $Code = $CURLE_OK Then         ConsoleWrite("Content Type: " & Curl_Easy_GetInfo($Curl, $CURLINFO_CONTENT_TYPE) & @LF)         ConsoleWrite("Download Size: " & Curl_Easy_GetInfo($Curl, $CURLINFO_SIZE_DOWNLOAD) & @LF)         MsgBox(0, 'Html', BinaryToString(Curl_Data_Get($Html))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         MsgBox(0, 'Header', BinaryToString(Curl_Data_Get($Header))) ; this is something I threw in for debugging, expecting to see SOMETHING. Returns nothing         Local $response = Curl_Easy_GetInfo($Curl, $CURLINFO_RESPONSE_CODE)             If $response = "409" Then $response = "Failed due to a conflict."             If $response = "200" Then $response = "Was NOT created."             If $response = "201" Then $response = "Was created."             ; read the ID that was assigned and store it         $NewIDNumber = StringRight(StringLeft(BinaryToString(Curl_Data_Get($Html)), 10), 4) ; this DID work, but now it doesn't. An old compiled version still works ;~         Global $JsonObject = json_decode($Html); another debugging attempt. Did not use json functions previously and the program worked without it. ;~         Global $NewIDNumber = json_get($JsonObject, '.id')         ConsoleWrite(@CRLF &'! id:' & $NewIDNumber & @CRLF & @CRLF)    ; debugging feedback         MsgBox(0, $response, $wm_serial_number & " new ID = " & $NewIDNumber); debugging feedback         If $Code <> $CURLE_OK Then ConsoleWrite(Curl_Easy_StrError($Code) & @LF)             Local $Data = BinaryToString(Curl_Data_Get($Curl))             Curl_Easy_Cleanup($Curl)             Curl_Data_Cleanup($Curl)             Curl_Data_Cleanup($Header)             Curl_Data_Cleanup($Html)             Curl_FormFree($HttpPost)             Curl_slist_free_all($Slist)             curl_easy_reset($Curl)             FileClose($File)             ConsoleWrite(@LF)         EndIf  This is the captured request (minus the host and token)
      POST /api/v2/wireless_modules HTTP/1.1 Host: api. Accept: */* authorization: Token token= Content-Length: 942 Expect: 100-continue content-type: multipart/form-data; boundary=---011000010111000001101001; boundary=------------------------9adb0d87c7ea5061 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[serial_number]" WM20745001 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[component_status_id]" 10 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[manufacturer]" Multi-Tech --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[model]" MTR-LAT1-B07 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[cellular_carrier_id]" 3 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[iccid_esn]" 89010303300012345678 --------------------------9adb0d87c7ea5061 Content-Disposition: form-data; name="wireless_module[ip_address]" 192.168.2.11 --------------------------9adb0d87c7ea5061-- and the captured response
      HTTP/1.1 201 Created Date: Sun, 04 Apr 2021 00:12:18 GMT Server: Apache Cache-Control: max-age=0, private, must-revalidate Access-Control-Allow-Origin: not-allowed Vary: Accept-Encoding Access-Control-Max-Age: 1728000 X-XSS-Protection: 1; mode=block X-Request-Id: 71cfcf36-6020-48a6-a822-d2b393a27b69 Access-Control-Allow-Credentials: true Access-Control-Allow-Methods: PUT, OPTIONS, GET, POST ETag: W/"25d97fe8a9387cb4b9029a9e62b0bfa2" X-Frame-Options: SAMEORIGIN, SAMEORIGIN X-Runtime: 0.344005 X-Content-Type-Options: nosniff Access-Control-Request-Method: * X-Powered-By: Phusion Passenger 5.2.1 Strict-Transport-Security: max-age=63072000; includeSubDomains; preload Location: /wireless_modules/3195 Status: 201 Created Connection: close Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 X-Charles-Received-Continue: HTTP/1.1 100 Continue {"id":3195,"model":"MTR-LAT1-B07","serial_number":"WM20745001","manufacturer":"Multi-Tech","mfg_date":null,"iccid_esn":"89010303300012345678","ip_address":"192.168.2.11","purchase_order":null,"supplier":null,"cellular_carrier_id":3,"component_status_id":10,"component_status":{"id":10,"name":"Hold","description":"Available- Held for specific use"},"custom_attributes":[{"name":"Deactivated","type":"Boolean","value":false},{"name":"Port 3001","type":"Boolean","value":false}],"comments":[]}  
      Also attached is the log file. I need to read the id value. Clearly, it is arriving back to cURL, since it is being written out to the log, but I cannot seem to get to it within the code. 
      It is established that I may be an idiot, but this idiot has wasted days in non-billable hours trying to figure out what should be a simple glitch.
      Help???
       
      cURL_Request.html
    • By Hermes
      I have an html table that displays data along with an excel spreadsheet that has the same data as the html table. I am wanting to only match the Title column in my html table with the Title column in my Excel spreadsheet. If the titles match, click on the Edit hyperlink and continue to loop to next row. The issue I'm experience is its not matching correctly. So far  i've written the codes below:
      <table border="1" class="test"> <tr> <th> UniqueID</th> <th> Title</th> <th> UserID</th> <th> Address</th> <th> Gender </th> </tr> <tr> <td> 1 </td> <td> Title1 </td> <td> 12345 </td> <td> Manila </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5"> <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 2 </td> <td> Title2 </td> <td> 67891 </td> <td> Valenzuela </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 3 </td> <td> Title3 </td> <td> 88888 </td> <td> Ohio </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 4 </td> <td> Title4 </td> <td> 77777 </td> <td> California </td> <td> <span> Female </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> <tr> <td> 5 </td> <td> Title5 </td> <td> 33333 </td> <td> Arizona </td> <td> <span> Male </span> </td> </tr> <tr> <td align="center" colspan="5" > <a href="#" class="testlink">Edit</a> </td> </tr> </table> #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "Excel.au3" #Include "_HtmlTable2Array.au3" #Include "Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "index.html") Sleep(6000) Local $oExcel = _Excel_Open() Local $oWorkbook = _Excel_BookOpen($oExcel, "test.xlsx") ; Get the table element $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='test']") ; Retrieve HTML $sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML") ;Local $aTable = _HtmlTableGetWriteToArray($sHTML) Local $aArray1 = _Excel_RangeRead($oWorkbook,1,$oWorkbook.ActiveSheet.Usedrange.Columns("B:B")) Local $aArray2 = _HtmlTableGetWriteToArray($sHTML) ;_ArrayDisplay($aArray1) ;_ArrayDisplay($aArray2) For $i = UBound($aArray1) - 1 To 0 step - 1 For $j = UBound($aArray2) - 1 to 0 step - 1 If $aArray1[$i][1] == $aArray2[$j][1] Then _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") $test1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]") _WD_ElementAction($sSession, $test1, 'click') ;_ArrayDisplay($aArray1) ;_ArrayDelete($aArray1 , $i) ;exitloop EndIf Next Next _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome Would appreciate if anyone can provide tips, or point me in the right direction in doing it.
       
      test.xlsx
    • By JuanFelipe
      Hello guys!
      I have a problem with a script, in the past I made a program and it worked perfect, I recently used it again and it already stands still in one step, the problem is a Javascript event that changed but now I cannot execute it.
       
      <td colspan="2" align="center"><input type="button" id="Buscar" name="Buscar" value="Buscar" onclick="javascript:enviarForma(document.obtenercasosPersonaPorDocumento,'0');" class="boton"></td>  
      Previously I used this code and it worked, but now it does nothing
      $botonconsulta = _IEGetObjByName($oIE,"Buscar") _IEAction($botonconsulta, 'click') _IELoadWait($oIE)  
      Now I have tried the following codes but none works.
       
      ;==================== 1 _IEHeadInsertEventScript($oIE, "document", "onclick", "javascript:enviarForma(document.obtenercasosPersonaPorDocumento,'0');") ControlClick("SUPER CELAC", "", "[CLASS:Internet Explorer_Server; INSTANCE:1]") _IELoadWait($oIE) ;==================== 2 $forma = $oIE.document.obtenercasosPersonaPorDocumento $oIE.Navigate("JavaScript:enviarForma("&$forma&",""0"");") _IELoadWait($oIE) ;==================== 3 $boton = _IEGetObjById($oIE, "Buscar") $boton.document.parentwindow.execScript("enviarForma(document.obtenercasosPersonaPorDocumento,'0');", "javascript") I hope you can guide me, because I think the error is in the parameters that the javascript function receives but I don't know how to send it, here I leave the first part of the JavaScript function.
      function enviarForma(frm,tipoForma){ var bExisteDatoConsulta = false; var bError=true; var mensajeError=""; switch (tipoForma) { //--Forma documento case "0": if (validar_campo_no_vacio_no_print(frm.numeroDocumento)) { if (!isNum(frm.numeroDocumento.value)) { bError = false; mensajeError += "El número de documento debe ser un valor numérico\n"; } bExisteDatoConsulta = true; } else { mensajeError += "Debe digitar un número de documento\n"; } break;  Thanks!
×
×
  • Create New...