Skip to content
shouya edited this page May 4, 2024 · 6 revisions

This page lists the APIs available in the JavaScript runtime (for the js, modify_post, and modify_feed filters).

Logging

console.log(...)
console.error(...)

DOM

Starting from version 0.0.4. There is a custom set of DOM API accessible in the JS runtime. The DOM API can be used to query and manipulate feed's description which is often in html format.

Full API list:

class DOM {
    constructor(html_document: string);
    static parse_fragment(html_fragment: string): DOM;
    static parse_document(html_document: string): DOM;
    
    to_html(): string;
    select(css_selector: string): Node[];
}

class Node {
    attrs(): { [key: string]: string };
    attr(attr_name: string): string?;
    set_attr(attr_name: string, attr_value: string): void;
    unset_attr(attr_name: string): void;

    node_type(): "text" | "element" | "other";
    tag_name(): string?; // return null if not an element.

    inner_text(): string;
    inner_html(): string;
    outer_html(): string;
    set_inner_text(text: string): void;
    set_inner_html(fragment: string): void;
    set_outer_html(fragment: string): void;

    destroy(): void;

    previous_sibling(): Node?;
    next_sibling(): Node?;
    parent(): Node?;
    children(): Node[];

    select(css_selector: string): Node[];
}

Utility functions

util.decode_html(string): string?;
util.encode_html(string): string;
util.encode_url(string): string;
util.decode_url(string): string?;
util.encode_base64(string): string;
util.decode_base64(string): string?;

Fetch (unreleased)

type RequestParam = {
  method: "GET" | "POST" | "PUT" | "DELETE",
  headers: { [key: string]: string },
  body: string?
}

fetch(url: string, params?: RequestParam): Promise<Response>;

class Response {
  status: number,
  headers: { [key: string]: string },
  body: string | null

  json(): Object
}
Clone this wiki locally