Get information from Greasy Fork and do actions in it.
Dit script moet niet direct worden geïnstalleerd - het is een bibliotheek voor andere scripts om op te nemen met de meta-richtlijn // @require https://update.greasyfork.org/scripts/445697/1748148/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)
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 ScriptsQuery {
q?: Query,
page?: Page,
filter_locale?: FilterLocale,
sort?: "total_installs" | "ratings" | "created" | "updated" | "name",
by?: Id,
language: "js" | "css"
}
interface AdvancedScriptsQuery extends ScriptsQuery {
total_installs_operator?: "lt" | "gt" | "eq", // default gt
total_installs?: number, // default 0
daily_installs_operator?: "lt" | "gt" | "eq", // default gt
daily_installs?: number, // default 0
ratings_operator?: "lt" | "gt" | "eq", // default gt
ratings?: number, // from 0 to 1, default 0
created_operator?: "lt" | "gt" | "eq", // default gt
created?: string, // datetime string, default blank
updated_operator?: "lt" | "gt" | "eq", // default gt
updated?: string, // datetime string, default blank
entry_locales?: number[],
tz?: string // is validated by that regex: /^[A-Za-z0-9_+-]+\/[A-Za-z0-9_+-]+(?:\/[A-Za-z0-9_+-]+)?$/
}
interface ScriptsBySiteQuery extends ScriptsQuery {
site: '*' | string // accepts only ip addesses, hostnames and * (for all sites)
}
Same as ScriptsQuery, but has property set and doesn't have property 'by'.
type ScriptSetQuery = Omit<ScriptsQuery & { set: Id }, 'by'>
Same as ScriptsQuery, but doesn't have sorting by total_installs or ratings
interface LibrariesQuery {
q?: Query,
page?: Page,
filter_locale?: FilterLocale,
sort?: "created" | "updated" | "name",
by?: Id
}
interface UsersQuery {
q?: Query,
page?: Page,
sort?: "name" | "daily_installs" | "total_installs" | "ratings" | "scripts" | "created_scripts" | "updated_scripts",
authors?: boolean
}
interface Install {
id: Id,
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 max 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
})
await GF.getScripts({
by: 1 // get scripts by user with id of 1
})
await GF.getScripts({
language: "css" // get only user styles
})
Queries 100 scripts max at once using specified parameters
await GF.getScriptsAdvanced({
total_installs: 1000 // get scripts that have min of 1000 total installs
})
await GF.getScriptsAdvanced({
daily_installs: 100 // get scripts that have min of 1000 daily installs
})
Has same properties as getScripts, but itself requires site property.
Note: write '*' to get scripts that work at all of the sites
await GF.getScriptsBySite({
site: 'youtube.com' // get scripts that work on 'youtube.com'
})
await GF.getScriptsBySite({
site: '*' // get scripts work on all of the sites
})
await GF.getSitesPopularity()
/* Example:
{
"example.com": 123,
"example.org": 456,
"example.net": 789
}
*/
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.getLibraries({
by: 1 // get libraries by user with id of 1
})
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 max 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
})