The platform passes the currently selected sample input (or custom test case) to your plugin via the URL hash:
index.html#input={urlEncodedInput}
The iframe is recreated every time the input changes, so your plugin always receives fresh input on load — no event listeners or polling needed.
The easiest way to read input is with the monkeyCodeInput.js helper library. It is automatically available in every plugin — you do not need to include it in your ZIP.
If you want to test your plugin locally, you can download the library here:
Include the script at the top of your <head>, before any other scripts:
monkeyCodeInput.js at the top of the <head>, before any plugin or application scripts. Otherwise your code may run before the library is available on first load../monkeyCodeInput.js) so the script resolves correctly in all environments.<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./monkeyCodeInput.js"></script>
<script src="./script.js"></script>
</head>
<body>
<!-- your plugin UI -->
</body>
</html>
Once the script is loaded, four global functions are available:
| Function | Returns | Description |
|---|---|---|
input() | string | null | The raw URL-decoded input string, or null if no input is present |
inputArray() | number[] | Input split on all whitespace and newlines, each token converted to a number |
inputLines() | string[] | Input split on newlines, each line returned as a string |
getInputAt(index) | number | undefined | A single number from inputArray() at the given zero-based index |
Read the entire input as a string:
const raw = input()
console.log(raw) // "5\n1 2 3 4 5"
Read all tokens as numbers (e.g. a flat list of values):
const values = inputArray()
// Input: "3 1 4 1 5"
// values → [3, 1, 4, 1, 5]
Read line by line (e.g. a grid or multi-line input):
const lines = inputLines()
// Input: "3\n1 2\n3 4\n5 6"
// lines → ["3", "1 2", "3 4", "5 6"]
const n = parseInt(lines[0])
for (let i = 1; i <= n; i++) {
const [a, b] = lines[i].split(' ').map(Number)
// process row i
}
Read a specific token by index:
const n = getInputAt(0) // first token
const k = getInputAt(1) // second token
If you prefer not to use monkeyCodeInput.js, you can read the hash directly:
const raw = decodeURIComponent(window.location.hash.replace('#input=', ''))
// `raw` is the full input string, e.g. "5\n1 2 3 4 5"
Or using URLSearchParams for a more robust parse:
const raw = new URLSearchParams(window.location.hash.slice(1)).get('input')
const decoded = raw ? decodeURIComponent(raw) : ''
A complete plugin that reads n followed by n numbers and renders them as a bar chart:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="./monkeyCodeInput.js"></script>
</head>
<body>
<canvas id="chart" width="380" height="360"></canvas>
<script>
const lines = inputLines()
const n = parseInt(lines[0])
const values = lines[1].split(' ').map(Number)
const canvas = document.getElementById('chart')
const ctx = canvas.getContext('2d')
const max = Math.max(...values)
const barWidth = canvas.width / n
values.forEach((v, i) => {
const barHeight = (v / max) * canvas.height
ctx.fillStyle = '#6366f1'
ctx.fillRect(i * barWidth, canvas.height - barHeight, barWidth - 2, barHeight)
})
</script>
</body>
</html>