Difference between revisions of "Talk:2445: Checkbox"

Explain xkcd: It's 'cause you're dumb.
Jump to: navigation, search
(Scripts: Add script to add a text box)
m (Added a comment about the maze)
Line 94: Line 94:
 
     print("SOJOURNER:", r)
 
     print("SOJOURNER:", r)
 
</pre> Python script to interact directly with SOJOURNER
 
</pre> Python script to interact directly with SOJOURNER
 +
 +
If you try to read the book in the maze, it says "Your eyes swim". [[User:Sarah the Pie(yes, the food)|Sarah the Pie(yes, the food)]] ([[User talk:Sarah the Pie(yes, the food)|talk]]) 16:13, 2 April 2021 (UTC)

Revision as of 16:13, 2 April 2021


It doesn't work as described, fo be. Does it depend on the browser? I'm using Chrome.

[I don't see 'Loading...' or any other text, or a mute button; I do see dots and dashes, but get no sound(s).]

[[Special:Contributions] 06:57, 2 April 2021 (UTC)

To activate the sound, you must click the unmute button on the bottom right corner.

Note that those with a keyboard may press space as well to send the code. May be easier to control than a touchy laptop trackpad 162.158.187.75 10:31, 2 April 2021 (UTC)

Scripts

If your clicking abilities have dwindled since the invention of the vocal telephone, you may use this roughly written script in the webconsole as an aid

 (()=>{
  const checkbox = document.querySelector('#comic>label')
  const asleep = async (dur) => {
    let r
    const p = new Promise(res=>r=res)
    setTimeout(r,dur)
    return p
  }
  const press = async (dur) => {
    checkbox.dispatchEvent(new Event('mousedown'))
    await asleep(dur)
    checkbox.dispatchEvent(new Event('mouseup', { bubbles: true }))
  }
  
  // timings
  const long = async () => press(600)
  const short = async () => press(100)
  const space = async () => asleep(600)      // End character delay
  const endWord = async () => asleep(600)    // End word delay. (same as character)
  const end = async () => await asleep(2100) // End message delay
  
  const type = async (c) =>  {
    if (c == '.') await short()
    else if (c == '-') await long()
    else if (c == ' ') await space()
    else if (c == '/') await endWord()
    //else if (c == '/') await end()
  } 
  const send = async (msg) =>  {
    const code = morse.encode(msg)
    
    // Give checkbox focus and wait a moment so focusin hooks or something may run.
    checkbox.dispatchEvent(new Event('focusin'))
    await asleep(100)
    
    // Type each character
    for await (const char of code)
      await type(char)
  }
  
  // Say something
  send('hi')
 })()
Feel free to fix/clean/shorten/move the script. I put it in a topic to encourage keeping it at the bottom of discussion. 108.162.237.46 10:17, 2 April 2021 (UTC)


JavaScript to be pasted in the browser console. Adds a text box below the comic, in which you can write text and press enter to send it. Responses can be read from the JS console. Ad1217 (talk) 14:53, 2 April 2021 (UTC)

BeepComic.hurryUp();

var input = comic.parentNode.insertBefore(document.createElement('input'), comic.nextSibling);
input.addEventListener("keydown", e => {
  if (e.keyCode == 13) {
    BeepComic.send(morse.encode(e.target.value));
    e.target.value = '';
  }
}, false);
import requests

URL = r"https://xkcd.com/2445/morse/...%s/%s"
enc_map = {"0":"-----","1":".----","2":"..---","3":"...--","4":"....-","5":".....","6":"-....","7":"--...","8":"---..","9":"----.","A":".-","B":"-...","C":"-.-.","D":"-..","E":".","F":"..-.","G":"--.","H":"....","I":"..","J":".---","K":"-.-","L":".-..","M":"--","N":"-.","O":"---","P":".--.","Q":"--.-","R":".-.","S":"...","T":"-","U":"..-","V":"...-","W":".--","X":"-..-","Y":"-.--","Z":"--..",".":".-.-.-",",":"--..--","?":"..--..","'":".----.","!":"-.-.--","/":"-..-.","(":"-.--.",")":"-.--.-","&":".-...",":":"---...",";":"-.-.-.","=":"-...-","+":".-.-.","-":"-....-","_":"..--.-",'"':".-..-.","$":"...-..-","@":".--.-."," ": "/"}
dec_map = dict([(y,x) for x,y in enc_map.items()])

to_morse = lambda text: " ".join(enc_map[i] for i in text if i in enc_map)
from_morse = lambda text:  "".join(dec_map[i] for i in text if i in dec_map)

def get_resp(text, key):
    url = URL%(("/" if len(key) else "") + to_morse(key), to_morse(text))
    c = requests.get(url).content.decode('utf-8')
    c = from_morse(c.split(' '))
    return c[:36], c[37:]

k = ""
while True:
    k,r = get_resp(input("YOU      : "), k)
    print("SOJOURNER:", r)
Python script to interact directly with SOJOURNER

If you try to read the book in the maze, it says "Your eyes swim". Sarah the Pie(yes, the food) (talk) 16:13, 2 April 2021 (UTC)