<commit_before>window.VimiumInjector === undefined &&
VSettings && document.readyState !== "complete" &&
(function(this: void): void {
  let d: Document | Document["documentElement"] = document
    , script = d.createElement("script") as HTMLScriptElement | Element
    , box: EventTarget | null | false = null
    , secret = "" + ((Math.random() * 1e6 + 1) | 0);
  /**
   * As said in https://github.com/philc/vimium/pull/1797#issuecomment-135761835
   * it's safe enough if only no `document.createElementNS` on scripts initing
   */
  if (!(script instanceof HTMLScriptElement)) { return; }

  function installer(event: CustomEvent): void {
    const t = event.target;
    if (!(t instanceof Element) || event.detail !== secret) { return; }
    event.stopImmediatePropagation();
    removeEventListener("VimiumHook", installer, true);
    if (box === null) {
      t.removeAttribute("data-vimium");
      t.addEventListener("VimiumOnclick", onclick, true);
      box = t;
    }
  }
  addEventListener("VimiumHook", installer, true);
  function onclick(event: Event): void {
    (event.target as Element).vimiumHasOnclick = true;
    event.stopPropagation();
  }
  addEventListener("VimiumOnclick", onclick, true);
  function destroy() {
    const r = removeEventListener;
    /** this function should keep idempotent */
    r("VimiumOnclick", onclick, true);
    if (box) {
      r.call(box, "VimiumOnclick", onclick, true);
      box.dispatchEvent(new CustomEvent("VimiumUnhook", {detail: secret}));
    }
    if (box === null) {
      setTimeout(function(): void { r("VimiumHook", installer, true); }, 1100);
    }
    box = false;
    VSettings && (VSettings.uninit_ = null);
  }
  VSettings.uninit_ = destroy;

  let injected: Function | string = '"use strict";(' + (function VC(this: void): void {
type Call1<T, A, R> = (this: (this: T, a: A) => R, thisArg: T, a: A) => R;
type Call3o<T, A, B, C, R> = (this: (this: T, a: A, b: B, c?: C) => R, thisArg: T, a: A, b: B, c?: C) => R;

const ETP = EventTarget.prototype, _listen = ETP.addEventListener, toRegister: Element[] = [],
_apply = _listen.apply, _call = _listen.call,
call = _call.bind(_call) as <T, R, A, B, C>(func: (this: T, a?: A, b?: B, c?: C) => R, self: T, a?: A, b?: B, c?: C) => R,
dispatch = (_call as Call1<EventTarget, Event, boolean>).bind(ETP.dispatchEvent),
d = document, cs = d.currentScript as HTMLScriptElement, Create = d.createElement as Document["createElement"],
E = Element, EP = E.prototype, Append = EP.appendChild, Contains = EP.contains, Insert = EP.insertBefore,
Attr = EP.setAttribute, HasAttr = EP.hasAttribute, Remove = EP.remove,
contains = Contains.bind(d),
CE = CustomEvent, HA = HTMLAnchorElement, DF = DocumentFragment, HF = HTMLFormElement,
FP = Function.prototype, funcToString = FP.toString,
listen = (_call as Call3o<EventTarget, string, null | ((e: Event) => void), boolean, void>).bind(_listen) as (this: void
  , T: EventTarget, a: string, b: null | ((e: Event) => void), c?: boolean) => void,
rel = removeEventListener, ct = clearTimeout,
sec = <string>cs.getAttribute("data-vimium"),
hooks = {
  toString: function toString(this: Function): string {
    const a = this;
    return call(_apply as (this: (this: Function, ...args: {}[]) => string, self: Function, args: IArguments) => string,
                funcToString,
                a === hooks.addEventListener ? _listen : a === hooks.toString ? funcToString : a, arguments);
  },
  addEventListener: function addEventListener(this: EventTarget, type: string, listener: EventListenerOrEventListenerObject): void {
    const a = this;
    if (type === "click" && listener && !(a instanceof HA || a instanceof HF) && a instanceof E) {
      toRegister.push(a);
      if (timer === 0) { timer = next(); }
    }
    const args = arguments, len = args.length;
    return len === 2 ? listen(a, type, listener) : len === 3 ? listen(a, type, listener, args[2])
      : call(_apply as (this: (this: EventTarget, ...args: {}[]) => void, self: EventTarget, args: IArguments) => void,
             _listen as (this: EventTarget, ...args: {}[]) => void, a, args);
  }
}
;

let handler = function(this: void): void {
  rel("DOMContentLoaded", handler, true);
  ct(timer);
  handler = null as never;
  const d = document, docEl = d.documentElement as HTMLElement | SVGElement;
  if (!docEl) { return destroy(); }
  const el = call(Create, d, "div") as HTMLDivElement, key = "data-vimium";
  call(Attr, el, key, "");
  listen(el, "VimiumUnhook", destroy as (e: CustomEvent) => void, true);
  call(Append, docEl, el), dispatch(el, new CE("VimiumHook", {detail: sec})), call(Remove, el);
  if (call(HasAttr, el, key)) {
    destroy();
  } else {
    box = el;
    timer = toRegister.length > 0 ? next() : 0;
  }
},
next = setTimeout.bind(null as never, function(): void {
  const len = toRegister.length, start = len > 9 ? len - 10 : 0, delta = len - start;<commit_msg>extend_click: safer access to documentElement<commit_after>window.VimiumInjector === undefined &&
VSettings && document.readyState !== "complete" &&
(function(this: void): void {
  let d: Document | Document["documentElement"] = document
    , script = d.createElement("script") as HTMLScriptElement | Element
    , box: EventTarget | null | false = null
    , secret = "" + ((Math.random() * 1e6 + 1) | 0);
  /**
   * As said in https://github.com/philc/vimium/pull/1797#issuecomment-135761835
   * it's safe enough if only no `document.createElementNS` on scripts initing
   */
  if (!(script instanceof HTMLScriptElement)) { return; }

  function installer(event: CustomEvent): void {
    const t = event.target;
    if (!(t instanceof Element) || event.detail !== secret) { return; }
    event.stopImmediatePropagation();
    removeEventListener("VimiumHook", installer, true);
    if (box === null) {
      t.removeAttribute("data-vimium");
      t.addEventListener("VimiumOnclick", onclick, true);
      box = t;
    }
  }
  addEventListener("VimiumHook", installer, true);
  function onclick(event: Event): void {
    (event.target as Element).vimiumHasOnclick = true;
    event.stopPropagation();
  }
  addEventListener("VimiumOnclick", onclick, true);
  function destroy() {
    const r = removeEventListener;
    /** this function should keep idempotent */
    r("VimiumOnclick", onclick, true);
    if (box) {
      r.call(box, "VimiumOnclick", onclick, true);
      box.dispatchEvent(new CustomEvent("VimiumUnhook", {detail: secret}));
    }
    if (box === null) {
      setTimeout(function(): void { r("VimiumHook", installer, true); }, 1100);
    }
    box = false;
    VSettings && (VSettings.uninit_ = null);
  }
  VSettings.uninit_ = destroy;

  let injected: Function | string = '"use strict";(' + (function VC(this: void): void {
type Call1<T, A, R> = (this: (this: T, a: A) => R, thisArg: T, a: A) => R;
type Call3o<T, A, B, C, R> = (this: (this: T, a: A, b: B, c?: C) => R, thisArg: T, a: A, b: B, c?: C) => R;

const ETP = EventTarget.prototype, _listen = ETP.addEventListener, toRegister: Element[] = [],
_apply = _listen.apply, _call = _listen.call,
call = _call.bind(_call) as <T, R, A, B, C>(func: (this: T, a?: A, b?: B, c?: C) => R, self: T, a?: A, b?: B, c?: C) => R,
dispatch = (_call as Call1<EventTarget, Event, boolean>).bind(ETP.dispatchEvent),
d = document, cs = d.currentScript as HTMLScriptElement, Create = d.createElement as Document["createElement"],
E = Element, EP = E.prototype, Append = EP.appendChild, Contains = EP.contains, Insert = EP.insertBefore,
Attr = EP.setAttribute, HasAttr = EP.hasAttribute, Remove = EP.remove,
contains = Contains.bind(d),
CE = CustomEvent, HA = HTMLAnchorElement, DF = DocumentFragment, HF = HTMLFormElement,
FP = Function.prototype, funcToString = FP.toString,
listen = (_call as Call3o<EventTarget, string, null | ((e: Event) => void), boolean, void>).bind(_listen) as (this: void
  , T: EventTarget, a: string, b: null | ((e: Event) => void), c?: boolean) => void,
rel = removeEventListener, ct = clearTimeout,
sec = <string>cs.getAttribute("data-vimium"),
hooks = {
  toString: function toString(this: Function): string {
    const a = this;
    return call(_apply as (this: (this: Function, ...args: {}[]) => string, self: Function, args: IArguments) => string,
                funcToString,
                a === hooks.addEventListener ? _listen : a === hooks.toString ? funcToString : a, arguments);
  },
  addEventListener: function addEventListener(this: EventTarget, type: string, listener: EventListenerOrEventListenerObject): void {
    const a = this;
    if (type === "click" && listener && !(a instanceof HA || a instanceof HF) && a instanceof E) {
      toRegister.push(a);
      if (timer === 0) { timer = next(); }
    }
    const args = arguments, len = args.length;
    return len === 2 ? listen(a, type, listener) : len === 3 ? listen(a, type, listener, args[2])
      : call(_apply as (this: (this: EventTarget, ...args: {}[]) => void, self: EventTarget, args: IArguments) => void,
             _listen as (this: EventTarget, ...args: {}[]) => void, a, args);
  }
}
;

let handler = function(this: void): void {
  rel("DOMContentLoaded", handler, true);
  ct(timer);
  const d = document, docEl = docChildren[0] as HTMLElement | SVGElement | null;
  handler = docChildren = null as never;
  console.log('get docEl:', docEl);
  if (!docEl) { return destroy(); }
  const el = call(Create, d, "div") as HTMLDivElement, key = "data-vimium";
  call(Attr, el, key, "");
  listen(el, "VimiumUnhook", destroy as (e: CustomEvent) => void, true);
  call(Append, docEl, el), dispatch(el, new CE("VimiumHook", {detail: sec})), call(Remove, el);
  if (call(HasAttr, el, key)) {
    destroy();
  } else {
    box = el;
    timer = toRegister.length > 0 ? next() : 0;
  }
},
docChildren = d.children,
next = setTimeout.bind(null as never, function(): void {
  const len = toRegister.length, start = len > 9 ? len - 10 : 0, delta = len - start;
{'fraction_non_alphanumeric': 0.16549295774647887, 'fraction_numerical': 0.007142857142857143, 'mean_word_length': 3.8117134559535333, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 49, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3064249', 'n_tokens_mistral': 3233, 'n_tokens_neox': 3161, 'n_words': 966}