Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export interface Page {
image: string | null;
/** the thumbnail text of a page.
* the maximum number of lines is 5.
*/ descriptions: string[];
*/
descriptions: string[];
/** ページの最終更新日時 */ updated: number;
/** Date last visitedに使われる最終アクセス日時 */ accessed: number;
}
Expand All @@ -36,6 +37,7 @@ export type ProjectId = string;
/** the formatted string
*
* format rule:
*
* - UPPER CASE -> upper_case
*/
export type StringLc = string;
14 changes: 14 additions & 0 deletions layout.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/** Scrapboxのページの種類を表す文字列から`"page"`を除いたもの
*
* | String | Description |
* | ------ | ----------- |
* | list | トップページと全文検索結果ページ |
* | stream | streamページ |
* | error-page | 何らかのエラーが発生したときに遷移するページ |
* | new-project-page | 新規project作成ページ |
* | invitation-page | projectに参加するときに出てくるページ |
* | invitation-page | projectに参加するときに出てくるページ |
* | settings-* | ユーザー設定ページ |
* | project-settings-* | projectの設定ページ |
*/
export type PartialLayout =
| "launch"
| "error-page"
Expand Down Expand Up @@ -28,4 +41,5 @@ export type PartialLayout =
| "project-settings-upload-page"
| "project-settings-billing-page";

/** Scrapboxのページの種類を表す文字列 */
export type Layout = "page" | PartialLayout;
5 changes: 5 additions & 0 deletions pageMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export declare class PageMenu extends BaseStore {
public initialize(): void;
public reset(): void;
public pageMenu(menuName?: string): PageMenu;
/** Add a new Page Menu button
*
* @param init information used for a Page Menu button
*/
public addMenu(init: AddMenuInit): void;
/** Add a menu item to a particular Page Menu button
*
Expand All @@ -33,6 +37,7 @@ export declare class PageMenu extends BaseStore {
public addItem(item: Item): void;
/** Add a separator to a particular Page Menu button */
public addSeparator(): void;
/** remove all custom items from a particular Page Menu button */
public removeAllItems(): void;

public menuName: string;
Expand Down
36 changes: 33 additions & 3 deletions userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,71 @@ import type { EventEmitter } from "./deps/events.ts";
export type { EventEmitter, Layout, ParsedLine, PartialLayout, StringLc };
export * from "./pageMenu.ts";

/** Type definition of `window.scrapbox` */
export type Scrapbox =
& EventEmitter
& {
PageMenu: {
/** get a particular Page Menu
*
* @param menuName Page Menu name to get. If it is set to "default" or undefined, return the default page Menu
*/
(menuName?: string): PageMenu;
/** Add a new Page Menu button
*
* @param init information used for a Page Menu button
*/
addMenu: (init: AddMenuInit) => void;
/** Add a menu item to a particular Page Menu button
/** Add a menu item to the default Page Menu button
*
* @param item information used for a menu item
*/
addItem: (item: Item) => void;
/** Add a separator to a particular Page Menu button */
/** Add a separator to the default Page Menu button */
addSeparater: () => void;
/** remove all custom items from the default Page Menu button */
removeAllItems: () => void;
};
PopupMenu: {
/** Add a popup button
*
* @param button button settings
*/
addButton: (button: {
/** ボタンのタイトル
*
* 関数を設定して、選択範囲が変わるたびにタイトルを変更させる事もできる
*/
title: string | ((text: string) => (string | undefined));
/** ボタンをクリックしたときに実行する処理
*
* @return ここで返した文字列で選択範囲を置換し、popupを閉じる。`undefined`を返した場合は何もしない。popupも閉じない
*/
onClick: (text: string) => (string | undefined);
}) => void;
};
TimeStamp: TimeStamp;
Project: {
/** get the current project name */
get name(): string;
/** get the dictionary used for comupletion */
get pages(): PageBrief[];
};
}
& (
{
/** the current page layout */
Layout: "page";
Page: {
/** get the current page lines data */
get lines(): ParsedLine[];
/** get the current page title */
get title(): string;
/** get the current page id */
get id(): string;
};
} | {
/** the current page layout */
Layout: PartialLayout;
Page: {
get lines(): null;
Expand All @@ -56,12 +85,13 @@ export type Scrapbox =
}
);

/** 入力補完に使われる辞書 */
export interface PageBrief {
/** true when the page has contents */ exists: boolean;
/** whether the page contains any image */ hasIcon?: boolean;
/** the page id */ id: string;
/** the page title */ title: string;
titleLc: StringLc;
/** lower case style of the page title */ titleLc: StringLc;
/** updated time */ updated: number;
}

Expand Down