Skip to content

Instantly share code, notes, and snippets.

@jakedowns
Last active October 5, 2023 01:05
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakedowns/384d6aa84db9f43c31616a5c88cf3649 to your computer and use it in GitHub Desktop.
Save jakedowns/384d6aa84db9f43c31616a5c88cf3649 to your computer and use it in GitHub Desktop.
// original: https://github.com/kdzwinel/CSS-Diff
// @jakedowns 2.4.21: edited to print to a table
//Chrome keeps elements you select via 'inspect element' button in variables.
//Last selected element in $0, one before that in $1 etc.
//Basing on this, I've created a small snippet that compares last two inspected elements:
(function(a,b){
var aComputed = getComputedStyle(a);
var bComputed = getComputedStyle(b);
console.log('------------------------------------------');
console.log('You are comparing: ');
console.log('A:', a);
console.log('B:', b);
console.log('------------------------------------------');
let tableData = [];
for(var aname in aComputed) {
var avalue = aComputed[aname];
var bvalue = bComputed[aname];
if( aname === 'length' || aname === 'cssText' || typeof avalue === "function" ) {
continue;
}
if( avalue !== bvalue ) {
//console.warn('Attribute ' + aname + ' differs: ');
//console.log('A:', avalue);
//console.log('B:', bvalue);
tableData.push({attribute:aname,a:avalue,b:bvalue});
}
}
console.table(tableData,['attribute','a','b'])
console.log('------------------------------------------');
})($0,$1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment