okami.mom/albedo

git clone https://git.nkp.pet/okami.mom/albedo

dawnextensions: add cdp browser tool7de30f7

main
1.4 KiB35 linesraw
1"""Small page-side functions; values cross the boundary, not live JS handles."""
2
3STATE = r"""function() {
4  const e = this.nodeType === 1 ? this : this.parentElement;
5  if (!e || !e.isConnected) return {connected:false};
6  const r = e.getBoundingClientRect(), s = getComputedStyle(e);
7  return {connected:true, tag:e.tagName.toLowerCase(), type:e.type || '',
8    disabled:!!e.disabled || e.getAttribute('aria-disabled') === 'true',
9    readonly:!!e.readOnly || e.getAttribute('aria-readonly') === 'true',
10    editable:e.isContentEditable,
11    visible:r.width > 0 && r.height > 0 && s.visibility === 'visible'
12      && s.display !== 'none' && Number(s.opacity) !== 0,
13    width:r.width, height:r.height};
14}"""
15
16CONTAINS = r"""function(hit) {
17  const e = this.nodeType === 1 ? this : this.parentElement;
18  for (let n = hit; n; n = n.parentNode || n.host) if (n === e) return true;
19  return false;
20}"""
21
22SELECT_TEXT = r"""function() {
23  this.focus();
24  if (this.getRootNode().activeElement !== this) return false;
25  if (typeof this.select === 'function') this.select();
26  else if (this.isContentEditable) {
27    const range = this.ownerDocument.createRange(); range.selectNodeContents(this);
28    const sel = this.ownerDocument.getSelection(); sel.removeAllRanges(); sel.addRange(range);
29  } else return false;
30  return true;
31}"""
32
33READ_VALUE = (
34    r"""function() { return this.isContentEditable ? this.textContent : this.value; }"""
35)