Skip to content

Commit fbf8fa2

Browse files
docs: translate remaining Japanese text to English
- Translate test data in findMetadata.test.ts - Translate test strings in spotify.test.ts and youtube.test.ts - Enhance README.md documentation with clearer structure - Maintain consistent English terminology across files Part of PR #215 documentation translation effort.
1 parent da079e1 commit fbf8fa2

File tree

5 files changed

+85
-41
lines changed

5 files changed

+85
-41
lines changed

README.md

Lines changed: 54 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,75 @@ UNOFFICIAL standard module for Scrapbox UserScript
77

88
## Getting Started
99

10-
This library serves as an unofficial standard library for developing Scrapbox userscripts.
10+
This library serves as an unofficial standard library for developing Scrapbox userscripts. It provides a comprehensive set of utilities for interacting with Scrapbox's features, including REST API operations, browser interactions, and common utilities.
1111

1212
### Installation
1313

1414
1. Bundler Configuration
15-
To use this library, you need to configure a bundler. You can set it up using one of the following methods:
15+
This library is distributed through JSR (JavaScript Registry) and requires a bundler configuration. Follow these steps:
1616

17+
a. Configure your bundler to use JSR:
18+
- For esbuild: Add JSR to your import map
19+
- For other bundlers: Refer to your bundler's JSR integration documentation
20+
21+
b. Import the library:
1722
```typescript
18-
// Using JSR
23+
// Import the entire library
1924
import { ... } from "jsr:@cosense/std";
20-
// Or import specific features
21-
import { ... } from "jsr:@cosense/std/rest";
22-
import { ... } from "jsr:@cosense/std/browser";
25+
26+
// Or import specific modules (recommended)
27+
import { getPage, getLines } from "jsr:@cosense/std/rest";
28+
import { getLines, press } from "jsr:@cosense/std/browser/dom";
2329
```
2430

25-
2. Required Modules
26-
Import the modules based on your needs:
27-
- REST API operations: `rest` module
28-
- Browser operations: `browser` module
29-
- Utilities: `title`, `parseAbsoluteLink`, etc.
31+
2. Module Organization
32+
The library is organized into the following main modules:
33+
34+
- `rest/`: API operations for Scrapbox REST endpoints
35+
- Page operations
36+
- Project management
37+
- User authentication
38+
- `browser/`: Browser-side operations
39+
- DOM manipulation
40+
- WebSocket communication
41+
- Event handling
42+
- Core utilities:
43+
- `title`: Title parsing and formatting
44+
- `parseAbsoluteLink`: External link analysis
45+
- Additional helper functions
3046

3147
## Examples
3248

3349
### Basic Usage
3450

3551
1. Retrieving Page Information
3652
```typescript
53+
// Get page content and metadata
3754
import { getPage } from "jsr:@cosense/std/rest";
3855

3956
const page = await getPage("projectName", "pageName");
40-
console.log(page.title);
57+
console.log(page.title); // Access page title
58+
console.log(page.lines); // Access page content as lines
59+
console.log(page.descriptions); // Access page descriptions
4160
```
4261

4362
2. DOM Operations
4463
```typescript
45-
import { getLines } from "jsr:@cosense/std/browser/dom";
64+
// Interact with the current page's content
65+
import { getLines, press } from "jsr:@cosense/std/browser/dom";
4666

67+
// Get all lines from the current page
4768
const lines = getLines();
4869
console.log(lines.map(line => line.text));
70+
71+
// Simulate keyboard input
72+
await press("Enter"); // Add a new line
73+
await press("Tab"); // Indent the line
4974
```
5075

5176
3. External Link Analysis
5277
```typescript
78+
// Parse external links (YouTube, Spotify, etc.)
5379
import { parseAbsoluteLink } from "jsr:@cosense/std";
5480
import type { LinkNode } from "@progfay/scrapbox-parser";
5581

@@ -59,13 +85,24 @@ const link: LinkNode = {
5985
href: "https://www.youtube.com/watch?v=xxxxx",
6086
content: ""
6187
};
88+
89+
// Parse and handle different link types
6290
const parsed = parseAbsoluteLink(link);
6391
if (parsed.type === "youtube") {
64-
console.log(parsed.videoId);
92+
console.log(parsed.videoId); // YouTube video ID
93+
console.log(parsed.timestamp); // Video timestamp (if present)
94+
} else if (parsed.type === "spotify") {
95+
console.log(parsed.trackId); // Spotify track ID
6596
}
6697
```
6798

