Suppose you want to add a script named hello-world.js , stored on a remote server and accessible by the URL https://example.com/userscripts/hello-world.js . Code Block |
---|
language | js |
---|
title | Hello World! Userscript |
---|
| "use strict";
console.log("Hello World!");
alert("Hello World!"); |
Then the userscript configuration would look something like this: Code Block |
---|
language | js |
---|
title | Userscript Descriptor in JSON |
---|
| {
"namespace": "org.example.scripts",
"name": "hello-world",
"version": "1.0",
"script": "https://example.com/userscripts/hello-world.js",
"description": "Displays an alertbox with the text 'Hello World!'.",
"documentation": "https://example.com/userscripts/hello-world.html",
"support": "Scripts Team",
"activation": {
"space": ["UES"],
"group": ["userscripts-evaluation-team"]
}
} |
In this example the hello world script will be executed on each page within the Userscripts Evaluation Space (with space key UES ) if the user is member of the Group userscripts-evaluation-team . To access this resource users require to be a member of the Static Document Link |
---|
document | Confluence Administrator |
---|
label | confluence administrators |
---|
| or the Static Document Link |
---|
document | Userscripts Administrator |
---|
label | userscripts administrators |
---|
| . Transclusion |
---|
document | Userscripts |
---|
ids | Operations |
---|
|
|
To create a new userscript post the JSON representation to the server with Static Document Link |
---|
document | Create Userscript by JSON |
---|
| . Tip Box |
---|
Any REST client can interact with the REST API of the Userscripts for Confluence app. The Static Document Link |
---|
document | Atlassian REST API Browser |
---|
label | ${Short Name} |
---|
| may be convenient for administrators that want to use the API once in a while via a user interface from within Confluence.
After creating the userscript, check if it is accessible.
|
If everything is configured successfully, you should get a HTTP response with status code 200 and the listing of the hello world userscript code. To test which userscripts are actually activated, you could use the Static Document Link |
---|
document | Userscripts Context Service |
---|
| . Currently it is only possible to use this service for the currently logged in user. So if there is a space with space key UES and you are member of the Confluence group names userscripts-evaluation-team , then provide the page identifier to the service. The service returns a list of URLs to activated scripts. The hello world userscript should be member of this list.And whenever member if the group visits the space, there is log message in the browser's console and an alert box popping up. |