Script Rules
Rules
Script will be running in an async function, so
async/await
is ok to use there. Returning aPromise
at the end of script is ok as well.❌ Do not use following methods in script:
eval
,Function
,execScript
,setTimeout
,setInterval
. ✅ Usejiant.action.sleep
instead ofsetTimeout
andsetInterval
❌ Do not interact with content of target page directly, so do not use
window
anddocument
instance. ✅ You can get copy of content viajiant.get.dom
jiant.get.html
jiant.get.$
. ✅ You can interact with page using methodsjiant.action.*
.
Format of script parsing result
It is required to return an object with keys at the end of script:
// example script
//
// ... some parsing code
return {
items: [{
title: 'string',
link: 'string of valid URL',
description: 'optional string',
author: 'optional string',
pubDate: `optional
RFC822 formatted string
Date instance with timezone`,
contentHash: 'optional string'
}, {
...
}, {
...
}],
title: 'optional string',
pageTitle: 'optional string',
pageUrl: 'optional string of valid URL',
faviconUrl: 'optional string of valid URL',
}
- If not set, item's
contentHash
will be generated automatically by item'stitle
,link
,description
. It will be used in Deduplication. pageTitle
,pageUrl
,faviconUrl
will be original values of target page, if you do not want to replace them.
Reference: Configure (JSON)
{
"customParams": {
"private": false,
...
},
"INTERVAL_DEFAULT": 59,
...
}
customParams
- type:
object
When making or copying feeds with same code or temaple, custom configures of each should be inside of customParams
. Shared configures should outside.
Then when you batch override tasks with a copy, configures outside of customParams
will be overriden. customParams
of each will remain unchanged.
INTERVAL_DEFAULT
- type:
int
If a task sets the value in minute, when you make copy of it, copy's Checking Interval
will use this value instead of origin's.
DISABLE_AUTO_OPEN_PAGE_URL
- type:
boolean
At start of checking, task page URL
will be opened automatically. Then wait until Document.readyState
getting interactive
or complete
before script running.
If set true, you need to open an URL manully with jiant.action.pushURL
.
TIP
More infomation about page lifecycle.
DUPLICATE_CHECK_IN_MS
- Type:
int
After fetched an item and before saving, there is a duplication check with item's contentHash
. If found previous same item, the new one will be skipped when saving.
Sometime if you want to save duplicate item, you can set the DUPLICATE_CHECK_IN_MS
as "expire time" in millisecond.
if (DUPLICATE_CHECK_IN_MS && (previousItem.createdAt + DUPLICATE_CHECK_IN_MS < Date.now()))
, new duplicate item will be saved.
TIP
More infomation about Deduplication.
ALLOW_PARSED_ITEMS_EMPTY
- Type:
boolean
Script parsing result must return an object with an array:items
.
If no
items
, throwing error:No items returned
.If
items.length == 0
, throwing error:No items found.
The two errors are there to alert that script is not working properly.
When you want to disable the 2nd error (allow items.length == 0
), just enable ALLOW_PARSED_ITEMS_EMPTY
in configure.
ALLOW_REMOTE_CODE
- Type:
boolean
Enable remote code in this task, otherwise jiant.parse.plugin
and REMOTE_CONFIGURE_FOR_CHECKING
will not work.
REMOTE_CONFIGURE_FOR_CHECKING
- Type:
string
URL for remote configure JSON for checking.
TIP
- More infomation refers to Using Remote Code.
CustomParams in Configure (JSON)
private
- Type:
boolean
- If set true, script code and configure will not be accessible in public。
{
"customParams": {
"private": true
}
}
userAgent
- Type:
object
- Use custom User-Agent when feed checking.
- Randomly choose one if multiple values set.
- if
useLocalPool
enabled, values will be[...valuesInLocalPool, ...values]
. You can set User-Agent local pool in extension's navbar settings.
{
"customParams": {
"userAgent": {
"values": "Mozilla/5.0 (W.... \n XXXXXXXX", // one per line
"useLocalPool": false,
}
}
}
proxy
- Type:
object
- Use custom proxy when feed checking.
- Randomly choose one if multiple values set.
- if
useLocalPool
enabled, values will be[...valuesInLocalPool, ...values]
. You can set Proxy local pool in extension's navbar settings.
{
"customParams": {
"proxy": {
"hosts": "abc.com, xyz.com", // multiple separate with commas
"values": "SOCKS5 127.0.0.1:10089, XXXXXXX", // multiple separate with commas
"defaultValue": "DIRECT", // value when page URL does not match any host
"useLocalPool": false,
}
}
}
translate
- Type:
object
- Translate all parsed items'
title & description
to another language.
{
"customParams": {
"translate": {
// current valid language codes:
// 'en', 'zh', 'zh-Hant', 'fr', 'ru', 'de', 'es', 'pt', 'ja',
// 'it', 'fa', 'ar', 'vi', 'sv', 'nl', 'pl', 'ko', 'hi'
"toLang": "zh",
// @param toLang: required,
// destination language code for translation.
"fromLang": "",
// @param fromLang: optional,
// language code of origin content.
// If empty, it will be auto detected.
"provider": "",
// @param provider: optional, string,
// translation service provider.
// current valid values: 'GOOGLE' or 'MICROSOFT'
}
}
}
TIP
For more infomation and maually and flexibly using translation in script, please refer to Use Translation.
HEADER_VALUE_FETCHING_REMOTE_CODE
- Type:
string
- For server authentication when task in client fetching remote code.
TIP
More infomation refers to Using Remote Code.