カテゴリー 「javascript」 RSS

2020-04-05

[][][]VORZE A10サイクロンSA遠隔操作するアプリを作った

内容が内容なので匿名ダイアリーに投げ捨てる。

Bluetooth端末で動作する。(CC0 License)

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>A10 Cyclone SA easy controller</title>
</head>

<body>
  <span id="status">initializing...</span>
  <script>
    let status = document.querySelector('span#status');
    let device, characteristic;
    const connect = async _ => {
      try {
        device = await navigator.bluetooth.requestDevice({
          filters: [{ services: ['40ee1111-63ec-4b7f-8ce7-712efd55b90e'] }],
        });
        status.textContent = 'connecting...';
        let server = await device.gatt.connect();
        let service = await server.getPrimaryService('40ee1111-63ec-4b7f-8ce7-712efd55b90e');
        characteristic = await service.getCharacteristic('40ee2222-63ec-4b7f-8ce7-712efd55b90e');
      } catch (e) {
        status.textContent = `failed to connect: ${e.message}`;
        return;
      }

      document.addEventListener('pointermove', evt => {
        evt.preventDefault();
        let y = evt.y / innerHeight * 2 - 1;
        let data = Math.abs(y) * 0x7f | (y < 0 ? 0x80 : 0x00);
        characteristic.writeValue(new Int8Array([0x01, 0x01, data]));
      });
      status.textContent = 'swipe up and down to move';
      document.removeEventListener('click', connect);
    }
    document.addEventListener('click', connect);
    status.textContent = 'tap screen to connect';
  </script>
</body>

</html>

2009-06-05

[][][]すべてのリンク一覧を得る

javascript:document.body.innerHTML=document.body.innerHTML+"<pre%3e"+[].join.call(document.links, "\n")+"\n</pre%3e"

2008-12-30

[][]うごメモ関連付けセレクトボックス

javascript:(function(j){j.src='http://jqueryjs.googlecode.com/files/jquery-1.2.6.min.js';document.body.appendChild(j);setTimeout(function(){$.ready();$('<script src=%22http://query.yahooapis.com/v1/public/yql?q=select%2520content%2520from%2520html%2520where%2520url%253D%2522http%253A%252F%252Fugomemo.hatena.ne.jp%252Fchannels%2522%2520and%2520xpath%253D\'%252F%252Fh3%252Fa\'&amp;format=json&amp;callback=makeSelect%22>').appendTo('body')},1000)})(document.createElement('script'));function makeSelect(o){var s=$('<select name=%22channel-name%22>');$.each(o.query.results.a,function(i,v){$('<option>').text(v).appendTo(s);});$('input.txt').replaceWith(s)}

これでいいのかな。エンコード関係どうなんかね。

 
ログイン ユーザー登録
ようこそ ゲスト さん