Skip to content

Instantly share code, notes, and snippets.

@arieffikhrie
Created August 6, 2018 03:49
Show Gist options
  • Save arieffikhrie/5bd027aa0af24f904ff2c614963864a1 to your computer and use it in GitHub Desktop.
Save arieffikhrie/5bd027aa0af24f904ff2c614963864a1 to your computer and use it in GitHub Desktop.
// This script only can be used at http://timepaz.com/EyeTest/ , just open console and copied this code
var _$ = jQuery;
var $div = _$('#box');
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
if (mutation.attributeName === "class") {
const attributeValue = $(mutation.target).prop(mutation.attributeName);
const mapElem = {};
const currentClass = '';
$div.on('event', () => {
const item = _$(this);
console.log('class', currentClass, item.prop('class'));
});
$div.find('span').each((index, elem) => {
const bgColor = _$(elem).css('backgroundColor');
console.log(bgColor);
if (typeof mapElem[bgColor] === 'undefined') {
mapElem[bgColor] = {
color: bgColor,
count: 1,
elem: _$(elem),
index: index
}
} else {
mapElem[bgColor].count++;
mapElem[bgColor].elem = _$(elem);
mapElem[bgColor].index = index;
}
}).promise().done(() => {
console.log(mapElem);
for (let key in mapElem) {
const item = mapElem[key];
if (item.count === 1) {
item.elem.css('backgroundColor', 'white');
}
}
});
}
});
});
observer.observe($div[0], {
attributes: true
});
var _$=jQuery;var $div=_$('#box');var observer=new MutationObserver(function(mutations){mutations.forEach(function(mutation){if(mutation.attributeName==="class"){const attributeValue=$(mutation.target).prop(mutation.attributeName);const mapElem={};const currentClass='';$div.on('event',()=>{const item=_$(this);console.log('class',currentClass,item.prop('class'))});$div.find('span').each((index,elem)=>{const bgColor=_$(elem).css('backgroundColor');console.log(bgColor);if(typeof mapElem[bgColor]==='undefined'){mapElem[bgColor]={color:bgColor,count:1,elem:_$(elem),index:index}}else{mapElem[bgColor].count++;mapElem[bgColor].elem=_$(elem);mapElem[bgColor].index=index}}).promise().done(()=>{console.log(mapElem);for(let key in mapElem){const item=mapElem[key];if(item.count===1){item.elem.css('backgroundColor','white')}}})}})});observer.observe($div[0],{attributes:!0})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment