# Class: FrontendScriptApi

## FrontendScriptApi

Source:
  - services/frontend_script_api.js, line 21

### Members

#### $container

##### Properties:

Name | Type | Description
--- | --- | ---
`container` | jQuery | of all the rendered script content

Source:
  - services/frontend_script_api.js, line 25

#### currentNote

##### Properties:

Name | Type | Description
--- | --- | ---
`note` | object | where script is currently executing

Source:
  - services/frontend_script_api.js, line 30

#### originEntity

##### Properties:

Name | Type | Description
--- | --- | ---
`entity` | object | null | whose event triggered this execution

Source:
  - services/frontend_script_api.js, line 32

#### StandardWidget

##### Properties:

Type | Description
--- | ---
StandardWidget |

Source:
  - services/frontend_script_api.js, line 41

#### startNote

##### Properties:

Name | Type | Description
--- | --- | ---
`note` | object | where script started executing

Source:
  - services/frontend_script_api.js, line 28

#### tabContext

##### Properties:

Type | Description
--- | ---
TabContext | null | experimental!

Source:
  - services/frontend_script_api.js, line 38

### Methods

#### activateNewNote(notePath) → {Promise.<void>}

Activates newly created note. Compared to this.activateNote() also refreshes tree.

##### Parameters:

Name | Type | Description
--- | --- | ---
`notePath` | string | (or noteId)

Source:
  - services/frontend_script_api.js, line 66

##### Returns:

Type
  Promise.<void>

#### activateNote(notePath) → {Promise.<void>}

Activates note in the tree and in the note detail.

##### Parameters:

Name | Type | Description
--- | --- | ---
`notePath` | string | (or noteId)

Source:
  - services/frontend_script_api.js, line 50

##### Returns:

Type
  Promise.<void>

#### addButtonToToolbar(opts)

Adds new button the the plugin area.

##### Parameters:

Name | Type | Description
--- | --- | ---
`opts` | ToolbarButtonOptions |

Source:
  - services/frontend_script_api.js, line 85

#### bindGlobalShortcut(keyboardShortcut, handler)

##### Parameters:

Name | Type | Description
--- | --- | ---
`keyboardShortcut` | string | e.g. "ctrl+shift+a"
`handler` | function |

Source:
  - services/frontend_script_api.js, line 384

#### createNoteLink(notePath, noteTitleopt)

Create note link (jQuery object) for given note.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`notePath` | string |  | (or noteId)
`noteTitle` | string | <optional> | if not present we'll use note title

Source:
  - services/frontend_script_api.js, line 291

#### formatDateISO(date) → {string}

##### Parameters:

Name | Type | Description
--- | --- | ---
`date` | Date |

Source:
  - services/frontend_script_api.js, line 235

##### Returns:

date in YYYY-MM-DD format

Type
  string

#### getActiveTabNote() → {NoteFull}

Source:
  - services/frontend_script_api.js, line 297

##### Returns:

active note (loaded into right pane)

Type
  NoteFull

#### getActiveTabNotePath() → {Promise.<(string|null)>}

Source:
  - services/frontend_script_api.js, line 303

##### Returns:

returns note path of active note or null if there isn't active note

Type
  Promise.<(string|null)>

#### getDateNote(date) → {Promise.<NoteShort>}

Returns date-note. If it doesn't exist, it is automatically created.

##### Parameters:

Name | Type | Description
--- | --- | ---
`date` | string | e.g. "2019-04-29"

Source:
  - services/frontend_script_api.js, line 350

##### Returns:

Type
  Promise.<NoteShort>

#### getInstanceName() → {string}

Instance name identifies particular Trilium instance. It can be useful for scripts if some action needs to happen on only one specific instance.

Source:
  - services/frontend_script_api.js, line 228

##### Returns:

Type
  string

#### getMonthNote(month) → {Promise.<NoteShort>}

Returns month-note. If it doesn't exist, it is automatically created.

##### Parameters:

Name | Type | Description
--- | --- | ---
`month` | string | e.g. "2019-04"

Source:
  - services/frontend_script_api.js, line 359

##### Returns:

Type
  Promise.<NoteShort>

#### getNote(noteId) → {Promise.<NoteShort>}

Returns note by given noteId. If note is missing from cache, it's loaded. *

##### Parameters:

Name | Type | Description
--- | --- | ---
`noteId` | string |

Source:
  - services/frontend_script_api.js, line 200

##### Returns:

Type
  Promise.<NoteShort>

#### getNotes(noteIds, silentNotFoundErroropt) → {Promise.<Array.<NoteShort>>}

Returns list of notes. If note is missing from cache, it's loaded. This is often used to bulk-fill the cache with notes which would have to be picked one by one otherwise (by e.g. createNoteLink())

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`noteIds` | Array.<string> |  |
`silentNotFoundError` | boolean | <optional> | don't report error if the note is not found

Source:
  - services/frontend_script_api.js, line 212

##### Returns:

Type
  Promise.<Array.<NoteShort>>

#### getTodayNote() → {Promise.<NoteShort>}

Returns date-note for today. If it doesn't exist, it is automatically created.

Source:
  - services/frontend_script_api.js, line 341

##### Returns:

Type
  Promise.<NoteShort>

#### getYearNote(year) → {Promise.<NoteShort>}

Returns year-note. If it doesn't exist, it is automatically created.

##### Parameters:

Name | Type | Description
--- | --- | ---
`year` | string | e.g. "2019"

Source:
  - services/frontend_script_api.js, line 368

##### Returns:

Type
  Promise.<NoteShort>

#### isNoteStillActive() → {boolean}

This method checks whether user navigated away from the note from which the scripts has been started. This is necessary because script execution is async and by the time it is finished, the user might have already navigated away from this page - the end result would be that script might return data for the wrong note.

Source:
  - services/frontend_script_api.js, line 314

##### Returns:

returns true if the original note is still loaded, false if user switched to another

Type
  boolean

#### onNoteChange(func)

##### Parameters:

Name | Type | Description
--- | --- | ---
`func` | function | callback called on note change as user is typing (not necessarily tied to save event)

Source:
  - services/frontend_script_api.js, line 322

#### parseDate(str) → {Date}

##### Parameters:

Name | Type | Description
--- | --- | ---
`str` | string |

Source:
  - services/frontend_script_api.js, line 242

##### Returns:

parsed object

Type
  Date

#### protectActiveNote()

Source:
  - services/frontend_script_api.js, line 333

#### refreshActiveTab() → {Promise.<void>}

Refresh active tab

Source:
  - services/frontend_script_api.js, line 274

##### Returns:

Type
  Promise.<void>

#### refreshAllTabs() → {Promise.<void>}

Refresh current tab

Source:
  - services/frontend_script_api.js, line 282

##### Returns:

Type
  Promise.<void>

#### refreshTree() → {Promise.<void>}

Refresh tree

Source:
  - services/frontend_script_api.js, line 266

##### Returns:

Type
  Promise.<void>

#### reloadNotes(noteIds)

Update frontend tree (note) cache from the backend.

##### Parameters:

Name | Type | Description
--- | --- | ---
`noteIds` | Array.<string> |

Source:
  - services/frontend_script_api.js, line 220

#### runOnServer(script, params) → {Promise.<*>}

Executes given anonymous function on the server. Internally this serializes the anonymous function into string and sends it to backend via AJAX.

##### Parameters:

Name | Type | Description
--- | --- | ---
`script` | string | script to be executed on the backend
`params` | Array.<?> | list of parameters to the anonymous function to be send to backend

Source:
  - services/frontend_script_api.js, line 135

##### Returns:

return value of the executed function on the backend

Type
  Promise.<*>

#### searchForNote(searchString) → {Promise.<(NoteShort|null)>}

This is a powerful search method - you can search by attributes and their values, e.g.: "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search

##### Parameters:

Name | Type | Description
--- | --- | ---
`searchString` | string |

Source:
  - services/frontend_script_api.js, line 188

##### Returns:

Type
  Promise.<(NoteShort|null)>

#### searchForNotes(searchString) → {Promise.<Array.<NoteShort>>}

This is a powerful search method - you can search by attributes and their values, e.g.: "@dateModified =* MONTH AND @log". See full documentation for all options at: https://github.com/zadam/trilium/wiki/Search

##### Parameters:

Name | Type | Description
--- | --- | ---
`searchString` | string |

Source:
  - services/frontend_script_api.js, line 170

##### Returns:

Type
  Promise.<Array.<NoteShort>>

#### setHoistedNoteId(noteId) → {Promise}

Hoist note. See https://github.com/zadam/trilium/wiki/Note-hoisting

##### Parameters:

Name | Type | Description
--- | --- | ---
`noteId` | string | set hoisted note. 'root' will effectively unhoist

Source:
  - services/frontend_script_api.js, line 377

##### Returns:

Type
  Promise

#### setupElementTooltip($el)

##### Parameters:

Name | Type | Description
--- | --- | ---
`$el` | object | jquery object on which to setup the tooltip

Source:
  - services/frontend_script_api.js, line 328

#### showError(message)

Show error message to the user.

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | string |

Source:
  - services/frontend_script_api.js, line 258

#### showMessage(message)

Show info message to the user.

##### Parameters:

Name | Type | Description
--- | --- | ---
`message` | string |

Source:
  - services/frontend_script_api.js, line 250

#### waitUntilSynced()

Source:
  - services/frontend_script_api.js, line 389