Get information from Greasy Fork and do actions in it.
אין להתקין סקריפט זה ישירות. זוהי ספריה עבור סקריפטים אחרים // @require https://update.greasyfork.org/scripts/445697/1747795/Greasy%20Fork%20API.js
Get data from Greasy Fork, or/and do actions on Greasy Fork
Constructor only accepts one parameter, which determines if the hostname should be 'api.greasyfork.org' (pass down nothing since it is value by default or false to explicitly choose this one) or 'api.sleazyfork.org' (pass down true for this one)
const GF = new GreasyFork()
That's it for setting up the instance.
These types are not real typescript types, but rather just their representation. (I used zod for runtime types)
Positive integer or numeric string that doesn't start with 0 (regex for the string: /^(?!0)\d+$/)
An optional string
An optional integer
An optional boolean
interface ScriptsQuerySchema {
q?: QueryFormat,
page?: PageFormat,
filter_locale?: FilterLocaleFormat
sort?: "total_installs" | "ratings" | "created" | "updated" | "name"
}
Same as ScriptsQuerySchema, but has property set which has type IdStringFormat
interface ScriptSetsQuerySchema extends ScriptsQuerySchema {
set: IdStringFormat
}
Same as ScriptsQuerySchema, but doesn't have sorting by total_installs or ratings
interface LibrariesQuerySchema {
q?: string,
page?: number,
sort?: "created" | "updated" | "name"
}
interface UsersQuerySchema {
q?: QueryFormat,
page?: PageFormat,
sort?: "name" | "daily_installs" | "total_installs" | "ratings" | "scripts" | "created_scripts" | "updated_scripts",
authors?: boolean
}
interface InstallSchema {
id: IdStringFormat,
type?: "js" | "css" // "js" by default
}
Contains methods to get particular script information. (for example script history)
script property):Gets info about the script
const data = await GF.script.getData(1)
/* Response Example:
{
"id": 1,
"daily_installs": 0,
"total_installs": 311,
"fan_score": "82.4",
"good_ratings": 18,
"ok_ratings": 0,
"bad_ratings": 0,
"created_at": "2014-02-18T19:51:43.000Z",
"code_updated_at": "2023-11-22T00:50:37.000Z",
"namespace": "http://userstyles.org",
"support_url": null,
"contribution_url": null,
"contribution_amount": null,
"users": [
{
"id": 1,
"name": "JasonBarnabe",
"created_at": "2014-02-18T19:49:27.000Z",
"url": "https://greasyfork.org/users/1-jasonbarnabe"
}
],
"name": "Greasemonkey/Tampermonkey/Violentmonkey test style",
"description": "If you install this and all text turns red, then things are working.",
"url": "https://greasyfork.org/scripts/1-greasemonkey-tampermonkey-violentmonkey-test-style",
"code_url": "https://update.greasyfork.org/scripts/1/GreasemonkeyTampermonkeyViolentmonkey%20test%20style.user.js",
"code_size": 981,
"license": null,
"version": "20231121.2",
"locale": "en"
}
Gets all the code of the user-script
const code = await GF.script.getCode(1)
/*
// ==UserScript==
// @name Greasemonkey/Tampermonkey/Violentmonkey test style
// @namespace http://userstyles.org
// @description If you install this and all text turns red, then things are working.
// @author JasonBarnabe
// @homepage http://greasyfork.org/scripts/1
// @run-at document-start
// @version 20231121.2
// @include *
...
var node = document.createElement("style");
node.type = "text/css";
node.appendChild(document.createTextNode(css));
var heads = document.getElementsByTagName("head");
if (heads.length > 0) {
heads[0].appendChild(node);
} else {
// no head yet, stick it whereever
document.documentElement.appendChild(node);
}
}
})();
*/
Gets only the metadata of the user-script
const meta = await GF.script.getMeta(1)
/*
// ==UserScript==
// @name Greasemonkey/Tampermonkey/Violentmonkey test style
// @namespace http://userstyles.org
// @description If you install this and all text turns red, then things are working.
// @author JasonBarnabe
// @homepage http://greasyfork.org/scripts/1
// @run-at document-start
// @version 20231121.2
// @include *
// ==/UserScript==
*/
Gets version history of the user-script
const history = await GF.script.getHistory(1)
/*
[
{
"version": "20231121.2",
"created_at": "2023-11-22T00:50:38.000Z",
"url": "https://api.greasyfork.org/en/scripts/1-greasemonkey-tampermonkey-violentmonkey-test-style?version=1284072",
"code_url": "https://greasyfork.org/scripts/1-greasemonkey-tampermonkey-violentmonkey-test-style/code/GreasemonkeyTampermonkeyViolentmonkey%20test%20style.user.js?version=1284072"
},
...
{
"version": "1.20140218195143",
"created_at": "2014-02-18T19:51:43.000Z",
"url": "https://api.greasyfork.org/en/scripts/1-greasemonkey-tampermonkey-violentmonkey-test-style?version=1",
"code_url": "https://greasyfork.org/scripts/1-greasemonkey-tampermonkey-violentmonkey-test-style/code/GreasemonkeyTampermonkeyViolentmonkey%20test%20style.user.js?version=1"
}
]
*/
Gets stats of the user-script (installs, update checks)
/*
{
"2014-02-18": {
"installs": 1,
"update_checks": null
},
"2014-02-19": {
"installs": 5,
"update_checks": null
},
...
"2026-02-02": {
"installs": 0,
"update_checks": 0
},
"2026-02-03": {
"installs": 0,
"update_checks": 0
}
}
*/
Gets stats of the user-script (installs, update checks), but in csv format
const statsCsv = await GF.script.getStatsCsv(1)
/*
Response is too big to show
*/
Queries 100 scripts at once using specified parameters
await GF.getScripts() // just get top scripts
await GF.getScripts({ q: 'test' }) // get scripts with relevant keyword
await GF.getScripts({
q: 'test',
page: 2 // pages start from 1, not from 0
})
await GF.getScripts({
q: 'test',
filter_locale: false, // show all results regardless of the language
sort: 'name' // also, sort them by the name
})
Works same as getScripts, but just queries it from created sets.
GF.getScriptSet({
set: 1,
filter_locale: false,
sort: 'created',
page: 3
})
Queries the libraries.
The only real difference between script objects, is that value of code_url contains only the particular version of the library, not the always version.
await GF.getLibraries()
await GF.getLibraries({
page: 2
})
await GF.getLibraries({
q: 'GM',
sort: 'name'
})
await GF.getUserData(1)
/*
{
"id": 1,
"name": "JasonBarnabe",
"created_at": "2014-02-18T19:49:27.000Z",
"url": "https://greasyfork.org/users/1-jasonbarnabe",
"scripts": [...]
}
*/
Queries 100 users per request
await GF.getUsers()
await GF.getUsers({
q: 'john',
page: 2,
sort: 'name'
})
await GF.getUsers({
author: true, // query script authors
sort: 'created_scripts'
})
await GF.getUsers({
author: false // unlike await GF.getUsers(), this query skips the script authors
})
/*
[
{
"id": 1567324,
"name": "ambiel9687",
"created_at": "2026-02-03T08:13:26.000Z",
"url": "https://greasyfork.org/users/1567324-ambiel9687"
},
...
{
"id": 1567224,
"name": "Brandon Velasquez Morales",
"created_at": "2026-02-03T01:45:59.000Z",
"url": "https://greasyfork.org/users/1567224-brandon-velasquez-morales"
}
]
*/
Signs out of the Greasy Fork account
await GF.signOut()
Installs user-script.
Note: specifying "js" type for user-script doesn't do anything since this is default option
GF.installUserScript({
id: 437291
})
GF.installUserScript({
id: 439627,
type: 'css' // you can specify "js" for user-styles
})