userscript-parser

2.2.2 • Public • Published

userscript-parser npm-version install size

Userscript metadata parser.

Usage

const userscriptText = '// ==UserScript==...'
const usp = require('userscript-parser')
 
const { meta, metablock, content } = usp(userscriptText)

Given this userscript:

// ==UserScript==
// @name        Awesome Script
// @description This script even does the laundry!
// @downloadURL https://www.example.com/myscript.user.js
// @homepageURL https://github.com/gantt/downloadyoutube
// @author      Gantt
// @version     1.8.3
// @date        2015-05-17
// @include     https://www.youtube.com/*
// @exclude     https://www.youtube.com/embed/*
// @match       https://www.youtube.com/*
// @grant       GM_xmlhttpRequest
// @grant       GM_getValue
// @grant       GM_setValue
// @run-at      document-end
// @license     MIT License
// ==/UserScript==
 
var whoami = 'USERSCRIPT'

will produce this parsed object:

{
  meta: {
    description: [ 'This script even does the laundry!', ],
    downloadURL: [ 'https://www.example.com/myscript.user.js' ],
    name: [ 'Awesome Script' ],
    homepageURL: [ 'https://github.com/gantt/downloadyoutube' ],
    author: [ 'Gantt' ],
    version: [ '1.8.3' ],
    date: [ '2015-05-17' ],
    include: [ 'https://www.youtube.com/*' ],
    exclude: [ 'https://www.youtube.com/embed/*' ],
    match: [ 'https://www.youtube.com/*' ],
    grant: [ 'GM_xmlhttpRequest', 'GM_getValue', 'GM_setValue' ],
    'run-at': [ 'document-end' ],
    license: [ 'MIT License' ]
  },
  metablock: "// ==UserScript==...",
  content: "\n\nvar whoami = 'USERSCRIPT'\n"
}

License

MIT @ Amio

Readme

Keywords

Package Sidebar

Install

npm i userscript-parser

Weekly Downloads

6

Version

2.2.2

License

MIT

Unpacked Size

4.72 kB

Total Files

4

Last publish

Collaborators

  • amio