traQ UserScript Library template

template of QUSL

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

Autore
TwoSquirrels
Installazioni giornaliere
0
Installazioni totali
0
Valutazione
0 0 0
Versione
0.2
Creato il
13/01/2025
Aggiornato il
13/01/2025
Dimensione
4,69 KB
Licenza
MIT
Applica a

traQ UserScript Library template

QUSL は traQ 用のユーザースクリプトの制作を支援するライブラリです。このテンプレートをコピーして使ってください。

機能一覧

qusl というグローバルオブジェクトに色々生やしています。initQusl() で QUSL の初期化とこのオブジェクトの Promise の取得ができます。このライブラリを複数のユーザースクリプトが使っていてもこのオブジェクトは共有されます。

qusl.SimpleEventEmitter

QUSL で使用しているシンプルな EventEmitter クラスです。qusl 自体がこのクラスのインスタンスです。このクラスの使い方はコード内のコメントを参照してください。

qusl.index

traQ の index-*.js からエクスポートされている物の配列を格納しています。元が minify されたコードなので、名前で検索ができないことに注意してください。

qusl.apis

traQ の API クライアントです。ここに生えているメソッドから traQ API が叩けます。

またこの API クライアントに生えているメソッドは全てフックしていて、qusl.on("メソッド名", async (args) => {}) などで API リクエストの検出・リクエストの上書き・キャンセル等ができ、qusl.on("after.メソッド名", async (args, response) => {}) などで API レスポンスの検出・レスポンスの上書き等ができるようになっています。

サンプルコード

// Write your code here!

の部分を以下のように書き換えます。

全ての投稿の語尾に「にゃ」を付ける

initQusl().then((qusl) => {
  qusl.on("postMessage", async (args) => {
    args[1].content += "にゃ";
  });
});

全てのユーザーの自己紹介文を「おいすー」にする

initQusl().then((qusl) => {
  qusl.on("after.getUser", async (args, response) => {
    response.data.bio = "おいすー";
  });
});