Greasy Fork镜像 API

Parse information on greasyforks.org

2022-05-29 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyforks.org/scripts/445697/1055427/Greasy%20Fork%20API.js을(를) 사용하여 포함하는 라이브러리입니다.

작성자
NotYou
버전
1.0.0
생성일
2022-05-29
갱신일
2022-05-29
크기
27KB
라이선스
LGPL-3.0

Greasy Fork镜像 API

Description:

Parse information on greasyforks.org

How to use:

Let's start with adding @require in your script meta section! Add in your script this:

// @require https://greasyforks.org/scripts/SCRIPT_ID/code/index.js

So in final you are going to get something like this:

// ==UserScript==
// @name New Userscript (Example)
// @namespace -
// @description try to take over world!
// @author Example
// @include *example.com/*
// @require https://greasyforks.org/scripts/SCRIPT_ID/code/index.js
// @license GPL-3.0-or-later
// @grant none
// ==/UserScript==

Next, you need to add a variable that with equal to class GreasyFork. Example:

const GF = new GreasyFork

parseScriptElement

Returns properties of script element if it exists, such as: Name, ID, version, language, installs etc.

var myScript = GF.parseScriptElement(document.querySelector('[data-script-id]'))
console.log(myScript.id) // some number

parseScriptCodeMeta

Returns array with script meta blocks and their values, example:

GF.parseScriptCodeMeta(`
// ==UserScript==
// @name        New Userscript (Example)
// @description try to take over world!
// ==/UserScript==
`)

/* will return this:
[{
    meta: "@name",
    value: "New Userscript (Example)"
},
{
    meta: "@description",
    value: "try to take over world!"
}]
*/

ls

Returns object with scripts, libraries and browsed script if they exist.

GF.ls()

/* will return
{
browsed: [...],
libraries: [...],
scripts: [...]
}
if function can't find elements to parse, then it returns null.
*/

get

This is the parent function that returns an object with different functions.

GF.get()

get.script

This is the parent function that returns an object with different functions.

GF.get().script()

action

install

GF.action('install', {
    id: 439627,
    lang: 'css'
})

signout

GF.action('signout')

Asynchronous functions

get.script.code

Returns script code.

var code = await GF.get().script().code(437291)
console.log(code)

Note: Can be user with parseScriptCodeMeta:

var code = await GF.get().script().code(437291)
console.log(GF.parseScriptCodeMeta(code))

get.script.history

Returns script versions, time of versions and descriptions.

await GF.get().script().history(437291)

get.script.feedback

Returns script feedback: rating, text and meta info.

await GF.get().script().feedback(437291)

get.script.stats

Returns script stats (installs and update checks) in different days.

await GF.get().script().stats(437291)

get.script.info

Returns script information from itself main page.

await GF.get().script().info(437291)

get.script.set

Returns result from script set.

await GF.get().script().set(10699, {
    locale: 'zh-CN',
    page: 1
})

Also you can turn off locale filter:

await GF.get().script().set(10699, {
    localeFilter: 0,
    page: 1
})

get.user

Returns user's information such as:

ID, Nickname, scripts, libaries, script sets, recent comments etc.

await GF.get().user(824432)

get.search

Returns search result of some content types.

script

await GF.get().search('Open Redirector', 'script', {
    locale: 'ro',
    sort: 'daily_installs',
    page: 1
})

library

await GF.get().search('Random - Lib', 'library', {
    sort: 'name'
})

user

await GF.get().search('NotYou', 'user', {
    asJSON: true
})

list

await GF.get().search('', 'list') // ["script", "library", "user", "list"]
长期地址
遇到问题?请前往 GitHub 提 Issues。