(async () => { const hashMini = x => { if (!x) return x const json = `${JSON.stringify(x)}` const hash = json.split('').reduce((hash, char, i) => { return Math.imul(31, hash) + json.charCodeAt(i) | 0 }, 0x811c9dc5) return ('0000000' + (hash >>> 0).toString(16)).substr(-8) } // template views const patch = (oldEl, newEl) => oldEl.parentNode.replaceChild(newEl, oldEl) const html = (str, ...expressionSet) => { const template = document.createElement('template') template.innerHTML = str.map((s, i) => `${s}${expressionSet[i] || ''}`).join('') return document.importNode(template.content, true) } const start = performance.now() const el = document.getElementById('fingerprint-data') patch(el, html`
`) const rectElem = document.getElementById('rect1') const rect = rectElem.getClientRects()[0] const { x, y, top, bottom, right, left, width, height } = rect rectElem.classList.add('shift') rectElem.classList.remove('shift') const unShiftRect = document.getElementById('rect1').getClientRects()[0] const { x: unShiftX, y: unShiftY, top: unShiftTop, bottom: unShiftBottom, right: unShiftRight, left: unShiftLeft, height: unShiftHeight, width: unShiftWidth } = unShiftRect rectElem.classList.add('matrix') const matrixRect = document.getElementById('rect1').getClientRects()[0] const { x: matrixX, y: matrixY, top: matrixTop, bottom: matrixBottom, right: matrixRight, left: matrixLeft, height: matrixHeight, width: matrixWidth } = matrixRect const valid = { matrix: ( (matrixRight - matrixLeft) == matrixWidth && (matrixRight - matrixX) == matrixWidth && (matrixBottom - matrixTop) == matrixHeight && (matrixBottom - matrixY) == matrixHeight ), dimensions: ( x == y && x == top && x == left && bottom == right && height == width ), unshift: ( unShiftX == x && unShiftY == y && unShiftTop == top && unShiftBottom == bottom && unShiftRight == right && unShiftLeft == left && unShiftHeight == height && unShiftWidth == width ) } const lieLen = Object.keys(valid).filter(key => !valid[key]).length const score = (100/(1+lieLen)).toFixed(0) const lieHash = hashMini(valid) const rectHash = hashMini({ x, y, top, bottom, right, left, width, height }) const perf = performance.now() - start const styleResult = valid => valid ? `` : `` const rectEl = document.getElementById('rect-test') patch(rectEl, html`
${perf.toFixed(2)}ms DOMRect
score: ${score}%
rect: ${rectHash}
lie pattern: ${lieLen ? lieHash : 'none'}
${styleResult(valid.dimensions)}valid dimensions
${(({ x, y, top, bottom, right, left, width, height }) => { const chars = { x: (''+x).split(''), y: (''+y).split(''), top: (''+top).split(''), bottom: (''+bottom).split(''), right: (''+right).split(''), left: (''+left).split(''), width: (''+width).split(''), height: (''+height).split('') } const base = { dimension1: chars.x, dimension2: chars.right, dimension3: chars.width } const style = (a, b) => b.map( (char, i) => char != a[i] ? `${char}` : char ) .join('') return `
${'x'.padStart(10,'.')}: ${style(base.dimension1, chars.x)}
${'y'.padStart(10,'.')}: ${style(base.dimension1, chars.y)}
${'top'.padStart(10,'.')}: ${style(base.dimension1, chars.top)}
${'left'.padStart(10,'.')}: ${style(base.dimension1, chars.left)}
${'right'.padStart(10,'.')}: ${style(base.dimension2, chars.right)}
${'bottom'.padStart(10,'.')}: ${style(base.dimension2, chars.bottom)}
${'width'.padStart(10,'.')}: ${style(base.dimension3, chars.width)}
${'height'.padStart(10,'.')}: ${style(base.dimension3, chars.height)}
` })(rect)}
${styleResult(valid.matrix)}valid matrix coordinates
${(({ x, y, top, bottom, right, left, width, height }) => { const chars = { width: (''+width).split(''), height: (''+height).split('') } const base = { dimension1: ''+(right - left), dimension2: ''+(right - x), dimension3: ''+(bottom - top), dimension4: ''+(bottom - y) } const style = (a, b) => b.map( (char, i) => char != a[i] ? `${char}` : char ) .join('') const calc = (x, expression) => !expression ? `${x}` : x return `
+ ${''+right} (r)
- ${''+left} (l)
= ${style(base.dimension1, chars.width)} (w)
+ ${''+right} (r)
- ${''+x} (x)
= ${style(base.dimension2, chars.width)} (w)
+ ${''+bottom} (b)
- ${''+top} (t)
= ${style(base.dimension3, chars.height)} (h)
+ ${''+bottom} (b)
- ${''+y} (y)
= ${style(base.dimension4, chars.height)} (h)
` })(matrixRect)}
${styleResult(valid.unshift)}valid unshift
${((unShiftRect, rect) => { const { x, y, top, bottom, right, left, width, height } = rect const { x: unShiftX, y: unShiftY, top: unShiftTop, bottom: unShiftBottom, right: unShiftRight, left: unShiftLeft, height: unShiftHeight, width: unShiftWidth } = unShiftRect const chars = { x: (''+x).split(''), y: (''+y).split(''), top: (''+top).split(''), bottom: (''+bottom).split(''), right: (''+right).split(''), left: (''+left).split(''), width: (''+width).split(''), height: (''+height).split('') } const base = { dimension1: chars.x, dimension2: chars.y, dimension3: chars.top, dimension4: chars.left, dimension5: chars.right, dimension6: chars.bottom, dimension7: chars.width, dimension8: chars.height } const style = (a, b) => b.map( (char, i) => char != a[i] ? `${char}` : char ) .join('') return `
${'x'.padStart(10,'.')}: ${style(base.dimension1, (''+unShiftX).split(''))}
${'y'.padStart(10,'.')}: ${style(base.dimension2, (''+unShiftY).split(''))}
${'top'.padStart(10,'.')}: ${style(base.dimension3, (''+unShiftTop).split(''))}
${'left'.padStart(10,'.')}: ${style(base.dimension4, (''+unShiftLeft).split(''))}
${'right'.padStart(10,'.')}: ${style(base.dimension5, (''+unShiftRight).split(''))}
${'bottom'.padStart(10,'.')}: ${style(base.dimension6, (''+unShiftBottom).split(''))}
${'width'.padStart(10,'.')}: ${style(base.dimension7, (''+unShiftWidth).split(''))}
${'height'.padStart(10,'.')}: ${style(base.dimension8, (''+unShiftHeight).split(''))}
` })(unShiftRect, rect)}
`) })()