Skip to content

Generates a userscript header string to append to your files.

License

Notifications You must be signed in to change notification settings

cletusc/generate-userscript-header

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

This module generates a userscript header string to append to your scripts.

Usage

First install: npm install generate-userscript-header

Then you can use it:

var generateUserscriptHeader = require('generate-userscript-header');

var userscript = {
	'name': 'ACME Userscript Maker',
	'namespace': 'http://example.com/',
	'author': '{{{pkg.author}}}',
	'homepage': '{{{pkg.homepage}}}',
	'grant': 'none',
	'include': [
		'http://google.com/*',
		'https://google.com/*'
	]
};

var context = {
	pkg: {
		author: 'John Doe',
		homepage: 'http://example.com/johndoe'
	}
};

var header = generateUserscriptHeader(userscript, context);

console.log(header);

Output:

// ==UserScript==
// @name ACME Userscript Maker
// @namespace http://example.com/
// @author John Doe
// @homepage http://example.com/johndoe
// @grant none
// @include http://google.com/*
// @include https://google.com/*
// ==/UserScript==

API

This module exports a single method that outputs a userscript metadata block as a string given the data to convert. Data is parsed with mustache and replaced with the data of a certain context.

Syntax

var generate = require('generate-userscript-header');
generate(userscript, context)

Parameters

Name Type Description
userscript object The object containing the userscript data.
context object The data used to parse values with mustache. Use {{{yourKey}}} in the data to parse.

Return

Type Description
string The finalized metadata block.

About

Generates a userscript header string to append to your files.

Resources

License

Stars

Watchers

Forks

Packages

No packages published