1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
pub use lib::*;
#[allow(warnings)]
pub mod lib{
pub fn prepend_to_body(tagname:&str,options:&str,inner_html:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let body = document.body().expect("document should have a body");
let node = document.create_element_with_str(tagname, options).expect("create error");
node.set_inner_html(inner_html);
body.insert_adjacent_element("afterbegin",&node).expect("append style error");
}
pub fn append_to_body(tagname:&str,options:&str,inner_html:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let body = document.body().expect("document should have a body");
let node = document.create_element_with_str(tagname, options).expect("create error");
node.set_inner_html(inner_html);
body.insert_adjacent_element("beforeend",&node).expect("append style error");
}
pub fn prepend_to_head(tagname:&str,options:&str,inner_html:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let node = document.create_element_with_str(tagname, options).expect("create error");
node.set_inner_html(inner_html);
document.head().unwrap().insert_adjacent_element("afterbegin",&node).expect("insert to head error");
}
pub fn append_to_head(tagname:&str,options:&str,inner_html:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let node = document.create_element_with_str(tagname, options).expect("create error");
node.set_inner_html(inner_html);
document.head().unwrap().insert_adjacent_element("beforeend",&node).expect("insert to head error");
}
pub fn append_html_to_body(inner_html:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let body = document.body().expect("document should have a body");
let mut old_body = body.inner_html();
old_body.push_str(inner_html);
body.set_inner_html(&old_body);
}
pub fn append_html_to_head(inner_html:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let mut old_head = document.head().unwrap().inner_html();
old_head.push_str(inner_html);
document.head().unwrap().set_inner_html(&old_head);
}
pub fn append_html_by_class_name(class_name:&str,inner_html:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let body = document.body().expect("document should have a body");
let node = body.query_selector(&format!(".{}",class_name)).unwrap().unwrap();
let mut old_node = node.inner_html();
old_node.push_str(inner_html);
node.set_inner_html(&old_node);
}
pub fn remove_element_by_class_name(class_name:&str){
let window = web_sys::window().expect("no global `window` exists");
let document = window.document().expect("should have a document on window");
let body = document.body().expect("document should have a body");
if let Ok(node) = body.query_selector(&format!(".{}",class_name)){
if let Some(n) = node{
n.remove();
}
}
}
pub async fn get_request(url:&str)->Result<String, reqwasm::Error>{
let resp = reqwasm::http::Request::get(&url).send().await?;
Ok(resp.text().await.unwrap().to_string())
}
pub fn blocking_get_request(url:&str)->Result<String, reqwasm::Error>{
let url = url.to_string();
let result = safina_executor::block_on(async move{
let url = format!("{}",url);
let res = get_request(&url);
res.await
}).unwrap();
Ok(result.to_string())
}
}