Last active
December 8, 2020 20:14
-
-
Save iskigow/24c4b95b08e4cd05608b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Solve Huetest Kiosk Test | |
// @namespace http://tampermonkey.net/ | |
// @version 2.0 | |
// @require http://code.jquery.com/jquery-3.4.1.min.js | |
// @require https://raw.githubusercontent.com/padolsey-archive/jquery.fn/master/sortElements/jquery.sortElements.js | |
// @description try to take over the world! | |
// @author You | |
// @match https://www.xrite.com/hue-test | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const RGB = ["$1","$2","$3"] | |
function getRgbFatorOrdenacao(ref, ele) { | |
const [rr, gr, br] = getBackground(ref) | |
const [re, ge, be] = getBackground(ele) | |
return Math.trunc(Math.sqrt(Math.pow(re-rr,2) + Math.pow(ge-gr,2) + Math.pow(be-br,2))) | |
} | |
function compareRgb(ref, l, r) { | |
const fl = getRgbFatorOrdenacao(ref, l) | |
const fr = getRgbFatorOrdenacao(ref, r) | |
if (fl < fr) { | |
return -1 | |
} | |
if (fr < fl) { | |
return 1 | |
} | |
return 0 | |
} | |
const POR_RGB = (refL, refR) => (a, b) => { | |
let r = compareRgb(refL, a, b) | |
if (r === 0) { | |
r = compareRgb(refR, b, a) | |
} | |
return r | |
} | |
const POR_ID = (refL, refR) => (a, b) => { | |
return getDataPositionAttr(a) < getDataPositionAttr(b) ? -1 : 1; | |
}; | |
function getDataPositionAttr(ele) { | |
return parseInt(jQuery(ele).attr('data-position')); | |
} | |
function getBackground(ele) { | |
return RGB.map((grupo) => parseInt(jQuery(ele).css('background-color').replace(/^rgb\((\d+), (\d+), (\d+)\)$/g, grupo))); | |
} | |
function ordenarFilhos(pai, por, invert = false) { | |
const filhos = jQuery(pai).children(); | |
let ordenarPor = por; | |
if (invert) { | |
ordenarPor = (a,b) => { | |
return por(a,b) * -1; | |
} | |
} | |
jQuery(filhos).sortElements(ordenarPor); | |
} | |
const parentDiv = jQuery('.btn-container') | |
function createButton(confBtn) { | |
if (document.getElementById(confBtn.btnId)) return | |
const btn = jQuery(`<button id="${confBtn.btnId}" type="button">👨🏻💻 Hack ${confBtn.label}</button>`) | |
btn.on('click', () => { | |
for (let i = 1 ; i < 5 ; i++) { | |
const pai = jQuery(`.hue-container.container-${i} > div#row-${i}`) | |
const [refL, refR] = jQuery(`.hue-container.container-${i} > div.hue-box[data-position]`) | |
ordenarFilhos(pai, confBtn.ordenacao(refL, refR)); | |
} | |
}) | |
btn.appendTo(parentDiv) | |
} | |
setInterval(createButton({btnId:'solveHackButtonProDataPosition', label: 'Por data position', ordenacao: POR_ID}), 1000) | |
setInterval(createButton({btnId:'solveHackButtonProRGB', label: 'Por RGB', ordenacao: POR_RGB}), 1000) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment