• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5function $(id) {
6  return document.querySelector(id);
7}
8
9// ===========================================================================
10document.addEventListener('DOMContentLoaded', function () {
11  installFormChangeHandler()
12});
13
14
15function installFormChangeHandler() {
16  initForm();
17  let inputs = document.getElementsByTagName("input");
18  for (let i = 0; i < inputs.length; i++){
19     inputs[i].onchange = onFormChange;
20  }
21}
22
23function initForm() {
24  chrome.runtime.sendMessage({type:'get'}, function(response) {
25    updateFromMessage(response);
26  });
27}
28// ===========================================================================
29
30function updateFromMessage(msg) {
31  $("#minInterval").value = msg.minInterval;
32  $("#maxInterval").value = msg.maxInterval;
33  $("#pattern").value = msg.pattern;
34  $("#enabled").checked = msg.enabled;
35  $("#minIntervalValue").innerText = msg.minInterval+"ms";
36  $("#maxIntervalValue").innerText = msg.maxInterval+"ms";
37}
38
39function onFormChange() {
40  let minInterval = $("#minInterval").value;
41  let maxInterval = $("#maxInterval").value;
42
43  let message = {
44    type: 'update',
45    minInterval: minInterval,
46    maxInterval: maxInterval,
47    pattern: $("#pattern").value,
48    enabled: $("#enabled").checked
49  }
50  chrome.runtime.sendMessage(message, function(response) {
51    updateFromMessage(response);
52  });
53}
54