aboutsummaryrefslogtreecommitdiffstats
path: root/builtAssets/css
diff options
context:
space:
mode:
Diffstat (limited to 'builtAssets/css')
0 files changed, 0 insertions, 0 deletions
t .gu { color: #666 } /* Generic.Subheading */ .highlight .gt { color: #A00 } /* Generic.Traceback */ .highlight .kc { color: #080; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #080; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #080; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #080 } /* Keyword.Pseudo */ .highlight .kr { color: #080; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #00D; font-weight: bold } /* Literal.Number */ .highlight .s { color: #D20; background-color: #FFF0F0 } /* Literal.String */ .highlight .na { color: #369 } /* Name.Attribute */ .highlight .nb { color: #038 } /* Name.Builtin */ .highlight .nc { color: #B06; font-weight: bold } /* Name.Class */ .highlight .no { color: #036; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555 } /* Name.Decorator */ .highlight .ne { color: #B06; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #06B; font-weight: bold } /* Name.Function */ .highlight .nl { color: #369; font-style: italic } /* Name.Label */ .highlight .nn { color: #B06; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #369; font-weight: bold } /* Name.Property */ .highlight .nt { color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
// Dwell is measured on mounted rows, including posts taller than the viewport.
// Sampling also catches fast movement within a large post (IO alone cannot).
// A post read for half a second is a post that may be opened: its thread is
// fetched then (it was 1.2 s, which a quick reader beat to the tap), one at
// a time, a dozen a minute.
const DWELL_MS = 600, PER_MINUTE = 12;
export function createThreadPrefetch({ load, key, cached, doc = globalThis.document,
  nav = globalThis.navigator, now = Date.now, schedule = setTimeout, cancel = clearTimeout }) {
  const seeds = new Map(), dwell = new Map();
  let timer = null, busy = false, starts = [], generation = 0;
  const allowed = () => !doc.hidden && nav?.onLine !== false && !nav?.connection?.saveData
    && !['slow-2g', '2g'].includes(nav?.connection?.effectiveType);
  function tick() {
    timer = null;
    const time = now(), visible = new Set(), mounted = new Set(), ready = [];
    const height = doc.documentElement.clientHeight;
    for (const row of doc.querySelectorAll('[data-thread-prefetch]')) {
      const id = row.getAttribute('data-thread-prefetch'), seed = seeds.get(id);
      mounted.add(id);
      if (!seed || !allowed() || cached(seed)) continue;
      const r = row.getBoundingClientRect();
      const overlap = Math.min(r.bottom, height) - Math.max(r.top, 0);
      if (overlap < Math.min(r.height, height) * 0.5 || overlap <= 0) continue;
      visible.add(id);
      let d = dwell.get(id);
      // More than 100px/s is still scrolling past; slow reading can qualify.
      if (!d || Math.abs(r.top - d.top) > 25) d = { since: time, top: r.top };
      d.top = r.top;
      dwell.set(id, d);
      if (time - d.since >= DWELL_MS) ready.push(seed);
    }
    for (const id of seeds.keys()) if (!mounted.has(id)) seeds.delete(id);
    for (const id of dwell.keys()) if (!visible.has(id)) dwell.delete(id);
    starts = starts.filter((t) => time - t < 60000);
    if (!busy && starts.length < PER_MINUTE && ready.length) {
      const seed = ready[0], token = generation;
      busy = true; starts.push(time);
      // The loader inserts synchronously, so clicks share its in-flight work.
      Promise.resolve().then(() => token === generation && load(seed)).catch(() => {}).finally(() => {
        if (token === generation) busy = false;
      });
      for (const [id, ev] of seeds) if (key(ev) === key(seed)) dwell.delete(id);
    }
    if (seeds.size) timer = schedule(tick, 250);
  }
  return {
    watch(seed) {
      if (!doc) return;
      seeds.set(seed.id, seed);
      if (timer === null) timer = schedule(tick, 250);
    },
    stop() {
      generation++; cancel(timer); timer = null; busy = false;
      seeds.clear(); dwell.clear(); starts = [];
    },
  };
}