<commit_before>package action

import (
	"errors"
	"fmt"
	"strings"

	"github.com/trumae/valente/status"

	"golang.org/x/net/websocket"
)

var (
	errNotImplemented = errors.New("Not Implemented!")
)

// Exec execute the js code on WebBrowser
func Exec(ws *websocket.Conn, js string) error {
	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//Enable the target form field or button.
func Enable(ws *websocket.Conn, target string) error {
	return errNotImplemented
}

//Disable  the target form field or button.
func Disable(ws *websocket.Conn, target string) error {
	return errNotImplemented
}

//Replace target with new content
func Replace(ws *websocket.Conn, target, content string) error {
	c := strings.Replace(content, "\n", "\\n", -1)
	c = strings.Replace(c, "\"", "\\\"", -1)
	js := fmt.Sprintf("$( \"#%s\" ).replaceWith(\"%s\");", target, c)

	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//HTML replace target with new content
func HTML(ws *websocket.Conn, target, content string) error {
	c := strings.Replace(content, "\n", "\\n", -1)
	c = strings.Replace(c, "\"", "\\\"", -1)
	js := fmt.Sprintf("$( \"#%s\" ).html(\"%s\");", target, c)

	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//Remove target from the DOM<commit_msg>show/hide actions<commit_after>package action

import (
	"errors"
	"fmt"
	"strings"

	"github.com/trumae/valente/status"

	"golang.org/x/net/websocket"
)

var (
	errNotImplemented = errors.New("Not Implemented!")
)

// Exec execute the js code on WebBrowser
func Exec(ws *websocket.Conn, js string) error {
	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//Enable the target form field or button.
func Enable(ws *websocket.Conn, target string) error {
	return errNotImplemented
}

//Disable  the target form field or button.
func Disable(ws *websocket.Conn, target string) error {
	return errNotImplemented
}

//Replace target with new content
func Replace(ws *websocket.Conn, target, content string) error {
	c := strings.Replace(content, "\n", "\\n", -1)
	c = strings.Replace(c, "\"", "\\\"", -1)
	js := fmt.Sprintf("$( \"#%s\" ).replaceWith(\"%s\");", target, c)

	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//HTML replace target with new content
func HTML(ws *websocket.Conn, target, content string) error {
	c := strings.Replace(content, "\n", "\\n", -1)
	c = strings.Replace(c, "\"", "\\\"", -1)
	js := fmt.Sprintf("$( \"#%s\" ).html(\"%s\");", target, c)

	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//Hide the target
func Hide(ws *websocket.Conn, target string, duration string) error {
	js := fmt.Sprintf("$( \"#%s\" ).hide(\"%s\");", target, duration)

	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//Show the target
func Show(ws *websocket.Conn, target string, duration string) error {
	js := fmt.Sprintf("$( \"#%s\" ).show(\"%s\");", target, duration)

	err := websocket.Message.Send(ws, js)
	if err != nil {
		return err
	}
	status.Status.SendedBytes += len(js)
	return err
}

//Remove target from the DOM
{'fraction_non_alphanumeric': 0.177124928693668, 'fraction_numerical': 0.0022818026240730175, 'mean_word_length': 3.7073825503355704, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4495752', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1251, 'n_words': 356}