mirror of
				https://github.com/MontFerret/ferret.git
				synced 2025-10-30 23:37:40 +02:00 
			
		
		
		
	Rename variables and methods to match styleguide
This commit is contained in:
		| @@ -11,7 +11,7 @@ import ( | |||||||
| type Topic struct { | type Topic struct { | ||||||
| 	Name        string `json:"name"` | 	Name        string `json:"name"` | ||||||
| 	Description string `json:"description"` | 	Description string `json:"description"` | ||||||
| 	Url         string `json:"url"` | 	URL         string `json:"url"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func main() { | func main() { | ||||||
| @@ -23,7 +23,7 @@ func main() { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, topic := range topics { | 	for _, topic := range topics { | ||||||
| 		fmt.Println(fmt.Sprintf("%s: %s %s", topic.Name, topic.Description, topic.Url)) | 		fmt.Println(fmt.Sprintf("%s: %s %s", topic.Name, topic.Description, topic.URL)) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -43,8 +43,8 @@ type ( | |||||||
| 		pos    int | 		pos    int | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	HtmlNodeIterator struct { | 	HTMLNodeIterator struct { | ||||||
| 		values values.HtmlNode | 		values values.HTMLNode | ||||||
| 		pos    int | 		pos    int | ||||||
| 	} | 	} | ||||||
| ) | ) | ||||||
| @@ -56,7 +56,7 @@ func ToIterator(value core.Value) (Iterator, error) { | |||||||
| 	case core.ObjectType: | 	case core.ObjectType: | ||||||
| 		return NewObjectIterator(value.(*values.Object)), nil | 		return NewObjectIterator(value.(*values.Object)), nil | ||||||
| 	case core.HtmlElementType, core.HtmlDocumentType: | 	case core.HtmlElementType, core.HtmlDocumentType: | ||||||
| 		return NewHtmlNodeIterator(value.(values.HtmlNode)), nil | 		return NewHTMLNodeIterator(value.(values.HTMLNode)), nil | ||||||
| 	default: | 	default: | ||||||
| 		return nil, core.TypeError( | 		return nil, core.TypeError( | ||||||
| 			value.Type(), | 			value.Type(), | ||||||
| @@ -214,15 +214,15 @@ func (iterator *ObjectIterator) Next() (core.Value, core.Value, error) { | |||||||
| 	return values.None, values.None, ErrExhausted | 	return values.None, values.None, ErrExhausted | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewHtmlNodeIterator(input values.HtmlNode) *HtmlNodeIterator { | func NewHTMLNodeIterator(input values.HTMLNode) *HTMLNodeIterator { | ||||||
| 	return &HtmlNodeIterator{input, 0} | 	return &HTMLNodeIterator{input, 0} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (iterator *HtmlNodeIterator) HasNext() bool { | func (iterator *HTMLNodeIterator) HasNext() bool { | ||||||
| 	return iterator.values.Length() > values.NewInt(iterator.pos) | 	return iterator.values.Length() > values.NewInt(iterator.pos) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (iterator *HtmlNodeIterator) Next() (core.Value, core.Value, error) { | func (iterator *HTMLNodeIterator) Next() (core.Value, core.Value, error) { | ||||||
| 	if iterator.values.Length() > values.NewInt(iterator.pos) { | 	if iterator.values.Length() > values.NewInt(iterator.pos) { | ||||||
| 		idx := iterator.pos | 		idx := iterator.pos | ||||||
| 		val := iterator.values.GetChildNode(values.NewInt(idx)) | 		val := iterator.values.GetChildNode(values.NewInt(idx)) | ||||||
|   | |||||||
| @@ -15,8 +15,8 @@ const ( | |||||||
| 	DateTimeType     Type = 5 | 	DateTimeType     Type = 5 | ||||||
| 	ArrayType        Type = 6 | 	ArrayType        Type = 6 | ||||||
| 	ObjectType       Type = 7 | 	ObjectType       Type = 7 | ||||||
| 	HtmlElementType  Type = 8 | 	HTMLElementType  Type = 8 | ||||||
| 	HtmlDocumentType Type = 9 | 	HTMLDocumentType Type = 9 | ||||||
| 	BinaryType       Type = 10 | 	BinaryType       Type = 10 | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -29,8 +29,8 @@ var typestr = map[Type]string{ | |||||||
| 	DateTimeType:     "datetime", | 	DateTimeType:     "datetime", | ||||||
| 	ArrayType:        "array", | 	ArrayType:        "array", | ||||||
| 	ObjectType:       "object", | 	ObjectType:       "object", | ||||||
| 	HtmlElementType:  "HTMLElement", | 	HTMLElementType:  "HTMLElement", | ||||||
| 	HtmlDocumentType: "HTMLDocument", | 	HTMLDocumentType: "HTMLDocument", | ||||||
| 	BinaryType:       "BinaryType", | 	BinaryType:       "BinaryType", | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ package values | |||||||
| import "github.com/MontFerret/ferret/pkg/runtime/core" | import "github.com/MontFerret/ferret/pkg/runtime/core" | ||||||
|  |  | ||||||
| type ( | type ( | ||||||
| 	HtmlNode interface { | 	HTMLNode interface { | ||||||
| 		core.Value | 		core.Value | ||||||
|  |  | ||||||
| 		NodeType() Int | 		NodeType() Int | ||||||
| @@ -14,7 +14,7 @@ type ( | |||||||
|  |  | ||||||
| 		InnerText() String | 		InnerText() String | ||||||
|  |  | ||||||
| 		InnerHtml() String | 		InnerHTML() String | ||||||
|  |  | ||||||
| 		Value() core.Value | 		Value() core.Value | ||||||
|  |  | ||||||
| @@ -31,9 +31,9 @@ type ( | |||||||
| 		QuerySelectorAll(selector String) core.Value | 		QuerySelectorAll(selector String) core.Value | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	HtmlDocument interface { | 	HTMLDocument interface { | ||||||
| 		HtmlNode | 		HTMLNode | ||||||
|  |  | ||||||
| 		Url() core.Value | 		URL() core.Value | ||||||
| 	} | 	} | ||||||
| ) | ) | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ import ( | |||||||
|  * @param selector (String) - Selector |  * @param selector (String) - Selector | ||||||
|  * @returns str (String) - String value of inner html. |  * @returns str (String) - String value of inner html. | ||||||
|  */ |  */ | ||||||
| func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) { | func InnerHTML(_ context.Context, args ...core.Value) (core.Value, error) { | ||||||
| 	err := core.ValidateArgs(args, 2, 2) | 	err := core.ValidateArgs(args, 2, 2) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -35,7 +35,7 @@ func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) { | |||||||
| 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return doc.InnerHtmlBySelector(values.NewString(selector)) | 	return doc.InnerHTMLBySelector(values.NewString(selector)) | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| @@ -44,7 +44,7 @@ func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) { | |||||||
|  * @param selector (String) - Selector |  * @param selector (String) - Selector | ||||||
|  * @returns array (Array) - Array of string values. |  * @returns array (Array) - Array of string values. | ||||||
|  */ |  */ | ||||||
| func InnerHtmlAll(_ context.Context, args ...core.Value) (core.Value, error) { | func InnerHTMLAll(_ context.Context, args ...core.Value) (core.Value, error) { | ||||||
| 	err := core.ValidateArgs(args, 2, 2) | 	err := core.ValidateArgs(args, 2, 2) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -66,7 +66,7 @@ func InnerHtmlAll(_ context.Context, args ...core.Value) (core.Value, error) { | |||||||
| 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return doc.InnerHtmlBySelectorAll(values.NewString(selector)) | 	return doc.InnerHTMLBySelectorAll(values.NewString(selector)) | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| @@ -97,7 +97,7 @@ func InnerText(_ context.Context, args ...core.Value) (core.Value, error) { | |||||||
| 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return doc.InnerHtmlBySelector(values.NewString(selector)) | 	return doc.InnerHTMLBySelector(values.NewString(selector)) | ||||||
| } | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
| @@ -128,5 +128,5 @@ func InnerTextAll(_ context.Context, args ...core.Value) (core.Value, error) { | |||||||
| 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | 		return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return doc.InnerHtmlBySelectorAll(values.NewString(selector)) | 	return doc.InnerHTMLBySelectorAll(values.NewString(selector)) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,7 +2,7 @@ package common | |||||||
|  |  | ||||||
| import "golang.org/x/net/html" | import "golang.org/x/net/html" | ||||||
|  |  | ||||||
| func ToHtmlType(nt html.NodeType) int { | func ToHTMLType(nt html.NodeType) int { | ||||||
| 	switch nt { | 	switch nt { | ||||||
| 	case html.DocumentNode: | 	case html.DocumentNode: | ||||||
| 		return 9 | 		return 9 | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ import ( | |||||||
| 	"time" | 	"time" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type HtmlDocument struct { | type HTMLDocument struct { | ||||||
| 	sync.Mutex | 	sync.Mutex | ||||||
| 	logger  *zerolog.Logger | 	logger  *zerolog.Logger | ||||||
| 	conn    *rpcc.Conn | 	conn    *rpcc.Conn | ||||||
| @@ -31,11 +31,11 @@ type HtmlDocument struct { | |||||||
| 	element *HtmlElement | 	element *HtmlElement | ||||||
| } | } | ||||||
|  |  | ||||||
| func LoadHtmlDocument( | func LoadHTMLDocument( | ||||||
| 	ctx context.Context, | 	ctx context.Context, | ||||||
| 	conn *rpcc.Conn, | 	conn *rpcc.Conn, | ||||||
| 	url string, | 	url string, | ||||||
| ) (*HtmlDocument, error) { | ) (*HTMLDocument, error) { | ||||||
| 	if conn == nil { | 	if conn == nil { | ||||||
| 		return nil, core.Error(core.ErrMissedArgument, "connection") | 		return nil, core.Error(core.ErrMissedArgument, "connection") | ||||||
| 	} | 	} | ||||||
| @@ -84,7 +84,7 @@ func LoadHtmlDocument( | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	root, innerHtml, err := getRootElement(client) | 	root, innerHTML, err := getRootElement(client) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, err | 		return nil, err | ||||||
| @@ -96,13 +96,13 @@ func LoadHtmlDocument( | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return NewHtmlDocument( | 	return NewHTMLDocument( | ||||||
| 		logging.FromContext(ctx), | 		logging.FromContext(ctx), | ||||||
| 		conn, | 		conn, | ||||||
| 		client, | 		client, | ||||||
| 		broker, | 		broker, | ||||||
| 		root, | 		root, | ||||||
| 		innerHtml, | 		innerHTML, | ||||||
| 	), nil | 	), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -117,29 +117,29 @@ func getRootElement(client *cdp.Client) (dom.Node, values.String, error) { | |||||||
| 		return dom.Node{}, values.EmptyString, err | 		return dom.Node{}, values.EmptyString, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	innerHtml, err := client.DOM.GetOuterHTML(ctx, dom.NewGetOuterHTMLArgs().SetNodeID(d.Root.NodeID)) | 	innerHTML, err := client.DOM.GetOuterHTML(ctx, dom.NewGetOuterHTMLArgs().SetNodeID(d.Root.NodeID)) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return dom.Node{}, values.EmptyString, err | 		return dom.Node{}, values.EmptyString, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return d.Root, values.NewString(innerHtml.OuterHTML), nil | 	return d.Root, values.NewString(innerHTML.OuterHTML), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewHtmlDocument( | func NewHTMLDocument( | ||||||
| 	logger *zerolog.Logger, | 	logger *zerolog.Logger, | ||||||
| 	conn *rpcc.Conn, | 	conn *rpcc.Conn, | ||||||
| 	client *cdp.Client, | 	client *cdp.Client, | ||||||
| 	broker *events.EventBroker, | 	broker *events.EventBroker, | ||||||
| 	root dom.Node, | 	root dom.Node, | ||||||
| 	innerHtml values.String, | 	innerHTML values.String, | ||||||
| ) *HtmlDocument { | ) *HTMLDocument { | ||||||
| 	doc := new(HtmlDocument) | 	doc := new(HTMLDocument) | ||||||
| 	doc.logger = logger | 	doc.logger = logger | ||||||
| 	doc.conn = conn | 	doc.conn = conn | ||||||
| 	doc.client = client | 	doc.client = client | ||||||
| 	doc.events = broker | 	doc.events = broker | ||||||
| 	doc.element = NewHtmlElement(doc.logger, client, broker, root.NodeID, root, innerHtml) | 	doc.element = NewHtmlElement(doc.logger, client, broker, root.NodeID, root, innerHTML) | ||||||
| 	doc.url = "" | 	doc.url = "" | ||||||
|  |  | ||||||
| 	if root.BaseURL != nil { | 	if root.BaseURL != nil { | ||||||
| @@ -150,7 +150,7 @@ func NewHtmlDocument( | |||||||
| 		doc.Lock() | 		doc.Lock() | ||||||
| 		defer doc.Unlock() | 		defer doc.Unlock() | ||||||
|  |  | ||||||
| 		updated, innerHtml, err := getRootElement(client) | 		updated, innerHTML, err := getRootElement(client) | ||||||
|  |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			doc.logger.Error(). | 			doc.logger.Error(). | ||||||
| @@ -165,7 +165,7 @@ func NewHtmlDocument( | |||||||
| 		doc.element.Close() | 		doc.element.Close() | ||||||
|  |  | ||||||
| 		// create a new root element wrapper | 		// create a new root element wrapper | ||||||
| 		doc.element = NewHtmlElement(doc.logger, client, broker, updated.NodeID, updated, innerHtml) | 		doc.element = NewHtmlElement(doc.logger, client, broker, updated.NodeID, updated, innerHTML) | ||||||
| 		doc.url = "" | 		doc.url = "" | ||||||
|  |  | ||||||
| 		if updated.BaseURL != nil { | 		if updated.BaseURL != nil { | ||||||
| @@ -176,32 +176,32 @@ func NewHtmlDocument( | |||||||
| 	return doc | 	return doc | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) MarshalJSON() ([]byte, error) { | func (doc *HTMLDocument) MarshalJSON() ([]byte, error) { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.MarshalJSON() | 	return doc.element.MarshalJSON() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Type() core.Type { | func (doc *HTMLDocument) Type() core.Type { | ||||||
| 	return core.HtmlDocumentType | 	return core.HTMLDocumentType | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) String() string { | func (doc *HTMLDocument) String() string { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.url.String() | 	return doc.url.String() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Unwrap() interface{} { | func (doc *HTMLDocument) Unwrap() interface{} { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element | 	return doc.element | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Hash() int { | func (doc *HTMLDocument) Hash() int { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| @@ -216,21 +216,21 @@ func (doc *HtmlDocument) Hash() int { | |||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Clone() core.Value { | func (doc *HTMLDocument) Clone() core.Value { | ||||||
| 	return values.None | 	return values.None | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Compare(other core.Value) int { | func (doc *HTMLDocument) Compare(other core.Value) int { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	switch other.Type() { | 	switch other.Type() { | ||||||
| 	case core.HtmlDocumentType: | 	case core.HTMLDocumentType: | ||||||
| 		other := other.(*HtmlDocument) | 		other := other.(*HTMLDocument) | ||||||
|  |  | ||||||
| 		return doc.url.Compare(other.url) | 		return doc.url.Compare(other.url) | ||||||
| 	default: | 	default: | ||||||
| 		if other.Type() > core.HtmlDocumentType { | 		if other.Type() > core.HTMLDocumentType { | ||||||
| 			return -1 | 			return -1 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -238,7 +238,7 @@ func (doc *HtmlDocument) Compare(other core.Value) int { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Close() error { | func (doc *HTMLDocument) Close() error { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| @@ -287,95 +287,95 @@ func (doc *HtmlDocument) Close() error { | |||||||
| 	return doc.conn.Close() | 	return doc.conn.Close() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) NodeType() values.Int { | func (doc *HTMLDocument) NodeType() values.Int { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.NodeType() | 	return doc.element.NodeType() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) NodeName() values.String { | func (doc *HTMLDocument) NodeName() values.String { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.NodeName() | 	return doc.element.NodeName() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Length() values.Int { | func (doc *HTMLDocument) Length() values.Int { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.Length() | 	return doc.element.Length() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) InnerText() values.String { | func (doc *HTMLDocument) InnerText() values.String { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.InnerText() | 	return doc.element.InnerText() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) InnerHtml() values.String { | func (doc *HTMLDocument) InnerHTML() values.String { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.InnerHtml() | 	return doc.element.InnerHTML() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Value() core.Value { | func (doc *HTMLDocument) Value() core.Value { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.Value() | 	return doc.element.Value() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) GetAttributes() core.Value { | func (doc *HTMLDocument) GetAttributes() core.Value { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.GetAttributes() | 	return doc.element.GetAttributes() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) GetAttribute(name values.String) core.Value { | func (doc *HTMLDocument) GetAttribute(name values.String) core.Value { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.GetAttribute(name) | 	return doc.element.GetAttribute(name) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) GetChildNodes() core.Value { | func (doc *HTMLDocument) GetChildNodes() core.Value { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.GetChildNodes() | 	return doc.element.GetChildNodes() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) GetChildNode(idx values.Int) core.Value { | func (doc *HTMLDocument) GetChildNode(idx values.Int) core.Value { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.GetChildNode(idx) | 	return doc.element.GetChildNode(idx) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) QuerySelector(selector values.String) core.Value { | func (doc *HTMLDocument) QuerySelector(selector values.String) core.Value { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.QuerySelector(selector) | 	return doc.element.QuerySelector(selector) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) QuerySelectorAll(selector values.String) core.Value { | func (doc *HTMLDocument) QuerySelectorAll(selector values.String) core.Value { | ||||||
| 	doc.Lock() | 	doc.Lock() | ||||||
| 	defer doc.Unlock() | 	defer doc.Unlock() | ||||||
|  |  | ||||||
| 	return doc.element.QuerySelectorAll(selector) | 	return doc.element.QuerySelectorAll(selector) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Url() core.Value { | func (doc *HTMLDocument) URL() core.Value { | ||||||
| 	return doc.url | 	return doc.url | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.String, error) { | func (doc *HTMLDocument) InnerHTMLBySelector(selector values.String) (values.String, error) { | ||||||
| 	res, err := eval.Eval( | 	res, err := eval.Eval( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf(` | 		fmt.Sprintf(` | ||||||
| @@ -385,7 +385,7 @@ func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.Str | |||||||
| 				return ""; | 				return ""; | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			return el.innerHtml; | 			return el.innerHTML; | ||||||
| 		`, eval.ParamString(selector.String())), | 		`, eval.ParamString(selector.String())), | ||||||
| 		true, | 		true, | ||||||
| 		false, | 		false, | ||||||
| @@ -402,7 +402,7 @@ func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.Str | |||||||
| 	return values.EmptyString, nil | 	return values.EmptyString, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values.Array, error) { | func (doc *HTMLDocument) InnerHTMLBySelectorAll(selector values.String) (*values.Array, error) { | ||||||
| 	res, err := eval.Eval( | 	res, err := eval.Eval( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf(` | 		fmt.Sprintf(` | ||||||
| @@ -414,7 +414,7 @@ func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values | |||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			elements.forEach((i) => { | 			elements.forEach((i) => { | ||||||
| 				result.push(i.innerHtml); | 				result.push(i.innerHTML); | ||||||
| 			}); | 			}); | ||||||
|  |  | ||||||
| 			return result; | 			return result; | ||||||
| @@ -434,7 +434,7 @@ func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values | |||||||
| 	return values.NewArray(0), nil | 	return values.NewArray(0), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) InnerTextBySelector(selector values.String) (values.String, error) { | func (doc *HTMLDocument) InnerTextBySelector(selector values.String) (values.String, error) { | ||||||
| 	res, err := eval.Eval( | 	res, err := eval.Eval( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf(` | 		fmt.Sprintf(` | ||||||
| @@ -461,7 +461,7 @@ func (doc *HtmlDocument) InnerTextBySelector(selector values.String) (values.Str | |||||||
| 	return values.EmptyString, nil | 	return values.EmptyString, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) InnerTextBySelectorAll(selector values.String) (*values.Array, error) { | func (doc *HTMLDocument) InnerTextBySelectorAll(selector values.String) (*values.Array, error) { | ||||||
| 	res, err := eval.Eval( | 	res, err := eval.Eval( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf(` | 		fmt.Sprintf(` | ||||||
| @@ -493,7 +493,7 @@ func (doc *HtmlDocument) InnerTextBySelectorAll(selector values.String) (*values | |||||||
| 	return values.NewArray(0), nil | 	return values.NewArray(0), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) ClickBySelector(selector values.String) (values.Boolean, error) { | func (doc *HTMLDocument) ClickBySelector(selector values.String) (values.Boolean, error) { | ||||||
| 	res, err := eval.Eval( | 	res, err := eval.Eval( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf(` | 		fmt.Sprintf(` | ||||||
| @@ -523,7 +523,7 @@ func (doc *HtmlDocument) ClickBySelector(selector values.String) (values.Boolean | |||||||
| 	return values.False, nil | 	return values.False, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) ClickBySelectorAll(selector values.String) (values.Boolean, error) { | func (doc *HTMLDocument) ClickBySelectorAll(selector values.String) (values.Boolean, error) { | ||||||
| 	res, err := eval.Eval( | 	res, err := eval.Eval( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf(` | 		fmt.Sprintf(` | ||||||
| @@ -555,7 +555,7 @@ func (doc *HtmlDocument) ClickBySelectorAll(selector values.String) (values.Bool | |||||||
| 	return values.False, nil | 	return values.False, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) InputBySelector(selector values.String, value core.Value) (values.Boolean, error) { | func (doc *HTMLDocument) InputBySelector(selector values.String, value core.Value) (values.Boolean, error) { | ||||||
| 	res, err := eval.Eval( | 	res, err := eval.Eval( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf( | 		fmt.Sprintf( | ||||||
| @@ -591,7 +591,7 @@ func (doc *HtmlDocument) InputBySelector(selector values.String, value core.Valu | |||||||
| 	return values.False, nil | 	return values.False, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) WaitForSelector(selector values.String, timeout values.Int) error { | func (doc *HTMLDocument) WaitForSelector(selector values.String, timeout values.Int) error { | ||||||
| 	task := events.NewWaitTask( | 	task := events.NewWaitTask( | ||||||
| 		doc.client, | 		doc.client, | ||||||
| 		fmt.Sprintf(` | 		fmt.Sprintf(` | ||||||
| @@ -612,7 +612,7 @@ func (doc *HtmlDocument) WaitForSelector(selector values.String, timeout values. | |||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) WaitForNavigation(timeout values.Int) error { | func (doc *HTMLDocument) WaitForNavigation(timeout values.Int) error { | ||||||
| 	timer := time.NewTimer(time.Millisecond * time.Duration(timeout)) | 	timer := time.NewTimer(time.Millisecond * time.Duration(timeout)) | ||||||
| 	onEvent := make(chan bool) | 	onEvent := make(chan bool) | ||||||
| 	listener := func(_ interface{}) { | 	listener := func(_ interface{}) { | ||||||
| @@ -636,7 +636,7 @@ func (doc *HtmlDocument) WaitForNavigation(timeout values.Int) error { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (doc *HtmlDocument) Navigate(url values.String) error { | func (doc *HTMLDocument) Navigate(url values.String) error { | ||||||
| 	ctx := context.Background() | 	ctx := context.Background() | ||||||
| 	repl, err := doc.client.Page.Navigate(ctx, page.NewNavigateArgs(url.String())) | 	repl, err := doc.client.Page.Navigate(ctx, page.NewNavigateArgs(url.String())) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -21,7 +21,7 @@ import ( | |||||||
|  |  | ||||||
| const DefaultTimeout = time.Second * 30 | const DefaultTimeout = time.Second * 30 | ||||||
|  |  | ||||||
| type HtmlElement struct { | type HTMLElement struct { | ||||||
| 	sync.Mutex | 	sync.Mutex | ||||||
| 	logger         *zerolog.Logger | 	logger         *zerolog.Logger | ||||||
| 	client         *cdp.Client | 	client         *cdp.Client | ||||||
| @@ -30,7 +30,7 @@ type HtmlElement struct { | |||||||
| 	id             dom.NodeID | 	id             dom.NodeID | ||||||
| 	nodeType       values.Int | 	nodeType       values.Int | ||||||
| 	nodeName       values.String | 	nodeName       values.String | ||||||
| 	innerHtml      values.String | 	innerHTML      values.String | ||||||
| 	innerText      *common.LazyValue | 	innerText      *common.LazyValue | ||||||
| 	value          core.Value | 	value          core.Value | ||||||
| 	rawAttrs       []string | 	rawAttrs       []string | ||||||
| @@ -44,7 +44,7 @@ func LoadElement( | |||||||
| 	client *cdp.Client, | 	client *cdp.Client, | ||||||
| 	broker *events.EventBroker, | 	broker *events.EventBroker, | ||||||
| 	id dom.NodeID, | 	id dom.NodeID, | ||||||
| ) (*HtmlElement, error) { | ) (*HTMLElement, error) { | ||||||
| 	if client == nil { | 	if client == nil { | ||||||
| 		return nil, core.Error(core.ErrMissedArgument, "client") | 		return nil, core.Error(core.ErrMissedArgument, "client") | ||||||
| 	} | 	} | ||||||
| @@ -65,31 +65,31 @@ func LoadElement( | |||||||
| 		return nil, core.Error(err, strconv.Itoa(int(id))) | 		return nil, core.Error(err, strconv.Itoa(int(id))) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	innerHtml, err := loadInnerHtml(client, id) | 	innerHTML, err := loadInnerHTML(client, id) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, core.Error(err, strconv.Itoa(int(id))) | 		return nil, core.Error(err, strconv.Itoa(int(id))) | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return NewHtmlElement( | 	return NewHTMLElement( | ||||||
| 		logger, | 		logger, | ||||||
| 		client, | 		client, | ||||||
| 		broker, | 		broker, | ||||||
| 		id, | 		id, | ||||||
| 		node.Node, | 		node.Node, | ||||||
| 		innerHtml, | 		innerHTML, | ||||||
| 	), nil | 	), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewHtmlElement( | func NewHTMLElement( | ||||||
| 	logger *zerolog.Logger, | 	logger *zerolog.Logger, | ||||||
| 	client *cdp.Client, | 	client *cdp.Client, | ||||||
| 	broker *events.EventBroker, | 	broker *events.EventBroker, | ||||||
| 	id dom.NodeID, | 	id dom.NodeID, | ||||||
| 	node dom.Node, | 	node dom.Node, | ||||||
| 	innerHtml values.String, | 	innerHTML values.String, | ||||||
| ) *HtmlElement { | ) *HTMLElement { | ||||||
| 	el := new(HtmlElement) | 	el := new(HTMLElement) | ||||||
| 	el.logger = logger | 	el.logger = logger | ||||||
| 	el.client = client | 	el.client = client | ||||||
| 	el.broker = broker | 	el.broker = broker | ||||||
| @@ -97,7 +97,7 @@ func NewHtmlElement( | |||||||
| 	el.id = id | 	el.id = id | ||||||
| 	el.nodeType = values.NewInt(node.NodeType) | 	el.nodeType = values.NewInt(node.NodeType) | ||||||
| 	el.nodeName = values.NewString(node.NodeName) | 	el.nodeName = values.NewString(node.NodeName) | ||||||
| 	el.innerHtml = innerHtml | 	el.innerHTML = innerHTML | ||||||
| 	el.innerText = common.NewLazyValue(el.loadInnerText) | 	el.innerText = common.NewLazyValue(el.loadInnerText) | ||||||
| 	el.rawAttrs = node.Attributes[:] | 	el.rawAttrs = node.Attributes[:] | ||||||
| 	el.attributes = common.NewLazyValue(el.loadAttrs) | 	el.attributes = common.NewLazyValue(el.loadAttrs) | ||||||
| @@ -120,7 +120,7 @@ func NewHtmlElement( | |||||||
| 	return el | 	return el | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Close() error { | func (el *HTMLElement) Close() error { | ||||||
| 	el.Lock() | 	el.Lock() | ||||||
| 	defer el.Unlock() | 	defer el.Unlock() | ||||||
|  |  | ||||||
| @@ -140,11 +140,11 @@ func (el *HtmlElement) Close() error { | |||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Type() core.Type { | func (el *HTMLElement) Type() core.Type { | ||||||
| 	return core.HtmlElementType | 	return core.HTMLElementType | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) MarshalJSON() ([]byte, error) { | func (el *HTMLElement) MarshalJSON() ([]byte, error) { | ||||||
| 	val, err := el.innerText.Value() | 	val, err := el.innerText.Value() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -154,29 +154,29 @@ func (el *HtmlElement) MarshalJSON() ([]byte, error) { | |||||||
| 	return json.Marshal(val.String()) | 	return json.Marshal(val.String()) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) String() string { | func (el *HTMLElement) String() string { | ||||||
| 	return el.InnerHtml().String() | 	return el.InnerHTML().String() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Compare(other core.Value) int { | func (el *HTMLElement) Compare(other core.Value) int { | ||||||
| 	switch other.Type() { | 	switch other.Type() { | ||||||
| 	case core.HtmlDocumentType: | 	case core.HtmlDocumentType: | ||||||
| 		other := other.(*HtmlElement) | 		other := other.(*HTMLElement) | ||||||
|  |  | ||||||
| 		id := int(el.id) | 		id := int(el.id) | ||||||
| 		otherId := int(other.id) | 		otherID := int(other.id) | ||||||
|  |  | ||||||
| 		if id == otherId { | 		if id == otherID { | ||||||
| 			return 0 | 			return 0 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if id > otherId { | 		if id > otherID { | ||||||
| 			return 1 | 			return 1 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return -1 | 		return -1 | ||||||
| 	default: | 	default: | ||||||
| 		if other.Type() > core.HtmlElementType { | 		if other.Type() > core.HTMLElementType { | ||||||
| 			return -1 | 			return -1 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -184,17 +184,17 @@ func (el *HtmlElement) Compare(other core.Value) int { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Unwrap() interface{} { | func (el *HTMLElement) Unwrap() interface{} { | ||||||
| 	return el | 	return el | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Hash() int { | func (el *HTMLElement) Hash() int { | ||||||
| 	el.Lock() | 	el.Lock() | ||||||
| 	defer el.Unlock() | 	defer el.Unlock() | ||||||
|  |  | ||||||
| 	h := sha512.New() | 	h := sha512.New() | ||||||
|  |  | ||||||
| 	out, err := h.Write([]byte(el.innerHtml)) | 	out, err := h.Write([]byte(el.innerHTML)) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		el.logger.Error(). | 		el.logger.Error(). | ||||||
| @@ -208,7 +208,7 @@ func (el *HtmlElement) Hash() int { | |||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Value() core.Value { | func (el *HTMLElement) Value() core.Value { | ||||||
| 	if !el.IsConnected() { | 	if !el.IsConnected() { | ||||||
| 		return el.value | 		return el.value | ||||||
| 	} | 	} | ||||||
| @@ -232,23 +232,23 @@ func (el *HtmlElement) Value() core.Value { | |||||||
| 	return val | 	return val | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Clone() core.Value { | func (el *HTMLElement) Clone() core.Value { | ||||||
| 	return values.None | 	return values.None | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Length() values.Int { | func (el *HTMLElement) Length() values.Int { | ||||||
| 	return values.NewInt(len(el.children)) | 	return values.NewInt(len(el.children)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) NodeType() values.Int { | func (el *HTMLElement) NodeType() values.Int { | ||||||
| 	return el.nodeType | 	return el.nodeType | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) NodeName() values.String { | func (el *HTMLElement) NodeName() values.String { | ||||||
| 	return el.nodeName | 	return el.nodeName | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetAttributes() core.Value { | func (el *HTMLElement) GetAttributes() core.Value { | ||||||
| 	val, err := el.attributes.Value() | 	val, err := el.attributes.Value() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -259,7 +259,7 @@ func (el *HtmlElement) GetAttributes() core.Value { | |||||||
| 	return val.Clone() | 	return val.Clone() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetAttribute(name values.String) core.Value { | func (el *HTMLElement) GetAttribute(name values.String) core.Value { | ||||||
| 	attrs, err := el.attributes.Value() | 	attrs, err := el.attributes.Value() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -275,7 +275,7 @@ func (el *HtmlElement) GetAttribute(name values.String) core.Value { | |||||||
| 	return val | 	return val | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetChildNodes() core.Value { | func (el *HTMLElement) GetChildNodes() core.Value { | ||||||
| 	val, err := el.loadedChildren.Value() | 	val, err := el.loadedChildren.Value() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -285,7 +285,7 @@ func (el *HtmlElement) GetChildNodes() core.Value { | |||||||
| 	return val | 	return val | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetChildNode(idx values.Int) core.Value { | func (el *HTMLElement) GetChildNode(idx values.Int) core.Value { | ||||||
| 	val, err := el.loadedChildren.Value() | 	val, err := el.loadedChildren.Value() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -295,7 +295,7 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value { | |||||||
| 	return val.(*values.Array).Get(idx) | 	return val.(*values.Array).Get(idx) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) QuerySelector(selector values.String) core.Value { | func (el *HTMLElement) QuerySelector(selector values.String) core.Value { | ||||||
| 	if !el.IsConnected() { | 	if !el.IsConnected() { | ||||||
| 		return values.NewArray(0) | 		return values.NewArray(0) | ||||||
| 	} | 	} | ||||||
| @@ -330,7 +330,7 @@ func (el *HtmlElement) QuerySelector(selector values.String) core.Value { | |||||||
| 	return res | 	return res | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value { | func (el *HTMLElement) QuerySelectorAll(selector values.String) core.Value { | ||||||
| 	if !el.IsConnected() { | 	if !el.IsConnected() { | ||||||
| 		return values.NewArray(0) | 		return values.NewArray(0) | ||||||
| 	} | 	} | ||||||
| @@ -371,7 +371,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value { | |||||||
| 	return arr | 	return arr | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) InnerText() values.String { | func (el *HTMLElement) InnerText() values.String { | ||||||
| 	val, err := el.innerText.Value() | 	val, err := el.innerText.Value() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -381,14 +381,14 @@ func (el *HtmlElement) InnerText() values.String { | |||||||
| 	return val.(values.String) | 	return val.(values.String) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) InnerHtml() values.String { | func (el *HTMLElement) InnerHTML() values.String { | ||||||
| 	el.Lock() | 	el.Lock() | ||||||
| 	defer el.Unlock() | 	defer el.Unlock() | ||||||
|  |  | ||||||
| 	return el.innerHtml | 	return el.innerHTML | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Click() (values.Boolean, error) { | func (el *HTMLElement) Click() (values.Boolean, error) { | ||||||
| 	ctx, cancel := contextWithTimeout() | 	ctx, cancel := contextWithTimeout() | ||||||
|  |  | ||||||
| 	defer cancel() | 	defer cancel() | ||||||
| @@ -396,22 +396,22 @@ func (el *HtmlElement) Click() (values.Boolean, error) { | |||||||
| 	return events.DispatchEvent(ctx, el.client, el.id, "click") | 	return events.DispatchEvent(ctx, el.client, el.id, "click") | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Input(value core.Value) error { | func (el *HTMLElement) Input(value core.Value) error { | ||||||
| 	ctx, cancel := contextWithTimeout() | 	ctx, cancel := contextWithTimeout() | ||||||
| 	defer cancel() | 	defer cancel() | ||||||
|  |  | ||||||
| 	return el.client.DOM.SetAttributeValue(ctx, dom.NewSetAttributeValueArgs(el.id, "value", value.String())) | 	return el.client.DOM.SetAttributeValue(ctx, dom.NewSetAttributeValueArgs(el.id, "value", value.String())) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) IsConnected() values.Boolean { | func (el *HTMLElement) IsConnected() values.Boolean { | ||||||
| 	el.Lock() | 	el.Lock() | ||||||
| 	defer el.Unlock() | 	defer el.Unlock() | ||||||
|  |  | ||||||
| 	return el.connected | 	return el.connected | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) loadInnerText() (core.Value, error) { | func (el *HTMLElement) loadInnerText() (core.Value, error) { | ||||||
| 	h := el.InnerHtml() | 	h := el.InnerHTML() | ||||||
|  |  | ||||||
| 	if h == values.EmptyString { | 	if h == values.EmptyString { | ||||||
| 		return h, nil | 		return h, nil | ||||||
| @@ -434,11 +434,11 @@ func (el *HtmlElement) loadInnerText() (core.Value, error) { | |||||||
| 	return values.NewString(parsed.Text()), nil | 	return values.NewString(parsed.Text()), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) loadAttrs() (core.Value, error) { | func (el *HTMLElement) loadAttrs() (core.Value, error) { | ||||||
| 	return parseAttrs(el.rawAttrs), nil | 	return parseAttrs(el.rawAttrs), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) loadChildren() (core.Value, error) { | func (el *HTMLElement) loadChildren() (core.Value, error) { | ||||||
| 	if !el.IsConnected() { | 	if !el.IsConnected() { | ||||||
| 		return values.NewArray(0), nil | 		return values.NewArray(0), nil | ||||||
| 	} | 	} | ||||||
| @@ -458,11 +458,11 @@ func (el *HtmlElement) loadChildren() (core.Value, error) { | |||||||
| 	return loaded, nil | 	return loaded, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) handlePageReload(message interface{}) { | func (el *HTMLElement) handlePageReload(message interface{}) { | ||||||
| 	el.Close() | 	el.Close() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) handleAttrModified(message interface{}) { | func (el *HTMLElement) handleAttrModified(message interface{}) { | ||||||
| 	reply, ok := message.(*dom.AttributeModifiedReply) | 	reply, ok := message.(*dom.AttributeModifiedReply) | ||||||
|  |  | ||||||
| 	// well.... | 	// well.... | ||||||
| @@ -500,7 +500,7 @@ func (el *HtmlElement) handleAttrModified(message interface{}) { | |||||||
| 	attrs.Set(values.NewString(reply.Name), values.NewString(reply.Value)) | 	attrs.Set(values.NewString(reply.Name), values.NewString(reply.Value)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) handleAttrRemoved(message interface{}) { | func (el *HTMLElement) handleAttrRemoved(message interface{}) { | ||||||
| 	reply, ok := message.(*dom.AttributeRemovedReply) | 	reply, ok := message.(*dom.AttributeRemovedReply) | ||||||
|  |  | ||||||
| 	// well.... | 	// well.... | ||||||
| @@ -539,7 +539,7 @@ func (el *HtmlElement) handleAttrRemoved(message interface{}) { | |||||||
| 	attrs.Remove(values.NewString(reply.Name)) | 	attrs.Remove(values.NewString(reply.Name)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) handleChildrenCountChanged(message interface{}) { | func (el *HTMLElement) handleChildrenCountChanged(message interface{}) { | ||||||
| 	reply, ok := message.(*dom.ChildNodeCountUpdatedReply) | 	reply, ok := message.(*dom.ChildNodeCountUpdatedReply) | ||||||
|  |  | ||||||
| 	if !ok { | 	if !ok { | ||||||
| @@ -568,7 +568,7 @@ func (el *HtmlElement) handleChildrenCountChanged(message interface{}) { | |||||||
| 	el.children = createChildrenArray(node.Node.Children) | 	el.children = createChildrenArray(node.Node.Children) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) handleChildInserted(message interface{}) { | func (el *HTMLElement) handleChildInserted(message interface{}) { | ||||||
| 	reply, ok := message.(*dom.ChildNodeInsertedReply) | 	reply, ok := message.(*dom.ChildNodeInsertedReply) | ||||||
|  |  | ||||||
| 	if !ok { | 	if !ok { | ||||||
| @@ -579,26 +579,26 @@ func (el *HtmlElement) handleChildInserted(message interface{}) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	targetIdx := -1 | 	targetIDx := -1 | ||||||
| 	prevId := reply.PreviousNodeID | 	prevID := reply.PreviousNodeID | ||||||
| 	nextId := reply.Node.NodeID | 	nextID := reply.Node.NodeID | ||||||
|  |  | ||||||
| 	el.Lock() | 	el.Lock() | ||||||
| 	defer el.Unlock() | 	defer el.Unlock() | ||||||
|  |  | ||||||
| 	for idx, id := range el.children { | 	for idx, id := range el.children { | ||||||
| 		if id == prevId { | 		if id == prevID { | ||||||
| 			targetIdx = idx | 			targetIDx = idx | ||||||
| 			break | 			break | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if targetIdx == -1 { | 	if targetIDx == -1 { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	arr := el.children | 	arr := el.children | ||||||
| 	el.children = append(arr[:targetIdx], append([]dom.NodeID{nextId}, arr[targetIdx:]...)...) | 	el.children = append(arr[:targetIDx], append([]dom.NodeID{nextID}, arr[targetIDx:]...)...) | ||||||
|  |  | ||||||
| 	if !el.loadedChildren.Ready() { | 	if !el.loadedChildren.Ready() { | ||||||
| 		return | 		return | ||||||
| @@ -611,7 +611,7 @@ func (el *HtmlElement) handleChildInserted(message interface{}) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	loadedArr := loaded.(*values.Array) | 	loadedArr := loaded.(*values.Array) | ||||||
| 	loadedEl, err := LoadElement(el.logger, el.client, el.broker, nextId) | 	loadedEl, err := LoadElement(el.logger, el.client, el.broker, nextID) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		el.logger.Error(). | 		el.logger.Error(). | ||||||
| @@ -623,9 +623,9 @@ func (el *HtmlElement) handleChildInserted(message interface{}) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	loadedArr.Insert(values.NewInt(targetIdx), loadedEl) | 	loadedArr.Insert(values.NewInt(targetIDx), loadedEl) | ||||||
|  |  | ||||||
| 	newInnerHtml, err := loadInnerHtml(el.client, el.id) | 	newInnerHTML, err := loadInnerHTML(el.client, el.id) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		el.logger.Error(). | 		el.logger.Error(). | ||||||
| @@ -637,10 +637,10 @@ func (el *HtmlElement) handleChildInserted(message interface{}) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	el.innerHtml = newInnerHtml | 	el.innerHTML = newInnerHTML | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) handleChildDeleted(message interface{}) { | func (el *HTMLElement) handleChildDeleted(message interface{}) { | ||||||
| 	reply, ok := message.(*dom.ChildNodeRemovedReply) | 	reply, ok := message.(*dom.ChildNodeRemovedReply) | ||||||
|  |  | ||||||
| 	if !ok { | 	if !ok { | ||||||
| @@ -651,25 +651,25 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	targetIdx := -1 | 	targetIDx := -1 | ||||||
| 	targetId := reply.NodeID | 	targetID := reply.NodeID | ||||||
|  |  | ||||||
| 	el.Lock() | 	el.Lock() | ||||||
| 	defer el.Unlock() | 	defer el.Unlock() | ||||||
|  |  | ||||||
| 	for idx, id := range el.children { | 	for idx, id := range el.children { | ||||||
| 		if id == targetId { | 		if id == targetID { | ||||||
| 			targetIdx = idx | 			targetIDx = idx | ||||||
| 			break | 			break | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if targetIdx == -1 { | 	if targetIDx == -1 { | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	arr := el.children | 	arr := el.children | ||||||
| 	el.children = append(arr[:targetIdx], arr[targetIdx+1:]...) | 	el.children = append(arr[:targetIDx], arr[targetIDx+1:]...) | ||||||
|  |  | ||||||
| 	if !el.loadedChildren.Ready() { | 	if !el.loadedChildren.Ready() { | ||||||
| 		return | 		return | ||||||
| @@ -682,9 +682,9 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	loadedArr := loaded.(*values.Array) | 	loadedArr := loaded.(*values.Array) | ||||||
| 	loadedArr.RemoveAt(values.NewInt(targetIdx)) | 	loadedArr.RemoveAt(values.NewInt(targetIDx)) | ||||||
|  |  | ||||||
| 	newInnerHtml, err := loadInnerHtml(el.client, el.id) | 	newInnerHTML, err := loadInnerHTML(el.client, el.id) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		el.logger.Error(). | 		el.logger.Error(). | ||||||
| @@ -696,5 +696,5 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	el.innerHtml = newInnerHtml | 	el.innerHTML = newInnerHTML | ||||||
| } | } | ||||||
|   | |||||||
| @@ -47,10 +47,10 @@ func DispatchEvent( | |||||||
| 		return values.False, nil | 		return values.False, nil | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	evtId := evt.Result.ObjectID | 	evtID := evt.Result.ObjectID | ||||||
|  |  | ||||||
| 	// release the event object | 	// release the event object | ||||||
| 	defer client.Runtime.ReleaseObject(ctx, runtime.NewReleaseObjectArgs(*evtId)) | 	defer client.Runtime.ReleaseObject(ctx, runtime.NewReleaseObjectArgs(*evtID)) | ||||||
|  |  | ||||||
| 	res, err := client.Runtime.CallFunctionOn( | 	res, err := client.Runtime.CallFunctionOn( | ||||||
| 		ctx, | 		ctx, | ||||||
|   | |||||||
| @@ -51,7 +51,7 @@ func parseAttrs(attrs []string) *values.Object { | |||||||
| 	return res | 	return res | ||||||
| } | } | ||||||
|  |  | ||||||
| func loadInnerHtml(client *cdp.Client, id dom.NodeID) (values.String, error) { | func loadInnerHTML(client *cdp.Client, id dom.NodeID) (values.String, error) { | ||||||
| 	res, err := client.DOM.GetOuterHTML(context.Background(), dom.NewGetOuterHTMLArgs().SetNodeID(id)) | 	res, err := client.DOM.GetOuterHTML(context.Background(), dom.NewGetOuterHTMLArgs().SetNodeID(id)) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -6,15 +6,15 @@ import ( | |||||||
| 	"github.com/PuerkitoBio/goquery" | 	"github.com/PuerkitoBio/goquery" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type HtmlDocument struct { | type HTMLDocument struct { | ||||||
| 	*HtmlElement | 	*HtmlElement | ||||||
| 	url values.String | 	url values.String | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewHtmlDocument( | func NewHTMLDocument( | ||||||
| 	url string, | 	url string, | ||||||
| 	node *goquery.Document, | 	node *goquery.Document, | ||||||
| ) (*HtmlDocument, error) { | ) (*HTMLDocument, error) { | ||||||
| 	if url == "" { | 	if url == "" { | ||||||
| 		return nil, core.Error(core.ErrMissedArgument, "document url") | 		return nil, core.Error(core.ErrMissedArgument, "document url") | ||||||
| 	} | 	} | ||||||
| @@ -29,21 +29,21 @@ func NewHtmlDocument( | |||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return &HtmlDocument{el, values.NewString(url)}, nil | 	return &HTMLDocument{el, values.NewString(url)}, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlDocument) Type() core.Type { | func (el *HTMLDocument) Type() core.Type { | ||||||
| 	return core.HtmlDocumentType | 	return core.HTMLDocumentType | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlDocument) Compare(other core.Value) int { | func (el *HTMLDocument) Compare(other core.Value) int { | ||||||
| 	switch other.Type() { | 	switch other.Type() { | ||||||
| 	case core.HtmlDocumentType: | 	case core.HTMLDocumentType: | ||||||
| 		otherDoc := other.(values.HtmlDocument) | 		otherDoc := other.(values.HTMLDocument) | ||||||
|  |  | ||||||
| 		return el.url.Compare(otherDoc.Url()) | 		return el.url.Compare(otherDoc.URL()) | ||||||
| 	default: | 	default: | ||||||
| 		if other.Type() > core.HtmlDocumentType { | 		if other.Type() > core.HTMLDocumentType { | ||||||
| 			return -1 | 			return -1 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -51,6 +51,6 @@ func (el *HtmlDocument) Compare(other core.Value) int { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlDocument) Url() core.Value { | func (el *HTMLDocument) URL() core.Value { | ||||||
| 	return el.url | 	return el.url | ||||||
| } | } | ||||||
|   | |||||||
| @@ -9,39 +9,39 @@ import ( | |||||||
| 	"github.com/PuerkitoBio/goquery" | 	"github.com/PuerkitoBio/goquery" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| type HtmlElement struct { | type HTMLElement struct { | ||||||
| 	selection *goquery.Selection | 	selection *goquery.Selection | ||||||
| 	attrs     *values.Object | 	attrs     *values.Object | ||||||
| 	children  *values.Array | 	children  *values.Array | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewHtmlElement(node *goquery.Selection) (*HtmlElement, error) { | func NewHTMLElement(node *goquery.Selection) (*HTMLElement, error) { | ||||||
| 	if node == nil { | 	if node == nil { | ||||||
| 		return nil, core.Error(core.ErrMissedArgument, "element selection") | 		return nil, core.Error(core.ErrMissedArgument, "element selection") | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return &HtmlElement{node, nil, nil}, nil | 	return &HTMLElement{node, nil, nil}, nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) MarshalJSON() ([]byte, error) { | func (el *HTMLElement) MarshalJSON() ([]byte, error) { | ||||||
| 	return json.Marshal(el.InnerText().String()) | 	return json.Marshal(el.InnerText().String()) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Type() core.Type { | func (el *HTMLElement) Type() core.Type { | ||||||
| 	return core.HtmlElementType | 	return core.HTMLElementType | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) String() string { | func (el *HTMLElement) String() string { | ||||||
| 	return el.InnerHtml().String() | 	return el.InnerHTML().String() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Compare(other core.Value) int { | func (el *HTMLElement) Compare(other core.Value) int { | ||||||
| 	switch other.Type() { | 	switch other.Type() { | ||||||
| 	case core.HtmlElementType: | 	case core.HTMLElementType: | ||||||
| 		// TODO: complete the comparison | 		// TODO: complete the comparison | ||||||
| 		return -1 | 		return -1 | ||||||
| 	default: | 	default: | ||||||
| 		if other.Type() > core.HtmlElementType { | 		if other.Type() > core.HTMLElementType { | ||||||
| 			return -1 | 			return -1 | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -49,11 +49,11 @@ func (el *HtmlElement) Compare(other core.Value) int { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Unwrap() interface{} { | func (el *HTMLElement) Unwrap() interface{} { | ||||||
| 	return el.selection | 	return el.selection | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Hash() int { | func (el *HTMLElement) Hash() int { | ||||||
| 	h := sha512.New() | 	h := sha512.New() | ||||||
|  |  | ||||||
| 	str, err := el.selection.Html() | 	str, err := el.selection.Html() | ||||||
| @@ -71,13 +71,13 @@ func (el *HtmlElement) Hash() int { | |||||||
| 	return out | 	return out | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Clone() core.Value { | func (el *HTMLElement) Clone() core.Value { | ||||||
| 	c, _ := NewHtmlElement(el.selection.Clone()) | 	c, _ := NewHTMLElement(el.selection.Clone()) | ||||||
|  |  | ||||||
| 	return c | 	return c | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) NodeType() values.Int { | func (el *HTMLElement) NodeType() values.Int { | ||||||
| 	nodes := el.selection.Nodes | 	nodes := el.selection.Nodes | ||||||
|  |  | ||||||
| 	if len(nodes) == 0 { | 	if len(nodes) == 0 { | ||||||
| @@ -87,11 +87,11 @@ func (el *HtmlElement) NodeType() values.Int { | |||||||
| 	return values.NewInt(common.ToHtmlType(nodes[0].Type)) | 	return values.NewInt(common.ToHtmlType(nodes[0].Type)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) NodeName() values.String { | func (el *HTMLElement) NodeName() values.String { | ||||||
| 	return values.NewString(goquery.NodeName(el.selection)) | 	return values.NewString(goquery.NodeName(el.selection)) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Length() values.Int { | func (el *HTMLElement) Length() values.Int { | ||||||
| 	if el.children == nil { | 	if el.children == nil { | ||||||
| 		el.children = el.parseChildren() | 		el.children = el.parseChildren() | ||||||
| 	} | 	} | ||||||
| @@ -99,7 +99,7 @@ func (el *HtmlElement) Length() values.Int { | |||||||
| 	return el.children.Length() | 	return el.children.Length() | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) Value() core.Value { | func (el *HTMLElement) Value() core.Value { | ||||||
| 	val, ok := el.selection.Attr("value") | 	val, ok := el.selection.Attr("value") | ||||||
|  |  | ||||||
| 	if ok { | 	if ok { | ||||||
| @@ -109,11 +109,11 @@ func (el *HtmlElement) Value() core.Value { | |||||||
| 	return values.EmptyString | 	return values.EmptyString | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) InnerText() values.String { | func (el *HTMLElement) InnerText() values.String { | ||||||
| 	return values.NewString(el.selection.Text()) | 	return values.NewString(el.selection.Text()) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) InnerHtml() values.String { | func (el *HTMLElement) InnerHTML() values.String { | ||||||
| 	h, err := el.selection.Html() | 	h, err := el.selection.Html() | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -123,7 +123,7 @@ func (el *HtmlElement) InnerHtml() values.String { | |||||||
| 	return values.NewString(h) | 	return values.NewString(h) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetAttributes() core.Value { | func (el *HTMLElement) GetAttributes() core.Value { | ||||||
| 	if el.attrs == nil { | 	if el.attrs == nil { | ||||||
| 		el.attrs = el.parseAttrs() | 		el.attrs = el.parseAttrs() | ||||||
| 	} | 	} | ||||||
| @@ -131,7 +131,7 @@ func (el *HtmlElement) GetAttributes() core.Value { | |||||||
| 	return el.attrs | 	return el.attrs | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetAttribute(name values.String) core.Value { | func (el *HTMLElement) GetAttribute(name values.String) core.Value { | ||||||
| 	v, ok := el.selection.Attr(name.String()) | 	v, ok := el.selection.Attr(name.String()) | ||||||
|  |  | ||||||
| 	if ok { | 	if ok { | ||||||
| @@ -141,7 +141,7 @@ func (el *HtmlElement) GetAttribute(name values.String) core.Value { | |||||||
| 	return values.None | 	return values.None | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetChildNodes() core.Value { | func (el *HTMLElement) GetChildNodes() core.Value { | ||||||
| 	if el.children == nil { | 	if el.children == nil { | ||||||
| 		el.children = el.parseChildren() | 		el.children = el.parseChildren() | ||||||
| 	} | 	} | ||||||
| @@ -149,7 +149,7 @@ func (el *HtmlElement) GetChildNodes() core.Value { | |||||||
| 	return el.children | 	return el.children | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) GetChildNode(idx values.Int) core.Value { | func (el *HTMLElement) GetChildNode(idx values.Int) core.Value { | ||||||
| 	if el.children == nil { | 	if el.children == nil { | ||||||
| 		el.children = el.parseChildren() | 		el.children = el.parseChildren() | ||||||
| 	} | 	} | ||||||
| @@ -157,14 +157,14 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value { | |||||||
| 	return el.children.Get(idx) | 	return el.children.Get(idx) | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) QuerySelector(selector values.String) core.Value { | func (el *HTMLElement) QuerySelector(selector values.String) core.Value { | ||||||
| 	selection := el.selection.Find(selector.String()) | 	selection := el.selection.Find(selector.String()) | ||||||
|  |  | ||||||
| 	if selection == nil { | 	if selection == nil { | ||||||
| 		return values.None | 		return values.None | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	res, err := NewHtmlElement(selection) | 	res, err := NewHTMLElement(selection) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return values.None | 		return values.None | ||||||
| @@ -173,7 +173,7 @@ func (el *HtmlElement) QuerySelector(selector values.String) core.Value { | |||||||
| 	return res | 	return res | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value { | func (el *HTMLElement) QuerySelectorAll(selector values.String) core.Value { | ||||||
| 	selection := el.selection.Find(selector.String()) | 	selection := el.selection.Find(selector.String()) | ||||||
|  |  | ||||||
| 	if selection == nil { | 	if selection == nil { | ||||||
| @@ -183,7 +183,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value { | |||||||
| 	arr := values.NewArray(selection.Length()) | 	arr := values.NewArray(selection.Length()) | ||||||
|  |  | ||||||
| 	selection.Each(func(i int, selection *goquery.Selection) { | 	selection.Each(func(i int, selection *goquery.Selection) { | ||||||
| 		el, err := NewHtmlElement(selection) | 		el, err := NewHTMLElement(selection) | ||||||
|  |  | ||||||
| 		if err == nil { | 		if err == nil { | ||||||
| 			arr.Push(el) | 			arr.Push(el) | ||||||
| @@ -193,7 +193,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value { | |||||||
| 	return arr | 	return arr | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) parseAttrs() *values.Object { | func (el *HTMLElement) parseAttrs() *values.Object { | ||||||
| 	obj := values.NewObject() | 	obj := values.NewObject() | ||||||
|  |  | ||||||
| 	for _, name := range common.Attributes { | 	for _, name := range common.Attributes { | ||||||
| @@ -207,7 +207,7 @@ func (el *HtmlElement) parseAttrs() *values.Object { | |||||||
| 	return obj | 	return obj | ||||||
| } | } | ||||||
|  |  | ||||||
| func (el *HtmlElement) parseChildren() *values.Array { | func (el *HTMLElement) parseChildren() *values.Array { | ||||||
| 	children := el.selection.Children() | 	children := el.selection.Children() | ||||||
|  |  | ||||||
| 	arr := values.NewArray(10) | 	arr := values.NewArray(10) | ||||||
| @@ -215,14 +215,14 @@ func (el *HtmlElement) parseChildren() *values.Array { | |||||||
| 	children.Each(func(i int, selection *goquery.Selection) { | 	children.Each(func(i int, selection *goquery.Selection) { | ||||||
| 		//name := goquery.NodeName(selection) | 		//name := goquery.NodeName(selection) | ||||||
| 		//if name != "#text" && name != "#comment" { | 		//if name != "#text" && name != "#comment" { | ||||||
| 		//	child, err := NewHtmlElement(selection) | 		//	child, err := NewHTMLElement(selection) | ||||||
| 		// | 		// | ||||||
| 		//	if err == nil { | 		//	if err == nil { | ||||||
| 		//		arr.Push(child) | 		//		arr.Push(child) | ||||||
| 		//	} | 		//	} | ||||||
| 		//} | 		//} | ||||||
|  |  | ||||||
| 		child, err := NewHtmlElement(selection) | 		child, err := NewHTMLElement(selection) | ||||||
|  |  | ||||||
| 		if err == nil { | 		if err == nil { | ||||||
| 			arr.Push(child) | 			arr.Push(child) | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ import ( | |||||||
|  * @params text (String) - The string to parse as JSON. |  * @params text (String) - The string to parse as JSON. | ||||||
|  * @returns FQL value (Value) |  * @returns FQL value (Value) | ||||||
|  */ |  */ | ||||||
| func JsonParse(_ context.Context, args ...core.Value) (core.Value, error) { | func JSONParse(_ context.Context, args ...core.Value) (core.Value, error) { | ||||||
| 	err := core.ValidateArgs(args, 1, 1) | 	err := core.ValidateArgs(args, 1, 1) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| @@ -35,7 +35,7 @@ func JsonParse(_ context.Context, args ...core.Value) (core.Value, error) { | |||||||
|  * @params value (Value) - The input value to serialize. |  * @params value (Value) - The input value to serialize. | ||||||
|  * @returns json (String) |  * @returns json (String) | ||||||
|  */ |  */ | ||||||
| func JsonStringify(_ context.Context, args ...core.Value) (core.Value, error) { | func JSONStringify(_ context.Context, args ...core.Value) (core.Value, error) { | ||||||
| 	err := core.ValidateArgs(args, 1, 1) | 	err := core.ValidateArgs(args, 1, 1) | ||||||
|  |  | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|   | |||||||
| @@ -74,20 +74,20 @@ func IsObject(_ context.Context, inputs ...core.Value) (core.Value, error) { | |||||||
| 	return isTypeof(inputs[0], core.ObjectType), nil | 	return isTypeof(inputs[0], core.ObjectType), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func IsHtmlElement(_ context.Context, inputs ...core.Value) (core.Value, error) { | func IsHTMLElement(_ context.Context, inputs ...core.Value) (core.Value, error) { | ||||||
| 	if len(inputs) == 0 { | 	if len(inputs) == 0 { | ||||||
| 		return values.None, core.ErrMissedArgument | 		return values.None, core.ErrMissedArgument | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return isTypeof(inputs[0], core.HtmlElementType), nil | 	return isTypeof(inputs[0], core.HTMLElementType), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func IsHtmlDocument(_ context.Context, inputs ...core.Value) (core.Value, error) { | func IsHTMLDocument(_ context.Context, inputs ...core.Value) (core.Value, error) { | ||||||
| 	if len(inputs) == 0 { | 	if len(inputs) == 0 { | ||||||
| 		return values.None, core.ErrMissedArgument | 		return values.None, core.ErrMissedArgument | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return isTypeof(inputs[0], core.HtmlDocumentType), nil | 	return isTypeof(inputs[0], core.HTMLDocumentType), nil | ||||||
| } | } | ||||||
|  |  | ||||||
| func IsBinary(_ context.Context, inputs ...core.Value) (core.Value, error) { | func IsBinary(_ context.Context, inputs ...core.Value) (core.Value, error) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user