more strict lint
This commit is contained in:
parent
c5529958d5
commit
9ae814dfe4
21 changed files with 211 additions and 157 deletions
|
@ -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') {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
Reference in a new issue