Attention!

The API is under active development and this documentation is subject to change.

API

See how to report data to myUserJS's statistical engine


Current Version

0.0.13

URL

https://myuserjs.org/API/MUJS.js
https://myuserjs.org/API/MUJS.min.js

Version Specific URL

https://myuserjs.org/API/0.0.13/MUJS.js
https://myuserjs.org/API/0.0.13/MUJS.min.js

Usage

A full userscript example can be found here: Anti-Pagination.user.js

// ==UserScript==
// @name             API Example
// @namespace        http://myuserjs.org/user/jgjake2
// @description      MUJS API Example
// @author           jgjake2
// @homepage         http://myuserjs.org/
// @include          http://myuserjs.org/*
// @require          https://myuserjs.org/API/0.0.13/MUJS.js
// @version          0.0.1
// @grant            unsafeWindow
// @grant            GM_info
// @grant            GM_log
// @grant            GM_getMetadata
// @grant            GM_xmlhttpRequest
// @grant            GM_registerMenuCommand
// @unwrap
// @noframes
// ==/UserScript==

/***********************************
 ** Usage Example
 **********************************/
 
var scriptLoadTime = -1;

// Set object containing information about the current script
// Only necessary if MUJS is loaded outside of greasemonkey/tampermonkey
/*
MUJS({
	'ginfo': GM_info,
	'has_GM_info': (typeof GM_info !== "undefined" ? true : false),
	'has_GM_getMetadata': (typeof GM_getMetadata !== "undefined" ? true : false)
});
*/

// Not needed if you set "@updateURL" or "@MUJSupdateURL" to your myUserJS update URL
MUJS('set', 'script.username', 'jgjake2'); // Set Script Owner Name
// Not needed if you set "@updateURL" or "@MUJSupdateURL" to your myUserJS update URL
MUJS('set', 'script.script_name', 'Cracked.com_Enhancer'); // Set Script Name
MUJS('set', 'Update.getType', 'data'); // Set the update data return type
MUJS('set', 'Update.DOMTiming', true); // Enable reporting of timing information
MUJS('set', 'Error.autoReportErrors', true); // Enable auto reporting of script errors

// Callback function for update check
var updateCallback = function(result){
	console.log('updateCallback ', result);
}

function getMUJSUpdate(){
	var opts = {
		callback: updateCallback,
		getType: 'data',
		args: {}
	};
	
	// Only add "scriptLoadTime" if it is valid
	if(scriptLoadTime > -1)
		opts.args.scriptLoadTime = scriptLoadTime;
		
	// Initiate update check and send args to the collection engine
	MUJS.UPDATE.getUpdateData(opts);
}

function onReadyCB(){
	// Init your script
	
	// Get the page load time
	scriptLoadTime = performance.now();
	
	// Wait to report data (required if you want "pageLoadTime" to be accurate)
	MUJS.onPageReady = getMUJSUpdate;
}
// wait for MUJS API
MUJS.onReady = onReadyCB;

Options

/***********************************
 ** Set Options
 **********************************/
MUJS('set', '{{{OPTION_NAME}}}', {{{OPTION_VALUE}}});
//OR
MUJS.config('{{{OPTION_NAME}}}', {{{OPTION_VALUE}}});
Name Type Default Description
script.username String undefined Script owner’s username
script.script_name String undefined The script's file name (can be found in the URL of the script's page)
Update.script_info object undefined An object containing detailed information about your script.
/***********************************
 ** Set script_info
 **********************************/
MUJS({
	'ginfo': GM_info,
	'has_GM_info': (typeof GM_info !== "undefined" ? true : false),
	'has_GM_getMetadata': (typeof GM_getMetadata !== "undefined" ? true : false)
});
Update.DOMTiming Boolean false Send timing information to the server
Update.getType Object "data" The format of the update information.
  • meta - Raw Meta String
  • metajs - Array containing lines of the Meta block.
  • data - Object containing meta information broken into key-value pairs.
    • If a Meta tag has multiple instances, the values will be grouped into an array.
Update.getStats Boolean false Get statistical information about your script with your script update.
This will eventually support requesting stats the same way you can while making a custom graph.
For data updates only
/***********************************
 ** Return Example
 **********************************/
{
	"MUJS::STATS": {
		"DOWNLOADS": "459",
		"SCRIPT_DOWNLOADS": "193",
		"META_DOWNLOADS": "14",
		"METAJS_DOWNLOADS": "4",
		"DATA_DOWNLOADS": "248"
	},
	"author": "jgjake2",
	...
}

Example

/***********************************
 ** Set Options
 **********************************/
MUJS('set', 'script.username', 'jgjake2');
MUJS('set', 'script.script_name', 'Cracked.com_Enhancer');
MUJS('set', 'Update.getType', 'data');
MUJS('set', 'Update.DOMTiming', true);

Update Arguments

Name Type Description
getType String Overrides the global getType option
callback Function or String The Function or Function Name to be called with the response from the server.
args Object An object containing the arguments to be sent to the server.

Example

/***********************************
 ** Update Arguments
 **********************************/
var updateArgs = {
	getType: 'data',
	callback: testCBFunction,
	args: {
		'scriptLoadTime': 1234
	}
};

Methods

Name Return Value Description
getDOMTiming( ) DOMTiming Object
/***********************************
 ** getDOMTiming
 **********************************/
MUJS.getDOMTiming();
UPDATE.getUpdateURL( options object ) URL String Get the update URL from the supplied arguments.
/***********************************
 ** getUpdateURL
 **********************************/
MUJS.UPDATE.getUpdateURL(updateArgs);
UPDATE.getUpdateData( options object ) none undefined Send the arguments to the server and receive the requested meta information.
/***********************************
 ** getUpdateData
 **********************************/
MUJS.UPDATE.getUpdateData(updateArgs);

API Log Methods

Name Return Value Description
MUJS.Log( [,arg1 object] [,argN object] )
alias of MUJS.API.MUJS_Log.Log
none undefined
/***********************************
 ** MUJS.Log
 **********************************/
MUJS.Log('Log Text', logObject);