tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

common.js (961B)


      1 function elDesc(el) {
      2  let rv = `<${el.localName}`;
      3  if (el.hasAttribute('contenteditable')) {
      4    rv += ` contenteditable="${el.getAttribute('contenteditable')}"`;
      5  }
      6  if (el.hasAttribute('type')) {
      7    rv += ` type="${el.getAttribute('type')}"`;
      8  }
      9  rv += `>`;
     10  return rv;
     11 }
     12 
     13 function setSelection(el, selectionStart, selectionEnd) {
     14  if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
     15    el.selectionStart = selectionStart;
     16    el.selectionEnd = selectionEnd;
     17  } else {
     18    const s = getSelection();
     19    s.removeAllRanges();
     20    const r = new Range();
     21    r.setStart(el.firstChild || el, selectionStart);
     22    r.setEnd(el.firstChild || el, selectionEnd);
     23    s.addRange(r);
     24  }
     25 }
     26 
     27 function getValue(el) {
     28  if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
     29    return el.value;
     30  }
     31  return el.innerHTML;
     32 }
     33 
     34 const keyMapping = {
     35  "Enter": "\uE006",
     36  "Backspace": "\uE003",
     37  "Delete": "\uE017",
     38 };