Skip to content

Commit f539930

Browse files
Implement function of get-url
1 parent 978e215 commit f539930

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ web-sys = { version = "0.3.69", features = [
1414
"HtmlElement",
1515
"HtmlInputElement",
1616
"CssStyleDeclaration",
17+
"Location"
1718
] }
1819
js-sys = "0.3"

src/lib.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
use wasm_bindgen::prelude::*;
22
use web_sys::js_sys::Function;
33
use web_sys::{Document, Element, HtmlElement, HtmlInputElement};
4-
5-
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
6-
// allocator.
7-
#[cfg(feature = "wee_alloc")]
8-
#[global_allocator]
9-
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
4+
use wasm_bindgen::JsCast;
105

116
#[wasm_bindgen]
127
pub fn run_stack(src: &str) -> Result {
@@ -1104,6 +1099,17 @@ impl Executor {
11041099
.expect("チノちゃん「うるさいですね...」");
11051100
}
11061101

1102+
"get-url" => {
1103+
// Access the window object
1104+
let window = web_sys::window().expect("no global `window` exists");
1105+
1106+
// Access the current URL
1107+
let location = window.location();
1108+
1109+
// Get the full URL as a string
1110+
self.stack.push(Type::String(location.href().expect("should have href")))
1111+
}
1112+
11071113
// If it is not recognized as a command, use it as a string.
11081114
_ => self.stack.push(Type::String(command)),
11091115
}

0 commit comments

Comments
 (0)