Extension development

Sleipnir Mobile for Android is required to use the contents on this site.

Extensions are developed using JavaScript. The scripting used is very similar to the Greasemonkey script specifications so if you have developed Greasemonkey scripts in the past you should find the specifications very easy to understand.

Extensions are made using one JavaScript source file. The encoding used is UTF-8. Please set the name as *.slex.js. When a *.slex.js link is opened in the application, an installation dialog is displayed.

// ==UserScript==
// @name            Sample extension
// @namespace       http://fenrir-inc.com
// @author          fenrir_dev
// @description     This is a sample extension.
// @description     Inserts current date to fenrir-inc.com pages.
// @icon            http://extensions.fenrir-inc.com/sample/icon.png
// @include         http://*.fenrir-inc.com/*
// @exclude         http://*.fenrir-inc.com/*/dev/*
// @exclude         http://*.fenrir-inc.com/*/admin/*
// @version         0.2.1
// @history         0.2.1 Fixed some bugs.
// @history         0.2   Improved something.
// @history         0.2   Fixed something.
// @history         0.1   Initial version.
// @require         jquery
// ==/UserScript==

var str_date = " Date: ";
switch(SLEX_locale) {
  case "ja":
    str_date = " 日付: ";
    break;
}

$("body").prepend('
'+str_date + new Date()+'
');

Meta data is the data used to define the information in the application itself of the name and author.

// ==UserScript==

to

// ==/UserScript==

Comment blocks surrounding with the above are interpreted as meta data.

Formatting of each line of meta data is done like below.

<More than 0 blank characters>//<More than 0 blank characters><Meta data name><More than 1 blank characters><Meta data value>

Meta data list

Meta data Meaning Omittable Multiple
@name <Name> English expression name. x x
@name:ja <Name> Japanese expression name. o x
@author <Name> English author name. x x
@description <Description> English detailed description. x o
@description:ja <Description> Japanese detailed description. o o
@icon <URL or BASE64 data> Icon. Sets the URL or binary data encoded in BASE64. PNG formatting is used. Recommended size is 128x128. o x
@include <Included URL> URL to be executed. Wild cards possible. Regular expressions not possible. x o
@exclude <Excluded URL> URL not to be executed. Wild cards possible. Regular expressions not possible. o o
@android-version <Version number> Set the Android version used when operating this extension. It is not necessary to set this if operations are performed the same regardless of the Android version. o o
@version <Version number> Version number of this extension. x x
@history <Version number> <Description> Update history of each version in English. Please input in descending order from the latest version when setting multiple versions. o o
@history:ja <Version number> <Description> Update history of each version in Japanese. Please input in descending order from the latest version when setting multiple versions. o o
@require <Function name> Sets the script functions to be enabled. This differs with the @require of Greasemonkey so please be careful. o o
@origin <URL> The original URL for downloading the extension file. It is not required to set this. This will be treated as the ID of extension files not being distributed in the Sleipnir Mobile Extensions Center. o x
@gallery-id <ID> This shows the ID used in the Extensions Gallery. This meta data is automatically added in response to the script posted on the site. Please ignore it when this meta data is attached to the installed script on a site not distributed. o x

List of script functions

Script function name Details
api Makes using Extension API possible. Please do not use when the site to be executed can not be trusted.
jquery Makes using jQuery 1.7.1 possible.
xpath Make XPath usable. The implementation released on http://mcc.id.au/xpathjs is used.
api-notification Makes using Extension API for notifications possible. Please do not use when the site to be executed can not be trusted.
(Sleipnir Mobile for Android 2.12 or later)

Values that can be specified for @android-version

You can specify the following values.

As an example, if you want to specify operations for just Android 2.3.x, the following meta data should be specified.

// @android-version 2.3
// @android-version 2.3.3
// @android-version 2.3.4
// @android-version 2.3.5
// @android-version 2.3.6
// @android-version 2.3.7

Version number restrictions

Version are displayed using strings delimited by dots. A maximum of 4 numbers can be used within the range of [0, 65525].

Example:

Extension API can be used from JavaScript of extensions using function groups of applications.

SLEX_showNotification(text, [, callback])

Display a notification on the top bar.
"@require api-notification" is required to use. (Sleipnir Mobile for Android 2.12 or later)

Example:

function myCallback() {
  alert('callback');
}
SLEX_showNotification('notification', myCallback);

SLEX_addStyle(str)

Adds CSS.
"@require api" is required to use.

Example:

SLEX_addStyle('body{font-size:24px;color:#000;} a:hover{text-decoration:underline;}');

SLEX_httpGet(url [, data])

Load data from server using HTTP GET request, and return as string. null is returned when an error occurs. There are no cross-domain restrictions.
"@require api" is required to use.

  • url: URL to which the request is sent.
  • data: Parameter to be sent to the server.

Example:

SLEX_httpGet('http://en.wikipedia.org/wiki/Special:Search', {'search': 'android', 'go': 'Go'});

SLEX_httpPost(url [, data])

Load data from server using HTTP POST request, and return as string. null is returned when an error occurs. There are no cross-domain restrictions.
"@require api" is required to use.

  • url: URL to which the request is sent.
  • data: Parameter to be sent to the server.

Example:

SLEX_httpPost('http://www.sleipnirstart.com/', {'keywd': 'aaa', 'eng': 'fs'});

SLEX_download(url [, filename])

Files are downloaded using the downloader of the application.
"@require api" is required to use.

  • url: URL to download.
  • filename: File name to download. Changed to a suitable name when omitted.

Example:

SLEX_download("http://fenrir-inc.com/", "index.html");

SLEX_shareUrl(url)

Open URL in another application using intent.
"@require api" is required to use.

  • url: URL to open.

Example:

SLEX_shareUri('http://m.sleipnirstart.com/');

SLEX_shareText(text [, subject])

Send text to different application using intent.
"@require api" is required to use.

  • text: Text to send.
  • subject: Subject to send. Can be omitted.

Example:

SLEX_shareText('content', 'title');

SLEX_locale

The current locale value string variable. Takes the value below.
"@require api" is required to use.

  • "en"
  • "ja"

Example:

var str_msg = "Message";
switch( SLEX_locale ) {
    case "ja":
        str_msg = "メッセージ";
        break;
}
Top
Help
Extension development