Core APIs
These APIs are shared between all types of extension: content providers and plugins.
Last updated
These APIs are shared between all types of extension: content providers and plugins.
Last updated
Create a core.d.ts
file containing the following content:
console.log()
console.warn()
console.error()
/// <reference path="./core.d.ts" />
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1")
const data = res.json()
Parse HTML
const $ = LoadDoc(`
<section id="content">
<article class="post" data-id="1">
<h2>First Post</h2>
<p>This is the first post.</p>
<a href="https://example.com/first-post" class="read-more">Read more</a>
</article>
<article class="post" data-id="2">
<h2>Second Post</h2>
<p>This is the second post.</p>
<a href="https://example.com/second-post" class="read-more">Read more</a>
</article>
<article class="post" data-id="3">
<h2>Third Post</h2>
<p>This is the third post.</p>
<a href="https://example.com/third-post" class="read-more">Read more</a>
</article>
</section>
`);
const titles = $("section")
.children("article.post")
.filter((i, e) => e.attr("data-id") !== "1")
.map((i, e) => e.children("h2").text())
console.log(titles) // [Second Post, Third Post]
let message = "seanime";
let key = CryptoJS.enc.Utf8.parse("secret key");
console.log("Message:", message);
let encrypted = CryptoJS.AES.encrypt(message, key);
console.log("Encrypted:", encrypted); // map[iv toString]
console.log("Encrypted.toString():", encrypted.toString()); // AoHrnhJfbRht2idLHM82WdkIEpRbXufnA6+ozty9fbk=
console.log("Encrypted.toString(CryptoJS.enc.Base64):", encrypted.toString(CryptoJS.enc.Base64)); // AoHrnhJfbRht2idLHM82WdkIEpRbXufnA6+ozty9fbk=
let decrypted = CryptoJS.AES.decrypt(encrypted, key);
console.log("Decrypted:", decrypted.toString(CryptoJS.enc.Utf8));
let iv = CryptoJS.enc.Utf8.parse("3134003223491201");
encrypted = CryptoJS.AES.encrypt(message, key, { iv: iv });
console.log("Encrypted:", encrypted); // map[iv toString]
decrypted = CryptoJS.AES.decrypt(encrypted, key);
console.log("Decrypted without IV:", decrypted.toString(CryptoJS.enc.Utf8)); // "" <- Nothing
decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv });
console.log("Decrypted with IV:", decrypted.toString(CryptoJS.enc.Utf8)); // seanime
let a = CryptoJS.enc.Utf8.parse("Hello, World!");
console.log(a); // // Uint8Array [72 101 108 108 ...]
let b = CryptoJS.enc.Base64.stringify(a);
console.log(b); // SGVsbG8sIFdvcmxkIQ==
let c = CryptoJS.enc.Base64.parse(b);
console.log(c); // Uint8Array [72 101 108 108 ...]
let d = CryptoJS.enc.Utf8.stringify(c);
console.log(d); // Hello, World!
The $replace
function is used to overwrite properties of an object within an event.
This only works on values that are not undefined and on values that are references under the hood.
$app.onGetAnime((e) => {
if(e.anime.id === 130003) {
console.log(e.anime.title)
// {
// "english": "Bocchi the Rock!",
// "romaji": "Bocchi the Rock!",
// "userPreferred": "Bocchi the Rock!"
// }
e.anime.title = { "english": "The One Piece is Real" }
console.log(e.anime.title)
// {
// "english": "The One Piece is Real",
// "romaji": "Bocchi the Rock!",
// "userPreferred": "Bocchi the Rock!"
// }
// ✅ Overwrite the entire 'title' object
$replace(e.anime.title, { "english": "The One Piece is Real" })
console.log(e.anime.title)
// {
// "english": "The One Piece is Real",
// "romaji": undefined,
// "userPreferred": undefined
// }
e.anime.synonyms[0] = "The One Piece" // ✅ Works
$replace(e.anime.synonyms[0], "The One Piece") // ✅ Works
// ⛔️ Doesn't work because 'id' is not a reference under the hood
$replace(e.anime.id, 22)
// ⛔️ Doesn't work if is 'bannerImage' undefined
$replace(e.anime.bannerImage, "abc")
}
e.next();
})
// Get a magnet link from a torrent file content
const res = await fetch("http://[...].torrent")
const content = res.text()
$torrentUtils.getMagnetLinkFromTorrentData(content)
Converts binary data to string.
const uint8Array = new Uint8Array(new ArrayBuffer(5));
uint8Array[0] = 104;
uint8Array[1] = 101;
uint8Array[2] = 108;
uint8Array[3] = 108;
uint8Array[4] = 111;
console.log($toString(uint8Array)); // hello
Similar to the Web API TextEncoder.encode
const b = $toBytes("hello")
console.log(b); // Uint8Array [104, 101, 108, 108, 111]
console($toString(b)); // hello
Use carefully
// sleeps for 1s
$sleep(1000)
Filename parser
data := $habari.parse("Hyouka (2012) S1-2 [BD 1080p HEVC OPUS] [Dual-Audio]")
console.log(data.title) // Hyouka
console.log(data.formatted_title) // Hyouka (2012)
console.log(data.year) // 2012
console.log(data.season_number) // ["1", "2"]
console.log(data.video_resolution) // 1080p