User Scripts
Jancy comes with built-in support for user scripts and provides it’s own API for you to build user scripts with.
If you have existing Greasemonky/Tampermonkey user scripts, Jancy supports a small subset of the Greasemonkey/Tampermonkey APIs.
Metadata Block Fields
These are the currently supported metablock fields and how they’re interpreted.
@name
displayed in the user script manager@version
displayed in the user script manager@include
works like GreaseMonkey/TamperMonkey@match
works like GreaseMonkey/TamperMonkey@require
works like GreaseMonkey/TamperMonkey@connect
works like GreaseMonkey/TamperMonkey
All other metablock fields are ignored.
// ==UserScript== // @name Bigger Ticketmaster Dots // @version 1 // @description Makes the dots on the Ticketmaster seatmap bigger. // @author Joshua May // @match https://*ticketmaster.com/*/event/* // @match https://*ticketmaster.ca/*/event/* // @match https://*ticketmaster.com/event/* // @match https://*ticketmaster.ca/event/* // @match https://*livenation.com/event/* // @match https://*livenation.com/*/event/* // ==/UserScript==
JancyAPI Object
Jancy adds a jancyAPI
object to the window
object of every page and frame it loads.
window.jancyAPI.addStyle(style)
style
(string
) - CSS you want to add to the current page.
window.jancyAPI.consoleLog(message)
message
(string
)
Writes message
to the Jancy console.
window.jancyAPI.clipboard.writeText(text)
text
(string
)
Writes text
to the clipboard
window.jancyAPI.clipboard.writeTextWithNotification(text)
text
(string
)
Writes text
to the clipboard and generates an OS notification.
window.jancyAPI.dispatchAction(action, args)
Document me.
window.jancyAPI.executeCode(code)
code
(string
)
Returns a promise
that resolves with the result of executing code
in the webpage.
window.jancyAPI.getPath(name)
name
(string
)
Returns a promise
that resolves with a string that corresponds to name
. The following are the valid values for name
:
home
User’s home directory.temp
Temporary directory.exe
The current executable file.module
The libchromiumcontent library.desktop
The current user’s Desktop directory.documents
Directory for a user’s “My Documents”.downloads
Directory for a user’s downloads.music
Directory for a user’s music.pictures
Directory for a user’s pictures.videos
Directory for a user’s videos.recent
Directory for the user’s recent files (Windows only).logs
Directory for your app’s log folder.crashDumps
Directory where crash dumps are stored.
window.jancyAPI.getTabInfo()
Returns an object with the following properties.
tabId
(string
) a unique identifier for the tab the user script is running in
window.jancyAPI.getProfileInfo()
Returns a promise
that resolves with a profile
object or null
if a profile isn’t selected into the tab.
window.jancyAPI.scrollToBottom()
Scroll the current page to the bottom.
Mileage may vary depending on the page.
window.jancyAPI.scrollToTop()
Scroll the current page to the top.
window.jancyAPI.writeToFile(path, text)
path
(string
)text
(text
)
Appends text
to the file at path
.
window.jancyAPI.xmlHttpRequest()
Document me.
An Example
The following is an example user script that makes the non-resale dots on a Ticketmaster seat map bigger.
- Copy the following example to a new file called
bigger-tm-dots.js
.- Add
bigger-tm-dots.js
to Jancy via the User Script settings panel (File -> Settings -> User Scripts
)
// ==UserScript== // @name Bigger Ticketmaster Dots // @version 1 // @description Makes the dots on the Ticketmaster seatmap bigger. // @author Joshua May // @match https://*ticketmaster.com/*/event/* // @match https://*ticketmaster.ca/*/event/* // @match https://*ticketmaster.com/event/* // @match https://*ticketmaster.ca/event/* // @match https://*livenation.com/event/* // @match https://*livenation.com/*/event/* // ==/UserScript== const radius = 16 // change this to be your desired dot size /* This is the CSS we're injecting into the page. */ const style = ` circle[data-component="svg__seat"].is-available { r: ${ radius }; } ` /* For most ordinary websites, we could just call window.jancyAPI.addStyle() or ** GM_addStyle() (for GreaseMonkey you need to add @grant to the Metadata block) ** and be done with it but for TM we need our custom CSS to be injected ** into the page. The following bit of code creates a style element, set some properties ** along with the innerHTML and then adds it as a child element to the head node of the ** of the page. */ let stylesheet = document.createElement('style') stylesheet.rel = "stylesheet" stylesheet.type = "text/css" stylesheet.innerHTML = style document.head.appendChild(stylesheet)