6899
### Important Notes
69-
- You must use a bundler to use this library
70-
- TypeScript type definitions are available
71-
- For more detailed examples, refer to the [Examples](https://github.com/takker99/scrapbox-userscript-std/tree/main/examples) directory
100+
- This library requires a bundler for use in userscripts
101+
- Full TypeScript support with type definitions included
102+
- Comprehensive error handling with type-safe responses
103+
- For more examples and use cases, see the [Examples](https://github.com/takker99/scrapbox-userscript-std/tree/main/examples) directory
104+
105+
### Additional Resources
106+
- [JSR Package Page](https://jsr.io/@cosense/std)
107+
- [API Documentation](https://jsr.io/@cosense/std/doc)
108+
- [GitHub Repository](https://github.com/takker99/scrapbox-userscript-std)

browser/websocket/__snapshots__/findMetadata.test.ts.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ export const snapshot = {};
33
snapshot[`findMetadata() 1`] = `
44
[
55
[
6-
"ふつうの",
7-
"リンク2",
6+
"normal",
7+
"link2",
88
"hashtag",
99
],
1010
[
11-
"/help-jp/外部リンク",
11+
"/help-en/external-link",
1212
],
1313
[
1414
"scrapbox",
@@ -21,13 +21,13 @@ snapshot[`findMetadata() 1`] = `
2121
"65e7f4413bc95600258481fb",
2222
],
2323
[
24-
"助けてhelpfeel!!",
24+
"Need help with setup!!",
2525
],
2626
[
27-
"名前 [scrapbox.icon]",
28-
"住所 [リンク2]を入れること",
29-
"電話番号 #をつけてもリンクにならないよ",
30-
"自分の強み 3個くらい列挙",
27+
"Name [scrapbox.icon]",
28+
"Address Add [link2] here",
29+
"Phone Adding # won't create a link",
30+
"Strengths List about 3 items",
3131
],
3232
]
3333
`;

browser/websocket/_codeBlock.test.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@ import { assertEquals } from "@std/assert";
22
import { assertSnapshot } from "@std/testing/snapshot";
33
import { extractFromCodeTitle } from "./_codeBlock.ts";
44

5+
/**
6+
* Tests for code block title parsing functionality
7+
*
8+
* These tests verify the parsing of code block titles in various formats:
9+
* - Valid formats: code:filename.ext(param), code:filename(param), code:filename.ext
10+
* - Invalid formats: trailing dots, incorrect prefixes, non-code blocks
11+
*/
512
Deno.test("extractFromCodeTitle()", async (t) => {
613
await t.step("accurate titles", async (st) => {
714
const titles = [
8-
"code:foo.extA(extB)",
9-
" code:foo.extA(extB)",
10-
" code: foo.extA (extB)",
11-
" code: foo (extB) ",
12-
" code: foo.extA ",
13-
" code: foo ",
14-
" code: .foo ",
15+
"code:foo.extA(extB)", // Basic format: no spaces
16+
" code:foo.extA(extB)", // Leading space before code:
17+
" code: foo.extA (extB)", // Spaces around components
18+
" code: foo (extB) ", // Extension omitted, has parameter
19+
" code: foo.extA ", // Extension only, no parameter
20+
" code: foo ", // Basic name only
21+
" code: .foo ", // Leading dot in name
1522
];
1623
for (const title of titles) {
1724
await st.step(`"${title}"`, async (sst) => {
@@ -22,10 +29,10 @@ Deno.test("extractFromCodeTitle()", async (t) => {
2229

2330
await t.step("inaccurate titles", async (st) => {
2431
const nonTitles = [
25-
" code: foo. ", // Not recognized as a code block due to trailing dot without extension
32+
" code: foo. ", // Invalid: Trailing dot without extension is not a valid code block format
2633
// Returning `null` is expected as this format is invalid
27-
"any:code: foo ",
28-
" I'm not code block ",
34+
"any:code: foo ", // Invalid: Must start with exactly "code:" prefix
35+
" I'm not code block ", // Invalid: Not a code block format at all
2936
];
3037
for (const title of nonTitles) {
3138
await st.step(`"${title}"`, async () => {

browser/websocket/findMetadata.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ code:code
1919
Links [link] and images [https://scrapbox.io/files/65f29c0c9045b5002522c8bb.svg] in code blocks should be ignored
2020
2121
22-
? Help needed with setup!!
22+
? Need help with setup!!
2323
2424
table:infobox
2525
Name [scrapbox.icon]
2626
Address Add [link2] here
27-
Phone Adding # won't make it a link
27+
Phone Adding # won't create a link
2828
Strengths List about 3 items
2929
3030
#hashtag is recommended
31-
[/forum-jp] links should be excluded
32-
[/help-jp/] too
31+
[/forum-en] links should be excluded
32+
[/help-en/] too
3333
[/icons/example.icon][takker.icon]
34-
[/help-jp/external-link]
34+
[/help-en/external-link]
3535
3636
Prepare thumbnail
3737
[https://scrapbox.io/files/65f29c24974fd8002333b160.svg]

parser/youtube.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Deno.test("youtube links", async (t) => {
6262
await assertSnapshot(
6363
t,
6464
parseYoutube(
65-
"ほげほげ",
65+
"test_text",
6666
),
6767
);
6868
await assertSnapshot(

0 commit comments

Comments
 (0)