Created
November 20, 2019 18:04
-
-
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.
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
(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