How can I avoid swimming the same content twice?

My Kynetx application uses float_html() to place a field full of content.

 rule float_box { select when pageview ".*" pre { content = << <div id='messagebox'> <h3>Floating Message Box</h3> <ul id='my_list'></ul> </div> >>; // trippy } float_html("absolute","top:25px","right:20px",content); } rule fill_box { select when pageview ".*" foreach ["alpha","bravo","charlie"] setting (list_item) append("#my_list", "<li>#{list_item}</li>"); } 

The application (a421x27) is used from the bookmarklet. If you double-click the bookmarklet on the same page, you will get double content.

Is there a way to detect that the field is already on the screen and reuse it?

+4
source share
1 answer

You can float content manually using jQuery and check if it is there or not.

 ruleset a60x516 { meta { name "so-answer-example" description << so-answer-example >> author "Mike Grace" logging on } rule float_box { select when pageview ".*" pre { content = << <div id='messagebox'> <h3>Floating Message Box</h3> <ul id='my_list'></ul> </div> >>; /// fixing syntax highlighting bug } { emit <| if ($K("#messagebox").length == 0) { $K(content).css({ "position": "absolute", "top": "25px", "right": "20px" }).appendTo(document.body); }; |>; } } rule fill_box { select when pageview ".*" foreach ["alpha","bravo","charlie"] setting (list_item) { append("#my_list", "<li>#{list_item}</li>"); } } } 

Here's what it looks like after clicking on the bookmarklet from this code several times on example.com alt text


Side notes:

always transfer your actions to {}. Actions work without turning around {} if you have only one action, but it’s best to get used to marking your action block with {}.

+4
source

Source: https://habr.com/ru/post/1333490/


All Articles