Extract the `@url` / `@navigate` auto-navigation target from a script's leading comment block, if present. Only lines at the very top of the file that are comments (`//`, `/*`, or a `*` JSDoc continuation line) are considered; scanning stops at the first blank-then-non-comment line. A trailing `*/` on single-line block comments (e.g. `/* @url https://example.com */`) is stripped so it isn't captu
(content: &str)
| 191 | /// (e.g. `/* @url https://example.com */`) is stripped so it isn't captured |
| 192 | /// as part of the URL. |
| 193 | fn parse_script_url_marker(content: &str) -> Option<String> { |
| 194 | for line in content.lines() { |
| 195 | let trimmed = line.trim(); |
| 196 | if trimmed.is_empty() { |
| 197 | continue; |
| 198 | } |
| 199 | let comment = trimmed |
| 200 | .strip_prefix("//") |
| 201 | .or_else(|| trimmed.strip_prefix("/*")) |
| 202 | .or_else(|| trimmed.strip_prefix('*'))?; |
| 203 | |
| 204 | let mut comment = comment.trim(); |
| 205 | if let Some(stripped) = comment.strip_suffix("*/") { |
| 206 | comment = stripped.trim(); |
| 207 | } |
| 208 | |
| 209 | if let Some(rest) = comment.strip_prefix("@url") { |
| 210 | return Some(rest.trim().to_string()); |
| 211 | } |
| 212 | if let Some(rest) = comment.strip_prefix("@navigate") { |
| 213 | return Some(rest.trim().to_string()); |
| 214 | } |
| 215 | } |
| 216 | None |
| 217 | } |
| 218 | |
| 219 | /// Run a local JavaScript file inside the page context |
| 220 | pub async fn run_script( |