traQ UserScript Library template

template of QUSL

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

Bạn sẽ cần cài đặt một tiện ích mở rộng như Tampermonkey hoặc Violentmonkey để cài đặt kịch bản này.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

Tác giả
TwoSquirrels
Cài đặt hàng ngày
0
Số lần cài đặt
0
Đánh giá
0 0 0
Phiên bản
0.2
Đã tạo
13-01-2025
Đã cập nhật
13-01-2025
Kích thước
5 KB
Giấy phép
MIT
Áp dụng cho

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 = "おいすー";
  });
});