This is a Tampermonkey userscript that gives full control of the VIJISA Mirage 3 (vibrate, rotate, and suction/constrict) through Intiface Central when watching videos that contain embedded control signals.
How it works
- The Mirage 3 connects to Intiface Central over Bluetooth.
- A Tampermonkey userscript running in Chrome intercepts the control signals from the website.
- The script translates those signals into proper commands for the Mirage 3’s three actuators (Vibrate, Rotate, Constrict).
The script includes:
- Automatic device detection
- Auto-gain (normalizes intensity per video)
- Pulse-reactive suction
- Safety features (forced vent after max hold time)
- Three presets (Mellow / Normal / Hard) + full manual controls
- On-screen control panel
Requirements
- PC with Bluetooth
- Google Chrome
- Intiface Central
- Tampermonkey extension
Setup
- Install Intiface Central from the official site:
https://intiface.com/ - Enable Bluetooth, start Intiface Central, start the engine, and connect the Mirage 3 (Devices → Start scanning).
- Install the Tampermonkey Chrome extension:
https://chromewebstore.google.com/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo - In Tampermonkey, create a new script, paste the entire code below, and save it.
JavaScript
// ==UserScript==
// @name FapTap JoyHub Mirage 3
// @version 2.6
// @description Mirage 3 – time-based engine, actuator auto-detect, auto-gain, suction with guaranteed release, presets, pulse-reactive suction, manual-timer intensity ramp
// @match *://faptap.net/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
'use strict';
// ---------------- constants ----------------
const STORAGE_KEY = 'mirage_settings_v2.0'; // unchanged so existing settings carry over
const TICK_MS = 40; // engine clock (25 Hz)
const MIN_SEND_MS = 90; // max ~11 device updates/s – keeps BLE responsive
const TICK_SEND = true; // false = only rewrite FapTap's own messages (no injection)
const OWN_ID_BASE = 3000000000; // Ids for injected messages (inside uint32 range)
const SPEED_SCALE = 80; // |Δintensity| per ms → 0..1 "dynamics"
const SLOW_SPEED = 0.30; // dynamics below this = steady section
const SUSTAIN_MS = 900; // steady this long → breathing mode
const PEAK_FLOOR = 0.35; // auto-gain never amplifies more than ~2.9x
const PEAK_START = 1.0; // auto-gain starts neutral (1x) and learns over ~30 s
const PEAK_DECAY_MS = 25000; // auto-gain memory
const BREATHE_ON = 0.65; // fraction of breathing cycle with suction on
const PULSE_SIZE = 0.25; // a rise this big (or bigger) counts as a full-size hit
const PULSE_DECAY_MS = 350; // how fast a pulse boost fades
const RAMP_IDLE_MS = 10000; // ramp timer pauses if FapTap sends nothing for this long
const DEFAULTS = {
v_on: true, r_on: true, c_on: true, auto_gain: true,
preset: 'Normal',
vibrate: 1.0,
rotate: 1.0, rotate_th: 0.10, rotate_curve: 1.3, speed_mix: 0.35,
c_th: 0.18, c_hyst: 0.06, c_floor: 0.25, c_max: 0.95,
c_punch: 0.5, // how much quick, hard hits boost suction
breathe_period: 4.0, // s
max_hold: 10, // s of continuous suction before forced vent
vent_ms: 1200,
min_release_ms: 350,
// auto-intensity ramp
ramp_on: false,
ramp_minutes: 15, // time from ramp start to reaching Normal
ramp_delay: 0, // minutes to hold at the start level first
ramp_low: 0.5, // 0 = start at Mellow, 1 = start at Soft
ramp_curve: 1.5 // 1 = linear, >1 = gentle longer then builds late, <1 = early climb
};
// Presets set sliders only – on/off toggles and auto-gain are left as you set them.
// Low presets use short pulls (max_hold) because the pump builds vacuum the longer it runs.
const PRESETS = {
Soft: {
vibrate: 0.55,
rotate: 0.6, rotate_th: 0.20, rotate_curve: 1.8, speed_mix: 0.10,
c_th: 0.45, c_hyst: 0.05, c_floor: 0.02, c_max: 0.20, c_punch: 0.05,
breathe_period: 2.5, max_hold: 1.5, vent_ms: 1800, min_release_ms: 900
},
Mellow: {
vibrate: 0.75,
rotate: 0.8, rotate_th: 0.15, rotate_curve: 1.5, speed_mix: 0.20,
c_th: 0.38, c_hyst: 0.05, c_floor: 0.05, c_max: 0.35, c_punch: 0.15,
breathe_period: 3.0, max_hold: 2.5, vent_ms: 1500, min_release_ms: 700
},
Normal: {
vibrate: 1.0,
rotate: 1.0, rotate_th: 0.10, rotate_curve: 1.3, speed_mix: 0.35,
c_th: 0.18, c_hyst: 0.06, c_floor: 0.25, c_max: 0.95, c_punch: 0.5,
breathe_period: 4.0, max_hold: 10, vent_ms: 1200, min_release_ms: 350
},
Hard: {
vibrate: 1.3,
rotate: 1.4, rotate_th: 0.05, rotate_curve: 1.1, speed_mix: 0.55,
c_th: 0.12, c_hyst: 0.08, c_floor: 0.35, c_max: 1.0, c_punch: 0.8,
breathe_period: 3.0, max_hold: 14, vent_ms: 900, min_release_ms: 250
}
};
const RAMP_KEYS = Object.keys(PRESETS.Normal);
const safeParse = s => { try { return JSON.parse(s) || {}; } catch { return {}; } };
const cfg = Object.assign({}, DEFAULTS, safeParse(localStorage.getItem(STORAGE_KEY)));
delete cfg.ramp_video; // leftover from v2.4
window.mirageConfig = cfg;
const save = () => localStorage.setItem(STORAGE_KEY, JSON.stringify(cfg));
const clamp = (v, lo = 0, hi = 1) => Math.min(hi, Math.max(lo, v));
const lerp = (a, b, t) => a + (b - a) * t;
const fmt = s => { s = Math.max(0, s || 0); return `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, '0')}`; };
// ---------------- state ----------------
const S = {
ws: null, deviceIndex: null, detected: false, deviceName: '',
map: { Rotate: 0, Vibrate: 1, Constrict: 2 }, // fallback until Intiface tells us
steps: { Rotate: 20, Vibrate: 20, Constrict: 20 },
raw: 0, lastRaw: 0, lastInputT: 0, x: 0,
speed: 0, punch: 0, peak: PEAK_START,
lastTick: performance.now(),
rotOn: false,
suck: { on: false, env: 0, slowSince: 0, breatheStart: 0,
nonzeroSince: 0, releasedAt: -1e9, ventUntil: 0, mode: 'idle' },
out: { v: 0, r: 0, c: 0 },
sentSteps: { v: -1, r: -1, c: -1 }, lastSendT: 0,
ownIds: new Map(), nextId: OWN_ID_BASE,
panic: false,
// ramp timer
lastRampTick: performance.now(), rampElapsed: 0, rampP: 0,
rampPaused: false, rampRunning: false,
lastCmdT: 0, appStopped: true
};
// ---------------- input ----------------
function onInput(raw, now) {
const dt = S.lastInputT ? Math.max(1, now - S.lastInputT) : 100;
const delta = raw - S.lastRaw;
const inst = Math.min(1, Math.abs(delta) / dt * SPEED_SCALE);
S.speed += (inst - S.speed) * (1 - Math.exp(-dt / 250)); // time-based smoothing
// Pulse = a rise that is both quick AND large, weighted toward hits that land high
if (delta > 0) {
const quick = Math.min(1, delta / dt * SPEED_SCALE);
const big = Math.min(1, delta / PULSE_SIZE);
const hit = quick * big * (0.5 + 0.5 * raw);
S.punch = Math.max(S.punch, hit);
}
S.lastRaw = raw; S.raw = raw; S.lastInputT = now;
}
function anyVideoPlaying() {
const vids = document.getElementsByTagName('video');
if (!vids.length) return true; // no <video> found → don't block
for (const v of vids) if (!v.paused && !v.ended && v.readyState >= 3) return true;
return false;
}
// ---------------- auto-intensity ramp (manual timer) ----------------
const rampEndS = () => (cfg.ramp_delay + cfg.ramp_minutes) * 60;
function applyRamp(now, dt) {
if (!cfg.ramp_on) { S.rampRunning = false; return; }
const appActive = !S.appStopped && now - S.lastCmdT < RAMP_IDLE_MS;
S.rampRunning = !S.panic && !S.rampPaused && appActive && anyVideoPlaying();
if (S.rampRunning) S.rampElapsed += dt / 1000;
const dur = Math.max(0.1, cfg.ramp_minutes) * 60;
const lin = clamp((S.rampElapsed - cfg.ramp_delay * 60) / dur);
const p = Math.pow(lin, cfg.ramp_curve);
S.rampP = p;
for (const k of RAMP_KEYS) {
const start = lerp(PRESETS.Mellow[k], PRESETS.Soft[k], cfg.ramp_low);
cfg[k] = lerp(start, PRESETS.Normal[k], p);
}
}
// ---------------- engine ----------------
function compute(now) {
const dt = clamp(now - S.lastTick, 0, 250);
S.lastTick = now;
if (now - S.lastInputT > 150) S.speed *= Math.exp(-dt / 600); // decay when input is steady
S.punch *= Math.exp(-dt / PULSE_DECAY_MS); // pulse boost fades out
if (S.panic || !anyVideoPlaying()) {
if (!S.panic) S.raw = 0;
S.punch = 0;
S.out.v = S.out.r = S.out.c = 0; S.rotOn = false;
resetSuction(now, S.panic ? 'STOPPED' : 'paused');
return;
}
S.peak = Math.max(S.raw, PEAK_FLOOR, S.peak * Math.exp(-dt / PEAK_DECAY_MS));
const x = cfg.auto_gain ? clamp(S.raw / S.peak) : clamp(S.raw);
S.x = x;
// Vibrate: linear, follows every nuance
S.out.v = cfg.v_on ? clamp(x * cfg.vibrate) : 0;
// Rotate: threshold w/ hysteresis, curve, speed boost fills remaining headroom
let r = 0;
if (cfg.r_on) {
const th = cfg.rotate_th;
if (x > 0 && x >= th) S.rotOn = true;
else if (x === 0 || x < th - 0.04) S.rotOn = false;
if (S.rotOn) {
const n = clamp((x - th) / Math.max(0.01, 1 - th));
const base = clamp(Math.pow(n, cfg.rotate_curve) * cfg.rotate);
r = Math.max(0.01, base + (1 - base) * S.speed * cfg.speed_mix);
}
} else S.rotOn = false;
S.out.r = clamp(r);
S.out.c = cfg.c_on ? suction(x, now, dt) : resetSuction(now, 'off');
}
function resetSuction(now, mode) {
const s = S.suck;
if (s.nonzeroSince) s.releasedAt = now;
s.on = false; s.nonzeroSince = 0; s.slowSince = 0; s.breatheStart = 0; s.env = 0;
s.mode = mode;
return 0;
}
function suction(x, now, dt) {
const s = S.suck;
const p = clamp(S.punch * cfg.c_punch); // effective pulse strength 0..1
// envelope: snappier attack on fast/hard content, always quick release
const attack = 150 - 110 * Math.min(1, S.speed + S.punch);
s.env += (x - s.env) * (1 - Math.exp(-dt / (x > s.env ? attack : 60)));
// on/off gate with hysteresis (no chatter around the threshold)
if (!s.on && x > 0 && x >= cfg.c_th) s.on = true;
else if (s.on && x < cfg.c_th - cfg.c_hyst) s.on = false;
if (!s.on) return resetSuction(now, 'idle');
if (now < s.ventUntil) { s.mode = 'VENT'; return 0; }
// hard pulses shorten the minimum release so rapid strokes get distinct pulls
if (now - s.releasedAt < cfg.min_release_ms * (1 - 0.6 * p)) { s.mode = 'releasing'; return 0; }
// map threshold..1 → floor..max (full range, no dead jump)
const n = clamp((s.env - cfg.c_th) / Math.max(0.01, 1 - cfg.c_th));
const top = Math.max(cfg.c_floor, cfg.c_max);
let level = cfg.c_floor + (top - cfg.c_floor) * n;
s.mode = 'follow';
// quick hard hit → push suction toward max for that moment
if (p > 0.02) {
level += (top - level) * p;
if (p > 0.15) s.mode = 'pulse';
}
// steady section detection (timer only resets when dynamics rise)
if (S.speed < SLOW_SPEED) { if (!s.slowSince) s.slowSince = now; }
else { s.slowSince = 0; s.breatheStart = 0; }
if (s.slowSince && now - s.slowSince > SUSTAIN_MS) {
if (!s.breatheStart) s.breatheStart = now;
const P = cfg.breathe_period * 1000;
const ph = ((now - s.breatheStart) % P) / P;
if (ph < BREATHE_ON) {
level *= 0.55 + 0.45 * Math.sin(Math.PI * ph / BREATHE_ON); // swell and ease
s.mode = 'breathe';
} else {
level = 0; // real release each cycle
s.mode = 'breathe-release';
}
}
// safety: never hold suction indefinitely
if (level > 0) {
if (!s.nonzeroSince) s.nonzeroSince = now;
if (now - s.nonzeroSince > cfg.max_hold * 1000) {
s.ventUntil = now + cfg.vent_ms; s.nonzeroSince = 0; s.releasedAt = now; s.mode = 'VENT';
return 0;
}
} else if (s.nonzeroSince) { s.nonzeroSince = 0; s.releasedAt = now; }
return clamp(level);
}
// ---------------- output ----------------
function quant(v, steps) {
v = clamp(v);
return v > 0 ? Math.max(1, Math.round(v * steps)) : 0; // any nonzero → at least 1 step
}
function buildScalars() {
const list = [];
[['Vibrate', 'v'], ['Rotate', 'r'], ['Constrict', 'c']].forEach(([type, k]) => {
const idx = S.map[type];
if (idx == null) return;
const st = S.steps[type] || 20;
const q = quant(S.out[k], st);
list.push({ k, q, msg: { Index: idx, Scalar: q / st, ActuatorType: type } });
});
return list;
}
function commit(list, now) {
list.forEach(s => { S.sentSteps[s.k] = s.q; });
S.lastSendT = now;
}
function maybeSend(now, force) {
if (!S.ws || S.ws.readyState !== 1 || S.deviceIndex == null) return;
const list = buildScalars();
const changed = list.some(s => S.sentSteps[s.k] !== s.q);
if (!force && (!changed || now - S.lastSendT < MIN_SEND_MS)) return;
const id = S.nextId++;
S.ownIds.set(id, now);
rawSend.call(S.ws, JSON.stringify([{ ScalarCmd: {
Id: id, DeviceIndex: S.deviceIndex, Scalars: list.map(s => s.msg) } }]));
commit(list, now);
}
function forceStop() {
const now = performance.now();
S.punch = 0;
S.out.v = S.out.r = S.out.c = 0;
resetSuction(now, S.panic ? 'STOPPED' : 'off');
maybeSend(now, true);
}
// ---------------- protocol hooks ----------------
function registerDevice(d) {
const arr = d && d.DeviceMessages && d.DeviceMessages.ScalarCmd;
if (!Array.isArray(arr)) return;
const types = arr.map(a => a.ActuatorType);
const isMirage = /mirage/i.test(d.DeviceName || '') ||
(types.includes('Constrict') && types.includes('Rotate'));
if (!isMirage) return;
S.map = {}; S.steps = {};
arr.forEach((a, i) => {
if (S.map[a.ActuatorType] == null) {
S.map[a.ActuatorType] = i;
S.steps[a.ActuatorType] = a.StepCount || 20;
}
});
S.deviceIndex = d.DeviceIndex; S.detected = true; S.deviceName = d.DeviceName || 'device';
S.sentSteps = { v: -1, r: -1, c: -1 };
console.info('[Mirage] detected', S.deviceName, S.map, S.steps);
}
function learn(data) {
if (typeof data !== 'string') return;
let msgs; try { msgs = JSON.parse(data); } catch { return; }
if (!Array.isArray(msgs)) return;
for (const m of msgs) {
if (m.DeviceList && Array.isArray(m.DeviceList.Devices)) m.DeviceList.Devices.forEach(registerDevice);
if (m.DeviceAdded) registerDevice(m.DeviceAdded);
if (m.DeviceRemoved && m.DeviceRemoved.DeviceIndex === S.deviceIndex) {
S.detected = false; S.deviceIndex = null;
}
if (m.Error && S.ownIds.has(m.Error.Id)) console.warn('[Mirage] device error', m.Error);
}
}
// hide replies to our injected messages from FapTap's client
function filterEvent(e) {
if (!S.ownIds.size || typeof e.data !== 'string') return e;
let msgs; try { msgs = JSON.parse(e.data); } catch { return e; }
if (!Array.isArray(msgs)) return e;
const keep = msgs.filter(m => { const r = m.Ok || m.Error; return !(r && S.ownIds.has(r.Id)); });
if (keep.length === msgs.length) return e;
if (!keep.length) return null;
return new MessageEvent('message', { data: JSON.stringify(keep), origin: e.origin });
}
function transformOutgoing(ws, data) {
const msgs = JSON.parse(data);
if (!Array.isArray(msgs)) return data;
let touched = false;
for (const m of msgs) {
if (m.RequestServerInfo || m.RequestDeviceList || m.StartScanning) S.ws = ws;
const stop = m.StopAllDevices ||
(m.StopDeviceCmd && (S.deviceIndex == null || m.StopDeviceCmd.DeviceIndex === S.deviceIndex));
if (stop) {
const now = performance.now();
S.raw = 0; S.punch = 0; S.out.v = S.out.r = S.out.c = 0;
resetSuction(now, 'off');
S.sentSteps = { v: 0, r: 0, c: 0 };
S.appStopped = true; // FapTap paused/stopped → ramp timer pauses
continue;
}
const sc = m.ScalarCmd;
if (!sc || !Array.isArray(sc.Scalars)) continue;
if (S.detected && sc.DeviceIndex !== S.deviceIndex) continue; // another toy: pass through
S.ws = ws;
if (!S.detected) S.deviceIndex = sc.DeviceIndex;
const raw = sc.Scalars.reduce((mx, s) => Math.max(mx, +s.Scalar || 0), 0);
const now = performance.now();
S.lastCmdT = now; S.appStopped = false; // FapTap is playing → ramp timer runs
onInput(raw, now);
compute(now);
const list = buildScalars();
sc.Scalars = list.map(s => s.msg);
commit(list, now);
touched = true;
}
return touched ? JSON.stringify(msgs) : data;
}
const OrigWS = window.WebSocket;
const rawSend = OrigWS.prototype.send;
const wrappedFns = new WeakMap();
class MirageWS extends OrigWS { // subclass keeps OPEN/CLOSED constants and instanceof
constructor(url, protocols) {
super(url, protocols);
super.addEventListener('message', e => learn(e.data));
super.addEventListener('close', () => { if (S.ws === this) S.ws = null; });
}
send(data) {
if (typeof data === 'string') {
try { data = transformOutgoing(this, data); }
catch (e) { if (!(e instanceof SyntaxError)) console.warn('[Mirage]', e); }
}
return super.send(data);
}
addEventListener(type, fn, opts) {
if (type === 'message' && typeof fn === 'function') {
let w = wrappedFns.get(fn);
if (!w) {
w = function (e) { const f = filterEvent(e); if (f) return fn.call(this, f); };
wrappedFns.set(fn, w);
}
return super.addEventListener(type, w, opts);
}
return super.addEventListener(type, fn, opts);
}
removeEventListener(type, fn, opts) {
if (type === 'message' && wrappedFns.has(fn)) return super.removeEventListener(type, wrappedFns.get(fn), opts);
return super.removeEventListener(type, fn, opts);
}
get onmessage() { return this._mirageOnMsg || null; }
set onmessage(fn) {
this._mirageOnMsg = fn;
super.onmessage = typeof fn === 'function'
? (e) => { const f = filterEvent(e); if (f) fn.call(this, f); }
: fn;
}
}
window.WebSocket = MirageWS;
// ---------------- clock & safety events ----------------
setInterval(() => {
const now = performance.now();
const rdt = clamp(now - S.lastRampTick, 0, 250);
S.lastRampTick = now;
applyRamp(now, rdt);
compute(now);
if (TICK_SEND) maybeSend(now, false);
for (const [id, t] of S.ownIds) if (now - t > 10000) S.ownIds.delete(id);
updateUI();
}, TICK_MS);
['pause', 'ended', 'waiting', 'seeking', 'emptied'].forEach(t =>
document.addEventListener(t, () => {
const now = performance.now();
compute(now); // checks whether any video is still playing
maybeSend(now, true);
}, true));
window.addEventListener('pagehide', forceStop);
// ---------------- UI ----------------
const UI = { ready: false, tick: 0, scrubbing: false };
const GROUPS = [
['Vibrate', 'v_on', [['vibrate', 'Gain', 0, 1.5, 0.05]]],
['Rotate', 'r_on', [
['rotate', 'Gain', 0.5, 2, 0.05],
['rotate_th', 'Threshold', 0, 0.5, 0.02],
['rotate_curve', 'Curve', 0.7, 2.5, 0.1],
['speed_mix', 'Speed boost', 0, 1, 0.05]]],
['Suction', 'c_on', [
['c_th', 'Threshold', 0.05, 0.6, 0.01],
['c_hyst', 'Hysteresis', 0, 0.2, 0.01],
['c_floor', 'Min level', 0, 0.6, 0.01],
['c_max', 'Max level', 0.1, 1, 0.05],
['c_punch', 'Pulse boost', 0, 1, 0.05],
['breathe_period', 'Breathe period (s)', 1.5, 10, 0.5],
['max_hold', 'Max pull length (s)', 1, 30, 0.5],
['vent_ms', 'Vent length (ms)', 300, 3000, 100],
['min_release_ms', 'Min release (ms)', 0, 1500, 50]]]
];
const RAMP_SLIDERS = [
['ramp_minutes', 'Ramp length (min)', 1, 90, 0.5],
['ramp_delay', 'Start delay (min)', 0, 30, 0.5],
['ramp_low', 'Start below Mellow (0=Mellow, 1=Soft)', 0, 1, 0.05],
['ramp_curve', 'Shape (1=linear, >1=late build)', 0.5, 3, 0.1]
];
const TOGGLES = ['v_on', 'r_on', 'c_on', 'auto_gain', 'ramp_on'];
const decimals = step => (step < 0.1 ? 2 : step < 1 ? 1 : 0);
const sliderHTML = ([k, label, min, max, step]) =>
`<div class="row"><span>${label}</span><span id="mv_${k}"></span></div>
<input type="range" id="ms_${k}" min="${min}" max="${max}" step="${step}">`;
function buildUI() {
const style = document.createElement('style');
style.textContent = `
#mirage-panel{position:fixed;top:40px;left:20px;z-index:99999;background:#0f0f0f;color:#eee;
padding:12px;border:1px solid #555;border-radius:10px;font:12px monospace;width:300px;
max-height:85vh;overflow:auto;box-shadow:0 0 8px rgba(255,255,255,.2)}
#mirage-panel .row{display:flex;justify-content:space-between;align-items:center;margin:6px 0 2px}
#mirage-panel input[type=range]{width:100%;margin:0}
#mirage-panel .bar{height:8px;background:#333;border-radius:4px;margin:2px 0 6px}
#mirage-panel .bar>div{height:100%;width:0;border-radius:4px;transition:width .08s}
#mirage-panel .sec{color:#aaa;margin-top:10px;border-top:1px solid #333;padding-top:6px}
#mirage-panel .dim{color:#888;font-size:11px}
#mirage-panel button{background:#222;color:#eee;border:1px solid #555;border-radius:4px;
padding:2px 8px;cursor:pointer;font:inherit}`;
document.head.appendChild(style);
const bar = (id, label, color) => `
<div class="row"><span>${label}</span><span id="mt_${id}">0.00</span></div>
<div class="bar"><div id="mb_${id}" style="background:${color}"></div></div>`;
let controls = '';
for (const [title, toggle, sliders] of GROUPS) {
controls += `<div class="sec"><label><input type="checkbox" id="mc_${toggle}"> ${title}</label></div>`;
controls += sliders.map(sliderHTML).join('');
}
const div = document.createElement('div');
div.id = 'mirage-panel';
div.innerHTML = `
<div class="row" style="margin-top:0">
<b>MIRAGE 3 <span class="dim">v2.6</span></b>
<span><button id="m_stop">STOP</button> <button id="m_min">–</button></span>
</div>
<div id="m_status" class="dim"></div>
<div id="m_body">
<div style="background:#1a1a1a;padding:8px;border-radius:6px;margin-top:8px">
${bar('v', 'Vibrate', '#4caf50')}${bar('r', 'Rotate', '#2196f3')}${bar('c', 'Suction', '#ff9800')}
<div id="m_info" class="dim"></div>
<div id="m_mode" class="dim"></div>
</div>
<div class="sec"><label><input type="checkbox" id="mc_auto_gain"> Auto-gain (normalize each video)</label></div>
<div class="sec"><label><input type="checkbox" id="mc_ramp_on"> Auto-intensity ramp → Normal</label></div>
${bar('p', 'Ramp position', '#b36bff')}
<div id="m_ramp_info" class="dim">off</div>
<div class="row" style="gap:4px">
<button id="m_ramp_back" style="flex:1">−1m</button>
<button id="m_ramp_fwd" style="flex:1">+1m</button>
<button id="m_ramp_pause" style="flex:1">Pause</button>
<button id="m_ramp_reset" style="flex:1">Reset</button>
</div>
<div class="row"><span>Ramp time (drag when you skip)</span><span id="m_ramp_pos_v">0:00</span></div>
<input type="range" id="m_ramp_pos" min="0" max="15" step="0.05" value="0">
${RAMP_SLIDERS.map(sliderHTML).join('')}
${controls}
<div class="sec">Preset: <b id="m_preset_name"></b></div>
<div class="row" style="gap:6px">
<button data-preset="Soft" style="flex:1">Soft</button>
<button data-preset="Mellow" style="flex:1">Mellow</button>
<button data-preset="Normal" style="flex:1">Normal</button>
<button data-preset="Hard" style="flex:1">Hard</button>
</div>
</div>`;
document.body.appendChild(div);
const presetBtns = div.querySelectorAll('[data-preset]');
function markPreset() {
presetBtns.forEach(b => {
const active = !cfg.ramp_on && b.dataset.preset === cfg.preset;
b.style.background = active ? '#2e5d3a' : '#222';
b.style.borderColor = active ? '#5c9' : '#555';
});
document.getElementById('m_preset_name').textContent =
cfg.ramp_on ? `Auto ramp ${Math.round(S.rampP * 100)}%` : (cfg.preset || 'Custom');
}
const showSlider = ([k, , , , step]) => {
document.getElementById('ms_' + k).value = cfg[k];
document.getElementById('mv_' + k).textContent = Number(cfg[k]).toFixed(decimals(step));
};
const refresh = () => {
TOGGLES.forEach(k => { document.getElementById('mc_' + k).checked = !!cfg[k]; });
GROUPS.forEach(g => g[2].forEach(showSlider));
RAMP_SLIDERS.forEach(showSlider);
};
function setRamp(on) {
cfg.ramp_on = on;
document.getElementById('mc_ramp_on').checked = on;
if (!on) cfg.preset = 'Custom';
markPreset();
save();
}
['v_on', 'r_on', 'c_on', 'auto_gain'].forEach(k =>
document.getElementById('mc_' + k).addEventListener('change', e => { cfg[k] = e.target.checked; save(); }));
document.getElementById('mc_ramp_on').addEventListener('change', e => {
if (e.target.checked) { S.rampElapsed = 0; S.rampPaused = false; S.peak = PEAK_START; }
setRamp(e.target.checked);
});
// ramp timer controls
const nudge = s => { S.rampElapsed = clamp(S.rampElapsed + s, 0, rampEndS()); };
document.getElementById('m_ramp_back').onclick = () => nudge(-60);
document.getElementById('m_ramp_fwd').onclick = () => nudge(60);
document.getElementById('m_ramp_reset').onclick = () => { S.rampElapsed = 0; S.peak = PEAK_START; };
const pauseBtn = document.getElementById('m_ramp_pause');
pauseBtn.onclick = () => {
S.rampPaused = !S.rampPaused;
pauseBtn.textContent = S.rampPaused ? 'Resume' : 'Pause';
pauseBtn.style.background = S.rampPaused ? '#5a4a1a' : '#222';
};
const pos = document.getElementById('m_ramp_pos');
pos.addEventListener('pointerdown', () => { UI.scrubbing = true; });
window.addEventListener('pointerup', () => { UI.scrubbing = false; });
pos.addEventListener('input', e => { S.rampElapsed = parseFloat(e.target.value) * 60; });
// manual slider = take over from the ramp
GROUPS.forEach(g => g[2].forEach(([k, , , , step]) =>
document.getElementById('ms_' + k).addEventListener('input', e => {
if (cfg.ramp_on) setRamp(false);
cfg[k] = parseFloat(e.target.value);
document.getElementById('mv_' + k).textContent = cfg[k].toFixed(decimals(step));
cfg.preset = 'Custom';
markPreset();
save();
})));
RAMP_SLIDERS.forEach(([k, , , , step]) =>
document.getElementById('ms_' + k).addEventListener('input', e => {
cfg[k] = parseFloat(e.target.value);
document.getElementById('mv_' + k).textContent = cfg[k].toFixed(decimals(step));
save();
}));
presetBtns.forEach(b => {
b.onclick = () => {
if (cfg.ramp_on) setRamp(false);
Object.assign(cfg, PRESETS[b.dataset.preset]);
cfg.preset = b.dataset.preset;
save();
refresh();
markPreset();
};
});
document.getElementById('m_min').onclick = () => {
const b = document.getElementById('m_body');
b.style.display = b.style.display === 'none' ? '' : 'none';
};
const stopBtn = document.getElementById('m_stop');
stopBtn.onclick = () => {
S.panic = !S.panic;
stopBtn.textContent = S.panic ? 'RESUME' : 'STOP';
stopBtn.style.background = S.panic ? '#a33' : '#222';
if (S.panic) forceStop();
};
['v', 'r', 'c', 'p'].forEach(k => { UI[k] = { t: document.getElementById('mt_' + k), b: document.getElementById('mb_' + k) }; });
UI.info = document.getElementById('m_info');
UI.mode = document.getElementById('m_mode');
UI.status = document.getElementById('m_status');
UI.rampInfo = document.getElementById('m_ramp_info');
UI.pos = pos;
UI.posV = document.getElementById('m_ramp_pos_v');
UI.refresh = refresh;
UI.markPreset = markPreset;
refresh();
markPreset();
UI.ready = true;
}
function updateUI() {
if (!UI.ready) return;
['v', 'r', 'c'].forEach(k => {
UI[k].t.textContent = S.out[k].toFixed(2);
UI[k].b.style.width = (S.out[k] * 100) + '%';
});
const gain = cfg.auto_gain ? ` | gain ×${(1 / S.peak).toFixed(1)}` : '';
UI.info.textContent = `in ${S.raw.toFixed(2)} → ${S.x.toFixed(2)}${gain} | dyn ${S.speed.toFixed(2)} | pulse ${S.punch.toFixed(2)}`;
UI.mode.textContent = `suction: ${S.suck.mode}`;
const m = S.map;
UI.status.textContent = !S.ws ? 'waiting for Intiface connection…'
: S.detected ? `${S.deviceName} · V${m.Vibrate ?? '-'} R${m.Rotate ?? '-'} C${m.Constrict ?? '-'} · suction ${S.steps.Constrict ?? '?'} steps`
: 'connected · device not announced, using default map';
// ramp time slider always reflects the timer
const endS = rampEndS();
UI.pos.max = (endS / 60).toFixed(2);
if (!UI.scrubbing) UI.pos.value = S.rampElapsed / 60;
UI.posV.textContent = fmt(S.rampElapsed);
if (cfg.ramp_on) {
UI.p.t.textContent = Math.round(S.rampP * 100) + '%';
UI.p.b.style.width = (S.rampP * 100) + '%';
const state = S.rampPaused ? 'paused' : S.panic ? 'stopped'
: S.rampRunning ? 'running' : 'waiting for playback';
UI.rampInfo.textContent = `${fmt(S.rampElapsed)} · Normal at ${fmt(endS)} · ${state}`;
if (++UI.tick % 6 === 0) { UI.refresh(); UI.markPreset(); } // move sliders ~4×/s
} else if (UI.p.t.textContent !== 'off') {
UI.p.t.textContent = 'off';
UI.p.b.style.width = '0%';
UI.rampInfo.textContent = 'off';
}
}
if (document.body) buildUI();
else document.addEventListener('DOMContentLoaded', buildUI, { once: true });
})();
Usage
- Make sure Intiface Central is running and the Mirage 3 is connected.
- Open a supported page that embeds control signals (currently the script matches *://faptap.net/*).
- Click the Connect button on the page.
- A control panel will appear on the left side of the browser. You can adjust all parameters or use the three presets (Mellow / Normal / Hard).