diff options
Diffstat (limited to 'src/content')
| -rw-r--r-- | src/content/follow.js | 32 | ||||
| -rw-r--r-- | src/content/hint-key-producer.js | 6 | ||||
| -rw-r--r-- | src/content/hint.js | 5 | ||||
| -rw-r--r-- | src/content/histories.js | 4 | ||||
| -rw-r--r-- | src/content/index.js | 8 | ||||
| -rw-r--r-- | src/content/scrolls.js | 4 | 
6 files changed, 35 insertions, 24 deletions
| diff --git a/src/content/follow.js b/src/content/follow.js index ffa16b9..5abeee0 100644 --- a/src/content/follow.js +++ b/src/content/follow.js @@ -1,7 +1,7 @@  import Hint from './hint';  import HintKeyProducer from './hint-key-producer'; -const DEFAULT_HINT_CHARSET = 'abcdefghijklmnopqrstuvwxyz' +const DEFAULT_HINT_CHARSET = 'abcdefghijklmnopqrstuvwxyz';  export default class Follow {    constructor(doc) { @@ -22,14 +22,14 @@ export default class Follow {      let producer = new HintKeyProducer(DEFAULT_HINT_CHARSET);      Array.prototype.forEach.call(elements, (ele) => {        let keys = producer.produce(); -      let hint = new Hint(ele, keys) +      let hint = new Hint(ele, keys);        this.hintElements[keys] = hint;      });    }    handleKeydown(e) { -    let keyCode = e.keyCode; +    let { keyCode } = e;      if (keyCode === KeyboardEvent.DOM_VK_ESCAPE) {        this.remove();        return; @@ -56,10 +56,10 @@ export default class Follow {      let hidden = Object.keys(this.hintElements).filter((key) => {        return !key.startsWith(chars);      }); -    if (shown.length == 0) { +    if (shown.length === 0) {        this.remove();        return; -    } else if (shown.length == 1) { +    } else if (shown.length === 1) {        this.remove();        this.hintElements[chars].activate();      } @@ -74,7 +74,7 @@ export default class Follow {    remove() { -    this.doc.removeEventListener("keydown", this.boundKeydown); +    this.doc.removeEventListener('keydown', this.boundKeydown);      Object.keys(this.hintElements).forEach((key) => {        this.hintElements[key].remove();      }); @@ -87,6 +87,14 @@ export default class Follow {      );    } +  static isNumericKey(code) { +    return KeyboardEvent.DOM_VK_0 <= code && code <= KeyboardEvent.DOM_VK_9; +  } + +  static isAlphabeticKey(code) { +    return KeyboardEvent.DOM_VK_A <= code && code <= KeyboardEvent.DOM_VK_Z; +  } +    static codeChars(codes) {      const CHARCODE_ZERO = '0'.charCodeAt(0);      const CHARCODE_A = 'a'.charCodeAt(0); @@ -94,10 +102,12 @@ export default class Follow {      let chars = '';      for (let code of codes) { -      if (KeyboardEvent.DOM_VK_0 <= code && code <= KeyboardEvent.DOM_VK_9) { -        chars += String.fromCharCode(code - KeyboardEvent.DOM_VK_0 + CHARCODE_ZERO); -      } else if (KeyboardEvent.DOM_VK_A <= code && code <= KeyboardEvent.DOM_VK_Z) { -        chars += String.fromCharCode(code - KeyboardEvent.DOM_VK_A + CHARCODE_A); +      if (Follow.isNumericKey(code)) { +        chars += String.fromCharCode( +          code - KeyboardEvent.DOM_VK_0 + CHARCODE_ZERO); +      } else if (Follow.isAlphabeticKey(code)) { +        chars += String.fromCharCode( +          code - KeyboardEvent.DOM_VK_A + CHARCODE_A);        }      }      return chars; @@ -112,7 +122,7 @@ export default class Follow {    }    static isVisibleElement(element) { -    var style = window.getComputedStyle(element); +    let style = window.getComputedStyle(element);      if (style.display === 'none') {        return false;      } else if (style.visibility === 'hidden') { diff --git a/src/content/hint-key-producer.js b/src/content/hint-key-producer.js index 8064afb..14b23b6 100644 --- a/src/content/hint-key-producer.js +++ b/src/content/hint-key-producer.js @@ -11,19 +11,19 @@ export default class HintKeyProducer {    produce() {      this.increment(); -    return this.counter.map((x) => this.charset[x]).join(''); +    return this.counter.map(x => this.charset[x]).join('');    }    increment() {      let max = this.charset.length - 1; -    if (this.counter.every((x) => x == max)) { +    if (this.counter.every(x => x === max)) {        this.counter = new Array(this.counter.length + 1).fill(0);        return;      }      this.counter.reverse();      let len = this.charset.length; -    let num = this.counter.reduce((x,y,index) => x + y * (len ** index)) + 1; +    let num = this.counter.reduce((x, y, index) => x + y * len ** index) + 1;      for (let i = 0; i < this.counter.length; ++i) {        this.counter[i] = num % len;        num = ~~(num / len); diff --git a/src/content/hint.js b/src/content/hint.js index fabf725..c75ca8b 100644 --- a/src/content/hint.js +++ b/src/content/hint.js @@ -8,10 +8,9 @@ export default class Hint {      this.target = target; -    let doc = target.ownerDocument +    let doc = target.ownerDocument;      let { top, left } = target.getBoundingClientRect(); -    let scrollX = window.scrollX; -    let scrollY = window.scrollY; +    let { scrollX, scrollY } = window;      this.element = doc.createElement('span');      this.element.className = 'vimvixen-hint'; diff --git a/src/content/histories.js b/src/content/histories.js index 2e34dc6..9c5665d 100644 --- a/src/content/histories.js +++ b/src/content/histories.js @@ -1,8 +1,8 @@  const prev = (win) => { -  win.history.back() +  win.history.back();  };  const next = (win) => { -  win.history.forward() +  win.history.forward();  };  export { prev, next }; diff --git a/src/content/index.js b/src/content/index.js index 5d3735c..91f5420 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -4,11 +4,11 @@ import * as scrolls from '../content/scrolls';  import * as histories from '../content/histories';  import Follow from '../content/follow';  import operations from '../operations'; -import messages  from '../messages'; +import messages from '../messages';  consoleFrames.initialize(window.document); -window.addEventListener("keypress", (e) => { +window.addEventListener('keypress', (e) => {    if (e.target instanceof HTMLInputElement) {      return;    } @@ -40,14 +40,14 @@ const execOperation = (operation) => {    case operations.HISTORY_NEXT:      return histories.next(window);    } -} +};  const update = (state) => {    if (!state.console.commandShown) {      window.focus();      consoleFrames.blur(window.document);    } -} +};  browser.runtime.onMessage.addListener((action) => {    switch (action.type) { diff --git a/src/content/scrolls.js b/src/content/scrolls.js index bc88e43..b1cea6f 100644 --- a/src/content/scrolls.js +++ b/src/content/scrolls.js @@ -37,4 +37,6 @@ const scrollRight = (page) => {    page.scrollTo(x, y);  }; -export { scrollLines, scrollPages, scrollTop, scrollBottom, scrollLeft, scrollRight } +export { +  scrollLines, scrollPages, scrollTop, scrollBottom, scrollLeft, scrollRight +}; | 
