es2016 WIP

es2016
Thibault Duplessis 2019-02-28 17:27:57 +07:00
parent 35b164740f
commit 65516365a1
63 changed files with 148 additions and 150 deletions

View File

@ -56,7 +56,7 @@ $(function() {
$editor.find('.panel.' + $(this).data('tab')).addClass('active');
$editor.find('div.status').removeClass('saved');
});
var submit = lichess.fp.debounce(function() {
var submit = lichess.debounce(function() {
$editor.find('form.form3').ajaxSubmit({
success: function() {
$editor.find('div.status').addClass('saved');

View File

@ -153,5 +153,5 @@ lichess.startEmbeddedAnalyse = function(opts) {
lichess.dispatchEvent(document.body, 'chessground.resize');
};
onResize();
window.addEventListener('resize', lichess.fp.debounce(onResize, 500));
window.addEventListener('resize', lichess.debounce(onResize, 500));
};

View File

@ -91,6 +91,6 @@ $(function() {
$form.submit();
};
$form.find("select, input[type=checkbox]").change(submit);
$usernames.on("keyup", lichess.fp.debounce(submit, 1500));
$usernames.on("keyup", lichess.debounce(submit, 1500));
}
});

View File

@ -1,7 +1,7 @@
$(function() {
var $form = $('.signup_box form');
var $exists = $form.find('.username .exists');
var runCheck = lichess.fp.debounce(function() {
var runCheck = lichess.debounce(function() {
var name = $username.val();
if (name.length >= 3) $.ajax({
method: 'GET',

View File

@ -21,11 +21,7 @@ interface Lichess {
loadedCss: [string];
escapeHtml(str: string): string
toYouTubeEmbedUrl(url: string): string
fp: {
debounce(func: (...args: any[]) => void, wait: number, immediate?: boolean): (...args: any[]) => void;
contains<T>(list: T[], needle: T): boolean;
contains(str: string, c: string): boolean;
}
debounce(func: (...args: any[]) => void, wait: number, immediate?: boolean): (...args: any[]) => void;
sound: any
powertip: any
userAutocomplete: any
@ -126,14 +122,6 @@ interface LightUser {
patron?: boolean
}
interface Array<T> {
find(f: (t: T) => boolean): T | undefined;
}
interface Math {
log2?: (x: number) => number;
}
interface WebAssemblyStatic {
validate(bufferSource: ArrayBuffer | Uint8Array): boolean
Memory: any

View File

@ -321,7 +321,7 @@ export default class AnalyseCtrl {
}
playedLastMoveMyself = () =>
!!this.justPlayed && !!this.node.uci && this.node.uci.indexOf(this.justPlayed) === 0;
!!this.justPlayed && !!this.node.uci && this.node.uci.startsWith(this.justPlayed);
jump(path: Tree.Path): void {
const pathChanged = path !== this.path,
@ -334,7 +334,7 @@ export default class AnalyseCtrl {
if (isForwardStep) {
if (!this.node.uci) this.sound.move(); // initial position
else if (!playedMyself) {
if (this.node.san!.indexOf('x') !== -1) this.sound.capture();
if (this.node.san!.includes('x')) this.sound.capture();
else this.sound.move();
}
if (/\+|\#/.test(this.node.san!)) this.sound.check();

View File

@ -63,7 +63,7 @@ function toCeval(e) {
export function make(opts): EvalCache {
const fenFetched: string[] = [];
function hasFetched(node): boolean {
return fenFetched.indexOf(node.fen) !== -1;
return fenFetched.includes(node.fen);
};
let upgradable = prop(false);
return {

View File

@ -58,7 +58,7 @@ export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
effectiveVariant = data.game.variant.key === 'fromPosition' ? 'standard' : data.game.variant.key,
config = configCtrl(data.game, onConfigClose, root.trans, root.redraw);
const fetch = window.lichess.fp.debounce(function() {
const fetch = window.lichess.debounce(function() {
const fen = root.node.fen;
const request: JQueryPromise<ExplorerData> = (withGames && tablebaseRelevant(effectiveVariant, fen)) ?
xhr.tablebase(opts.tablebaseEndpoint, effectiveVariant, fen) :

View File

@ -137,7 +137,7 @@ const analysisGlyphs = ['?!', '?', '??'];
function renderAcpl(ctrl: AnalyseController, style: Style): MaybeVNodes | undefined {
const anal = ctrl.data.analysis;
if (!anal) return undefined;
const analysisNodes = ctrl.mainline.filter(n => (n.glyphs || []).find(g => analysisGlyphs.indexOf(g.symbol) > -1));
const analysisNodes = ctrl.mainline.filter(n => (n.glyphs || []).find(g => analysisGlyphs.includes(g.symbol)));
const res: Array<VNode> = [];
['white', 'black'].forEach((color: Color) => {
const acpl = anal[color].acpl;

View File

@ -23,17 +23,16 @@ export function make(root: AnalyseCtrl): RetroCtrl {
const current = prop<any>(null);
const feedback = prop<Feedback>('find');
const contains = window.lichess.fp.contains;
const redraw = root.redraw;
function isPlySolved(ply: Ply): boolean {
return contains(solvedPlies, ply)
return solvedPlies.includes(ply);
};
function findNextNode(): Tree.Node | undefined {
const colorModulo = root.bottomIsWhite() ? 1 : 0;
candidateNodes = evalSwings(root.mainline, function(n) {
return n.ply % 2 === colorModulo && !contains(explorerCancelPlies, n.ply);
return n.ply % 2 === colorModulo && !explorerCancelPlies.includes(n.ply);
});
return candidateNodes.find(n => !isPlySolved(n.ply));
};

View File

@ -274,7 +274,7 @@ export default function(data: StudyData, ctrl: AnalyseCtrl, tagTypes: TagTypes,
return obj;
}
const likeToggler = window.lichess.fp.debounce(() => send("like", { liked: data.liked }), 1000);
const likeToggler = li.debounce(() => send("like", { liked: data.liked }), 1000);
const socketHandlers = {
path(d) {

View File

@ -62,7 +62,7 @@ function renderPgnTags(chapter: StudyChapter, submit, types: string[]): VNode {
}, [
h('option', 'New tag'),
...types.map(t => {
if (!window.lichess.fp.contains(existingTypes, t)) return option(t, '', t);
if (!existingTypes.includes(t)) return option(t, '', t);
})
]),
editable('', (value, el) => {

View File

@ -170,9 +170,9 @@ function renderMainlineCommentsOf(ctx: Ctx, node: Tree.Node, conceal: Conceal, w
return node.comments!.map(comment => {
if (comment.by === 'lichess' && !ctx.showComputer) return;
let sel = 'comment' + colorClass;
if (comment.text.indexOf('Inaccuracy.') === 0) sel += '.inaccuracy';
else if (comment.text.indexOf('Mistake.') === 0) sel += '.mistake';
else if (comment.text.indexOf('Blunder.') === 0) sel += '.blunder';
if (comment.text.startsWith('Inaccuracy.')) sel += '.inaccuracy';
else if (comment.text.startsWith('Mistake.')) sel += '.mistake';
else if (comment.text.startsWith('Blunder.')) sel += '.blunder';
if (conceal) sel += '.' + conceal;
const by = node.comments![1] ? `<span class="by">${commentAuthorText(comment.by)}</span>` : '',
truncated = truncateComment(comment.text, 400, ctx);

View File

@ -10,7 +10,8 @@
"noImplicitReturns": false,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -36,7 +36,6 @@
"dependencies": {
"chess": "1.0.0",
"common": "1.0.0",
"defer-promise": "^1.0.1",
"snabbdom": "ornicar/snabbdom#0.7.1-lichess"
}
}

View File

@ -1,4 +1,3 @@
import defer = require('defer-promise');
import { WorkerOpts, Work } from './types';
const EVAL_REGEX = new RegExp(''
@ -56,13 +55,13 @@ export default class Protocol {
if (!matches) return;
let depth = parseInt(matches[1]),
multiPv = parseInt(matches[2]),
isMate = matches[3] === 'mate',
ev = parseInt(matches[4]),
evalType = matches[5],
nodes = parseInt(matches[6]),
elapsedMs: number = parseInt(matches[7]),
moves = matches[8].split(' ');
multiPv = parseInt(matches[2]),
isMate = matches[3] === 'mate',
ev = parseInt(matches[4]),
evalType = matches[5],
nodes = parseInt(matches[6]),
elapsedMs: number = parseInt(matches[7]),
moves = matches[8].split(' ');
// Sometimes we get #0. Let's just skip it.
if (isMate && !ev) return;
@ -136,3 +135,12 @@ export default class Protocol {
return !this.stopped;
}
};
function defer<A>(): DeferPromise.Deferred<A> {
const deferred: Partial<DeferPromise.Deferred<A>> = {}
deferred.promise = new Promise<A>(function (resolve, reject) {
deferred.resolve = resolve
deferred.reject = reject
})
return deferred as DeferPromise.Deferred<A>;
}

View File

@ -13,7 +13,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5", "ES2015.Promise"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -8,7 +8,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -6,7 +6,7 @@ import { spinner } from './util'
export function noteCtrl(opts: NoteOpts): NoteCtrl {
let text: string
const doPost = window.lichess.fp.debounce(() => {
const doPost = window.lichess.debounce(() => {
xhr.setNote(opts.id, text);
}, 1000);
return {

View File

@ -12,7 +12,9 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -12,6 +12,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5"
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -8,7 +8,8 @@
"alwaysStrict": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -12,7 +12,9 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -80,7 +80,7 @@ function imageInput(ctrl: BackgroundCtrl) {
},
hook: {
insert: vnode => {
$(vnode.elm as HTMLElement).on('change keyup paste', window.lichess.fp.debounce(function(this: HTMLElement) {
$(vnode.elm as HTMLElement).on('change keyup paste', window.lichess.debounce(function(this: HTMLElement) {
ctrl.setImage($(this).val());
}, 200));
}

View File

@ -22,7 +22,7 @@ export function ctrl(data: BoardData, trans: Trans, publishZoom: PublishZoom, re
data.zoom = data.zoom || 100;
const saveZoom = window.lichess.fp.debounce(() => {
const saveZoom = window.lichess.debounce(() => {
$.ajax({ method: 'post', url: '/pref/zoom?v=' + data.zoom });
}, 1000);

View File

@ -59,7 +59,7 @@ export function view(ctrl: SoundCtrl): VNode {
}
function makeSlider(ctrl: SoundCtrl, vnode: VNode) {
const setVolume = window.lichess.fp.debounce(ctrl.volume, 50);
const setVolume = window.lichess.debounce(ctrl.volume, 50);
window.lichess.slider().done(() => {
$(vnode.elm as HTMLElement).slider({
orientation: 'vertical',

View File

@ -8,7 +8,8 @@
"alwaysStrict": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -95,7 +95,7 @@ function onMouseEvent(ctrl) {
if (
e.type === 'contextmenu' &&
['pointer', 'trash'].indexOf(sel) === -1 && sel.length >= 2
!['pointer', 'trash'].includes(sel) && sel.length >= 2
) {
ctrl.chessground.cancelMove();
sel[0] = util.opposite(sel[0]);

View File

@ -254,7 +254,7 @@ function sparePieces(ctrl, color, orientation, position) {
function onSelectSparePiece(ctrl, s, upEvent) {
return function(e) {
if (['pointer', 'trash'].indexOf(s) !== -1) {
if (!['pointer', 'trash'].includes(s)) {
ctrl.vm.selected(s);
} else {
ctrl.vm.selected('pointer');

View File

@ -12,7 +12,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -37,7 +37,7 @@ module.exports = {
keys = readKeys(keys);
return function(level) {
for (var key in level.chess.occupation())
if (keys.indexOf(key) === -1) return true;
if (!keys.includes(key)) return true;
return false;
};
},

View File

@ -26,7 +26,7 @@ module.exports = {
delete items[key];
},
hasItem: function(item) {
return list().indexOf(item) !== -1;
return list().includes(item);
},
appleKeys: function() {
var keys = [];

View File

@ -33,7 +33,7 @@ module.exports = function(cfg, element) {
langs.push($('html').attr('lang'));
$('.lobby__streams a, .event-spotlight').each(function() {
var match = $(this).text().match(/\[(\w{2})\]/mi);
if (match && langs.indexOf(match[1].toLowerCase()) === -1) $(this).hide();
if (match && !langs.includes(match[1].toLowerCase())) $(this).hide();
});
};
filterStreams();
@ -210,7 +210,7 @@ module.exports = function(cfg, element) {
var aiOk = typ != 'ai' || variantId != '3' || limit >= 1;
if (timeOk && ratedOk && aiOk) {
$submits.toggleClass('nope', false);
$submits.filter(':not(.random)').toggle(!rated || randomColorVariants.indexOf(variantId) === -1);
$submits.filter(':not(.random)').toggle(!rated || !randomColorVariants.includes(variantId));
} else $submits.toggleClass('nope', true);
};
var showRating = function() {
@ -359,7 +359,7 @@ module.exports = function(cfg, element) {
}).trigger('change');
var $fenInput = $fenPosition.find('input');
var validateFen = lichess.fp.debounce(function() {
var validateFen = lichess.debounce(function() {
$fenInput.removeClass("success failure");
var fen = $fenInput.val();
if (fen) {
@ -432,13 +432,12 @@ module.exports = function(cfg, element) {
}
});
$(this).addClass('active').siblings().removeClass('active');
$.modal.close();
return false;
}).on('click', function() {
return false;
});
if (['#ai', '#friend', '#hook'].indexOf(location.hash) !== -1) {
if (['#ai', '#friend', '#hook'].includes(location.hash)) {
$startButtons
.find('.config_' + location.hash.replace('#', ''))
.each(function() {

View File

@ -205,7 +205,7 @@ export default class LobbyController {
private startWatching() {
const newIds = this.data.nowPlaying
.map(p => p.gameId)
.filter(id => this.alreadyWatching.indexOf(id) === -1);
.filter(id => !this.alreadyWatching.includes(id));
if (newIds.length) {
setTimeout(() => this.socket.send("startWatching", newIds.join(' ')), 2000);
newIds.forEach(id => this.alreadyWatching.push(id));
@ -235,7 +235,7 @@ export default class LobbyController {
// after click on round "new opponent" button
private onNewOpponent() {
if (location.hash.indexOf('#pool/') === 0) {
if (location.hash.startsWith('#pool/')) {
const regex = /^#pool\/(\d+\+\d+)(?:\/(.+))?$/,
match = regex.exec(location.hash),
member: any = { id: match![1], blocking: match![2] },

View File

@ -8,22 +8,21 @@ interface Filtered {
export default function(ctrl: LobbyController, hooks: Hook[]): Filtered {
const f = ctrl.data.filter,
seen: string[] = [],
visible: Hook[] = [],
contains = window.lichess.fp.contains;
seen: string[] = [],
visible: Hook[] = [];
let variant: string, hidden = 0;
hooks.forEach(function(hook) {
variant = hook.variant;
if (hook.action === 'cancel') visible.push(hook);
else {
if (!contains(f.variant, variant) ||
!contains(f.mode, hook.ra || 0) ||
!contains(f.speed, hook.s || 1 /* ultrabullet = bullet */) ||
if (!f.variant.includes(variant) ||
!f.mode.includes(hook.ra || 0) ||
!f.speed.includes(hook.s || 1 /* ultrabullet = bullet */) ||
(f.rating && (!hook.rating || (hook.rating < f.rating[0] || hook.rating > f.rating[1])))) {
hidden++;
} else {
var hash = hook.ra + variant + hook.t + hook.rating;
if (!contains(seen, hash)) visible.push(hook);
const hash = hook.ra + variant + hook.t + hook.rating;
if (!seen.includes(hash)) visible.push(hook);
seen.push(hash);
}
}

View File

@ -40,7 +40,7 @@ export function remove(ctrl: LobbyController, id) {
}
export function syncIds(ctrl: LobbyController, ids) {
ctrl.data.hooks = ctrl.data.hooks.filter(function(h) {
return ids.indexOf(h.id) !== -1;
return ids.includes(h.id);
});
}
export function find(ctrl: LobbyController, id) {

View File

@ -6,7 +6,7 @@ function initialize(ctrl: LobbyController, el) {
const $div = $(el),
$ratingRange = $div.find('.rating-range');
const save = window.lichess.fp.debounce(function() {
const save = window.lichess.debounce(function() {
const $form = $div.find('form');
$.ajax({
url: $form.attr('action'),

View File

@ -9,7 +9,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -8,7 +8,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -26,8 +26,9 @@
},
"devDependencies": {
"@types/lichess": "1.0.0",
"game": "1.0.0",
"typescript": "^3"
},
"dependencies": {}
"dependencies": {
"snabbdom": "ornicar/snabbdom#0.7.1-lichess"
}
}

View File

@ -19,7 +19,7 @@ export function loadCss() {
export function supportedVariant(key: string) {
return [
'standard', 'chess960', 'kingOfTheHill', 'threeCheck', 'fromPosition'
].indexOf(key) > -1;
].includes(key);
}
export function styleSetting(): Setting<Style> {
@ -38,10 +38,9 @@ export function styleSetting(): Setting<Style> {
export function renderSan(san: San, uci: Uci | undefined, style: Style) {
if (!san) return '';
const has = window.lichess.fp.contains;
let move: string;
if (has(san, 'O-O-O')) move = 'long castling';
else if (has(san, 'O-O')) move = 'short castling';
if (san.includes('O-O-O')) move = 'long castling';
else if (san.includes('O-O')) move = 'short castling';
else if (style === 'san') move = san.replace(/[\+#]/, '');
else if (style === 'uci') move = uci || san;
else {
@ -56,8 +55,8 @@ export function renderSan(san: San, uci: Uci | undefined, style: Style) {
return roles[c] || c;
}).join(' ');
}
if (has(san, '+')) move += ' check';
if (has(san, '#')) move += ' checkmate';
if (san.includes('+')) move += ' check';
if (san.includes('#')) move += ' checkmate';
return move;
}
@ -93,7 +92,7 @@ export function renderPieceKeys(pieces: Pieces, p: string, style: Style): string
export function renderPiecesOn(pieces: Pieces, rankOrFile: string): string {
let res: string[] = [], piece: Piece | undefined;
for (let k of allKeys) {
if (k.indexOf(rankOrFile) > -1) {
if (k.includes(rankOrFile)) {
piece = pieces[k];
res.push(piece ? `${piece.color} ${piece.role}` : (
parseInt(k, 35) % 2 ? 'dark' : 'light'

View File

@ -12,7 +12,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -9,7 +9,8 @@
"noImplicitReturns": false,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -19,7 +19,7 @@ export function subscribe(ctrl: RoundController): void {
li.storage.make('ceval.fen').listen(ev => {
const v = ev.newValue;
if (!v) return;
else if (v.indexOf('start:') === 0) return li.storage.set('round.ongoing', v);
else if (v.startsWith('start:')) return li.storage.set('round.ongoing', v);
const d = ctrl.data;
if (!found && ctrl.ply > 14 && ctrl.isPlaying() &&
truncateFen(plyStep(d, ctrl.ply).fen) === truncateFen(v)) {

View File

@ -29,5 +29,5 @@ export function valid(data: RoundData, role: cg.Role, key: cg.Key): boolean {
const drops = dropStr.match(/.{2}/g) || [];
return drops.indexOf(key) !== -1;
return drops.includes(key);
}

View File

@ -216,7 +216,7 @@ export default class RoundController {
}
this.chessground.set(config);
if (s.san && isForwardStep) {
if (s.san.indexOf('x') !== -1) sound.capture();
if (s.san.includes('x')) sound.capture();
else sound.move();
if (/[+#]/.test(s.san)) sound.check();
}

View File

@ -55,7 +55,7 @@ function makeBindings(opts: any, submit: Function, clear: Function) {
*/
opts.input.addEventListener('keyup', function(e: KeyboardEvent) {
const v = (e.target as HTMLInputElement).value;
if (v.indexOf('/') > -1) {
if (v.includes('/')) {
focusChat();
clear();
}
@ -81,7 +81,7 @@ function sanToUci(san: string, sans: DecodedDests): Key[] | undefined {
function sanCandidates(san: string, sans: DecodedDests) {
const lowered = san.toLowerCase();
return Object.keys(sans).filter(function(s) {
return s.toLowerCase().indexOf(lowered) === 0;
return s.toLowerCase().startsWith(lowered);
});
}

View File

@ -145,7 +145,7 @@ function onSubmit(ctrl: RoundController, notify: (txt: string) => void, style: (
legalUcis = destsToUcis(ctrl.chessground.state.movable.dests!),
sans: Sans = sanWriter(plyStep(d, ctrl.ply).fen, legalUcis) as Sans,
uci = sanToUci(input, sans) || input;
if (legalUcis.indexOf(uci.toLowerCase()) >= 0) ctrl.socket.send("move", {
if (legalUcis.includes(uci.toLowerCase())) ctrl.socket.send("move", {
from: uci.substr(0, 2),
to: uci.substr(2, 2),
promotion: uci.substr(4, 1)

View File

@ -82,7 +82,7 @@ function slidingMovesTo(s, deltas, board) {
}
function sanOf(board, uci) {
if (uci.indexOf('@') !== -1) return fixCrazySan(uci);
if (uci.includes('@')) return fixCrazySan(uci);
var move = decomposeUci(uci);
var from = square(move[0]);
@ -139,8 +139,7 @@ export default function sanWriter(fen, ucis) {
ucis.forEach(function(uci) {
var san = sanOf(board, uci);
sans[san] = uci;
if (san.indexOf('x') !== -1)
sans[san.replace('x', '')] = uci;
if (san.includes('x')) sans[san.replace('x', '')] = uci;
});
return sans;
}

View File

@ -21,7 +21,7 @@ export function massage(d: RoundData): void {
if (d.correspondence) d.correspondence.showBar = d.pref.clockBar;
if (['horde', 'crazyhouse'].indexOf(d.game.variant.key) !== -1) d.pref.showCaptured = false;
if (['horde', 'crazyhouse'].includes(d.game.variant.key)) d.pref.showCaptured = false;
if (d.expiration) d.expiration.movedAt = Date.now() - d.expiration.idleMillis;
};

View File

@ -10,7 +10,8 @@
"noImplicitAny": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -19,7 +19,7 @@ module.exports = function(env) {
var newIds = this.data.pairings.map(function(p) {
return p.game.id;
}).filter(function(id) {
return alreadyWatching.indexOf(id) === -1;
return !alreadyWatching.includes(id);
});
if (newIds.length) {
setTimeout(function() {

View File

@ -256,7 +256,7 @@ lichess.topMenuIntent = function() {
url: $a.attr('href'),
type: 'post',
success: function(html) {
if (html.indexOf('relation_actions') > -1) $a.parent().html(html);
if (html.includes('relation_actions')) $a.parent().html(html);
else $a.replaceWith(html);
}
});
@ -477,7 +477,7 @@ lichess.topMenuIntent = function() {
$(el).find('.paginated[data-dedup]').each(function() {
var id = $(this).data('dedup');
if (id) {
if (lichess.fp.contains(ids, id)) $(this).remove();
if (ids.includes(id)) $(this).remove();
else ids.push(id);
}
});
@ -551,8 +551,12 @@ lichess.topMenuIntent = function() {
return false;
});
if (!getComputedStyle(document.body).getPropertyValue('--grid'))
$.get(lichess.assetUrl('oops/browser.html'), html => $('body').prepend(html))
if (!lichess.storage.get('grid')) setTimeout(function() {
if (getComputedStyle(document.body).getPropertyValue('--grid'))
lichess.storage.set('grid', 1);
else
$.get(lichess.assetUrl('oops/browser.html'), html => $('body').prepend(html))
}, 3000);
if (window.Fingerprint2) setTimeout(function() {
var t = Date.now()
@ -615,7 +619,7 @@ lichess.topMenuIntent = function() {
var collection = new memoize(function(k) {
var set = soundSet;
if (set === 'music') {
if (lichess.fp.contains(['move', 'capture', 'check'], k)) return {
if (['move', 'capture', 'check'].includes(k)) return {
play: $.noop
};
set = 'standard';

View File

@ -2,7 +2,7 @@ var lichess = window.lichess = window.lichess || {};
lichess.trans = function(i18n) {
var format = function(str, args) {
if (args.length && str.indexOf('$s') > -1)
if (args.length && str.includes('$s'))
for (var i = 1; i < 4; i++)
str = str.replace('%' + i + '$s', args[i - 1]);
args.forEach(function(arg) {

View File

@ -4,7 +4,7 @@ $(function() {
$(this).click(function() {
$("div.user_show .note_zone").toggle();
});
if (location.search.indexOf('note') != -1) $(this).click();
if (location.search.includes('note')) $(this).click();
});
$("div.user_show .claim_title_zone").each(function() {

View File

@ -87,11 +87,7 @@ lichess.once = function(key, mod) {
}
return false;
};
lichess.fp = {};
lichess.fp.contains = function(list, needle) {
return list.indexOf(needle) !== -1;
};
lichess.fp.debounce = function(func, wait, immediate) {
lichess.debounce = function(func, wait, immediate) {
var timeout;
var lastBounce = 0;
return function() {
@ -244,7 +240,7 @@ lichess.unloadCss = function(url) {
if (lichess.loadedCss[url]) {
lichess.loadedCss[url] = false;
$('head link[rel=stylesheet]')
.filter(function() { return this.href.indexOf(url) >= 0 })
.filter(function() { return this.href.includes(url) })
.remove();
}
}
@ -462,6 +458,7 @@ $.fn.scrollTo = function(target, offsetTop) {
});
};
$.modal = function(html, cls, onClose) {
$.modal.close();
if (!html.clone) html = $('<div>' + html + '</div>');
var $wrap = $('<div id="modal-wrap">')
.html(html.clone().removeClass('none'))
@ -484,13 +481,3 @@ $.modal.close = function() {
$(this).remove();
});
};
// polyfills
if (!Array.prototype.find) {
Object.defineProperty(Array.prototype, 'find', {
value: function(predicate) {
for (var i in this) if (predicate(this[i])) return this[i];
}
});
}

View File

@ -24,7 +24,7 @@ function loadZone() {
streamLoad({
node: $zone[0],
url: $toggle.attr('href'),
callback: lichess.fp.debounce(function() {
callback: lichess.debounce(function() {
userMod($zone);
}, 300)
});
@ -35,7 +35,7 @@ $toggle.click(function() {
else $zone.addClass('none');
return false;
});
if (location.search.indexOf('mod') === 1) $toggle.click();
if (location.search.startsWith('?mod')) $toggle.click();
function userMod($zone) {

View File

@ -9,7 +9,8 @@
"noImplicitReturns": false,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -9,7 +9,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": false,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -9,7 +9,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -21,7 +21,7 @@ export function last(path: Tree.Path): string {
}
export function contains(p1: Tree.Path, p2: Tree.Path): boolean {
return p1.indexOf(p2) === 0;
return p1.startsWith(p2);
}
export function fromNodeList(nodes: Tree.Node[]): Tree.Path {

View File

@ -12,7 +12,8 @@
"noImplicitReturns": true,
"noImplicitThis": true,
"noUnusedParameters": true,
"target": "es5",
"lib": ["DOM", "ES5"]
"moduleResolution": "node",
"target": "es2016",
"lib": ["DOM", "es2016"]
}
}

View File

@ -1594,11 +1594,6 @@ default-resolution@^2.0.0:
resolved "https://registry.yarnpkg.com/default-resolution/-/default-resolution-2.0.0.tgz#bcb82baa72ad79b426a76732f1a81ad6df26d684"
integrity sha1-vLgrqnKtebQmp2cy8aga1t8m1oQ=
defer-promise@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/defer-promise/-/defer-promise-1.0.2.tgz#b79521c59cadadaed2d305385d30f8b05cbf9196"
integrity sha512-5a0iWJvnon50nLLqHPW83pX45BLb4MmlSa1sIg05NBhZoK5EZGz1s8qoZ3888dVGGOT0Ni01NdETuAgdJUZknA==
define-properties@^1.1.2:
version "1.1.3"
resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.3.tgz#cf88da6cbee26fe6db7094f61d870cbd84cee9f1"