Greasy Fork API

Get information from Greasy Fork and do actions in it.

Detta skript bör inte installeras direkt. Det är ett bibliotek för andra skript att inkludera med meta-direktivet // @require https://update.greasyfork.org/scripts/445697/1244619/Greasy%20Fork%20API.js

Skapare
NotYou
Version
2.0.1
Skapad
2022-05-29
Uppdaterad
2023-09-02
Licens
LGPL-3.0

Greasy Fork API

Version: 2.0.1 License: LGPL-3.0

Description:

Parse information on greasyfork.org

Dependencies

  • GM.xmlHttpRequest
  • GM.openInTab

Docs

Static Values

languages

A list of languages

GreasyFork.languages // ['ar', 'bg', 'cs', 'da', …]

version

Current Greasy Fork API version.

GreasyFork.version // e.g. '1.2.3'

Static Methods

parseScriptNode

Argument Required Type Description
node Yes HTMLElement A script node (element) that includes data attributes

Returns information about script based on it's element.

Note: If script node doesn't have rating info (such as libraries), then properties ratingsBad, raingsOk, ratingsGood will not be included.

GreasyFork.parseScriptNode(document.querySelector('[data-script-id="437291"]')) /* Example response:
{
    cssAvailableAsJs: false
    node: <li data-script-id="437291" …>
    ratingsBad: 0
    ratingsGood: 12
    ratingsOk: 1
    scriptAuthors: { 824432: "NotYou" }
    scriptCreatedDate: "2021-12-19"
    scriptDailyInstalls: 7
    scriptId: "437291"
    scriptLanguage: "js"
    scriptName: "Open-Source Alternative Redirector"
    scriptRatingScore: 71.7
    scriptTotalInstalls: 6738
    scriptType: "public"
    scriptUpdatedDate: "2023-01-09"
    scriptVersion: "11.2.0"
    sensitive: false
}
*/

parseScriptMetadata

Returns user-script's metadata.

Argument Required Type Description
code Yes string A user-script code that includes metadata // ==UserScript== ... // ==/UserScript==
GreasyFork.getScriptCode('437291').then(code => {
    const metadata = GreasyFork.parseScriptMetadata(code) // <-- This method

    console.log(metadata) // { author: "NotYou", name: "Open-Source Alternative Redirector", …}
})

getScriptData

Returns user-script's info.

Argument Required Type Description
id Yes string A string that only contains numeric characters.
GreasyFork.getScriptData('437291').then(data => {
    console.log(data)
    /*
    Example response:
    {
        bad_ratings: 0
        code_updated_at: "2023-01-09T11:03:42.000Z"
        code_url: "https://greasyfork.org/scripts/437291-open-source-alternativ…director/code/Open-Source%20Alternative%20Redirector.user.js"
        contribution_amount: null
        contribution_url: null
        created_at: "2021-12-19T16:18:00.000Z"
        daily_installs: 7
        deleted: false
        description: "Redirects you from proprietary web-services to ethical     alternatives(front-end)."
        fan_score: "71.7"
        good_ratings: 12
        id: 437291
        license: "GNU General Public License v3.0 or later"
        locale: "en"
        name: "Open-Source Alternative Redirector"
        namespace: "-"
        ok_ratings: 1
        support_url: null
        total_installs: 6738
        url: "https://greasyfork.org/scripts/437291-open-source-            alternative-redirector"
        users: Array [ {…} ]
        version: "11.2.0"
    }
    */
})

getScriptCode

Returns user-script's code.

Argument Required Type Description
id Yes string A string that only contains numeric characters.
isLibrary No boolean Set to true if script is library (Default: false).
GreasyFork.getScriptCode('437291').then(code => {
    console.log(code)
    /* Example response:
    // ==UserScript==
    // @name Open-Source Alternative Redirector
    …
    */
})

getScriptHistory

Returns user-script's history.

Argument Required Type Description
id Yes string A string that only contains numeric characters.
GreasyFork.getScriptHistory('437291').then(data => {
    console.log(data)
    /* Example response:
    [
        { version: '11.2.0', … }
        { version: '11.1.1', … }
        { version: '11.1.0', … }
        …
    ]
    */
})

getScriptStats

Returns user-script's stats history.

Argument Required Type Description
id Yes string A string that only contains numeric characters.
GreasyFork.getScriptStats('437291').then(data => {
    console.log(data)
    /* Example response:
    {
        '2021-12-19': { installs: 2, update_checks: 0 }
        '2021-12-20': { installs: 11, update_checks: 1 }
        '2021-12-21': { installs: 6, update_checks: 4 }
        …
    }
    */
})

getScriptSet

Returns set of scripts.

Argument Required Type Description
id Yes string A string that only contains numeric characters.
page No number Page of script set. (Default: 1)
GreasyFork.getScriptSet('1').then(data => {
    console.log(data)
    /* Example response:
    [
        { id: 436446, … }
        { id: 468633, … }
        { id: 438657, … }
        …
    ]
    */
})

getUserData

Returns user's data.

Argument Required Type Description
id Yes string A string that only contains numeric characters.
GreasyFork.getUserData('824432').then(data => {
    console.log(data)
    /* Example response:
    {
        id: 824432
        name: "NotYou"
        scripts: [ {…}, {…}, {…}, … ]
        url: "https://greasyfork.org/users/824432-notyou"
    }
    */
})

searchScripts

Returns result of search request to find user-scripts by query.

Note: enter blank string to just list popular scripts.

Argument Required Type Description
query Yes string A search query.
page No number Page of scripts search. (Default: 1)
GreasyFork.searchScripts('dark theme', 2).then(data => {
    console.log(data)
    /* Example response:
    [
        { id: 25563, … }
        { id: 371158, … }
        { id: 435764, … }
        …
    ]
    */
})

searchUsers

Returns result of search request to find users by query.

Note: enter blank string to just list new users.

Argument Required Type Description
query Yes string A search query.
page No number Page of users search. (Default: 1)
GreasyFork.searchUsers('notyou').then(data => {
    console.log(data)
    /* Example response:
    [
        { id: 824432, … }
        { id: 1087451, … }
        { id: 1079658, … }
        …
    ]
    */
})

installScript

Opens installation tab of entity (user-script / user-style).

Argument Required Type Description
id Yes string A string that only contains numeric characters.
type No 'js' or 'css' Language of entity. (Default: 'js')
GreasyFork.installScript('437291') // To install user-script
GreasyFork.installScript('439627', 'css') // to install user-style

/*
Note:
GreasyFork.installScript('437291') is same as
GreasyFork.installScript('437291', 'js')
*/

Instance

An instance can only be initialized at greasyfork.org or sleazyfork.org, at other hosts constructor will throw an error. To create an instance do this:

const GF = new GreasyFork()

Instance Methods

listScripts

Returns current script list and script list's type, if scirpt list doens't exist, then throws an error.

Note: There are only 3 script list's types. 1) browse — browsed user-scripts 2) user — script list in user page 3) unknown — in cases when script list is created in unknown list.

const GF = new GreasyFork()

GF.listScripts()
/* Example response:
{
    list: [ {…}, {…}, {…}, … ]
    type: 'user'
}
*/

signOut

Sign out from Greasy Fork account.

const GF = new GreasyFork()

GF.signOut()