/*
* @title 座標自動維持ボタン(離席用)
* @description 押すとその場でグルグル回り続けるボタンが表示される
* @private
*/
javascript:(function(){
/* すでにボタンがある場合は重複させない */
if(document.getElementById('auto-rotate-btn')) return;
/* 1. ボタンの作成 */
const btn = document.createElement('button');
btn.id = 'auto-rotate-btn';
btn.innerHTML = '🌀 ぐるぐる OFF';
/* 誤タップしにくい上の方に配置 */
Object.assign(btn.style, {
position: 'fixed',
top: '10px',
left: '50%',
transform: 'translateX(-50%)',
zIndex: '9999',
padding: '8px 15px',
backgroundColor: '#333',
color: '#fff',
border: '2px solid #fff',
borderRadius: '20px',
fontSize: '14px',
fontWeight: 'bold',
cursor: 'pointer'
});
document.body.appendChild(btn);
/* 2. 旋回ロジックの変数 */
let rotateInterval = null;
let step = 0;
/* 上(0), 右(1), 下(2), 左(3) の方向ベクトル */
const directions = [
{dx: 0, dy: -100}, /* 上 */
{dx: 100, dy: 0}, /* 右 */
{dx: 0, dy: 100}, /* 下 */
{dx: -100, dy: 0} /* 左 */
];
/* 3. ぐるぐる実行関数 */
const toggleRotate = () => {
if (rotateInterval) {
/* 停止処理 */
clearInterval(rotateInterval);
rotateInterval = null;
btn.innerHTML = '🌀 ぐるぐる OFF';
btn.style.backgroundColor = '#333';
/* 入力をリセット */
if(window.inputState) {
window.inputState.dx = 0;
window.inputState.dy = 0;
window.inputState.drawing = false;
}
} else {
/* 開始処理 */
btn.innerHTML = '🌀 ぐるぐる ON!';
btn.style.backgroundColor = '#f00';
rotateInterval = setInterval(() => {
if (window.inputState) {
window.inputState.drawing = true;
const dir = directions[step % 4];
window.inputState.dx = dir.dx;
window.inputState.dy = dir.dy;
step++;
/* 内部の送信関数があれば呼ぶ(即時反映のため) */
if(typeof sendInput === 'function') sendInput();
}
}, 200); /* 0.2秒刻み */
}
};
btn.onclick = toggleRotate;
console.log('離席用ぐるぐるパッチ:インストール完了');
})();