Skip to content

Instantly share code, notes, and snippets.

@jaredrethman
Created November 20, 2019 18:04
Show Gist options
  • Save jaredrethman/ab2c07d1404d4cc26945ddb9d8e3998a to your computer and use it in GitHub Desktop.
Save jaredrethman/ab2c07d1404d4cc26945ddb9d8e3998a to your computer and use it in GitHub Desktop.
A WP CLI equivalent for running `wp plugin list` as a Chrome Snippet. Will output a Markdown table of plugins.
(function() {
const pTable = document.getElementById('the-list');
const pRows = pTable.getElementsByTagName('TR');
let output = '| # | PLUGIN | ACTIVE | INSTALLED | CURRENT |\n';
output += '|-|-|-|-|-|\n';
for (let i = 0, m = pRows.length; i < m; i++) {
const row = pRows[i];
const updateRow = row.classList.contains('plugin-update-tr');
if (updateRow) {
continue;
}
const [rowTitle] = row.getElementsByTagName('STRONG');
output += '|' + (i + 1);
output += '|' + rowTitle.textContent;
output += '|' + (row.classList.contains('active') ? 'Y' : 'N') + '|';
let version = row.querySelector('.plugin-version-author-uri').textContent;
[version] = version.match(/(?<=Version\s+).*?(?=\s+| By)/gs);
output += version.trim() + '|';
if (row.classList.contains('update')) {
let newVersion = row.nextSibling.querySelector('.open-plugin-details-modal').textContent;
[newVersion] = newVersion.match(/(?<=version\s+).*?(?=\s+details)/gs);
output += newVersion.trim() + '|\n';
} else {
output += 'n/a|\n';
}
}
const tArea = document.createElement('textarea');
tArea.value = output;
document.body.appendChild(tArea);
tArea.select();
document.execCommand('copy');
setTimeout(()=>{
document.body.removeChild(tArea);
}
, 500);
}
)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment