Created
April 19, 2018 17:12
-
-
Save luchaninov/d90f6cfb04260be29036f77e8de49a63 to your computer and use it in GitHub Desktop.
Bookmarklet: WP Beautifier
This file contains hidden or 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
(function(){ | |
var colNames = ['','site','','','','hosts','regs','ndp','','','in','','out','','net','rev']; | |
var table = []; | |
var row = []; | |
for (var colNo = 1; colNo < colNames.length; colNo++) { | |
if (colNames[colNo] !== '') { | |
row.push(colNames[colNo]); | |
} | |
} | |
table.push(row.join("\t")); | |
for (var colNo = 1; colNo <= colNames.length; colNo++) { | |
var col = colNames[colNo]; | |
Array.prototype.forEach.call(document.querySelectorAll('#table-stats-body > tr > td:nth-child('+ colNo +'), #table-stats > table > thead > tr > th:nth-child('+ colNo +')'), function(el, i){ | |
var styles = []; | |
if (col == 'site') { | |
styles.push('text-align: left'); | |
} else if (col === '') { | |
styles.push('display:none'); | |
} else { | |
styles.push('text-align:right'); | |
} | |
el.setAttribute('style', styles.join('; ')); | |
}); | |
Array.prototype.forEach.call(document.querySelectorAll('#table-stats-body > tr > td:nth-child('+ colNo +') > span'), function(el, i){ | |
var cls = el.getAttribute('class') || ''; | |
if (['in', 'out', 'net', 'rev'].indexOf(col) !== -1 && cls.indexOf('usd') === -1) { | |
el.innerHTML = (Math.round((el.innerText + 0) / 60 * 100) / 100).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); | |
el.setAttribute('class', cls + ' usd'); | |
} | |
}); | |
Array.prototype.forEach.call(document.querySelectorAll('#table-stats > table > thead > tr > th:nth-child('+ colNo +')'), function(el, i){ | |
el.innerHTML = col; | |
}); | |
} | |
Array.prototype.forEach.call(document.querySelectorAll('#table-stats-body > tr'), function(el, i){ | |
var row = []; | |
var tds = el.querySelectorAll('td'); | |
for (var colNo = 0; colNo < colNames.length - 1; colNo++) { | |
var col = colNames[colNo + 1]; | |
if (col !== '') { | |
row.push(tds[colNo].innerText); | |
} | |
} | |
table.push(row.join("\t")); | |
}); | |
if (document.querySelector('#results')) { | |
document.querySelector('#results').innerHTML = table.join("\n"); | |
} else { | |
document.body.innerHTML = '<textarea id="results" style="width:1280px; height:100px; margin-left: 148px" wrap="off" onfocus="var inp=this; setTimeout(function(){inp.select();},10);">' + table.join("\n") + '</textarea>' + document.body.innerHTML; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment