Last active
March 27, 2017 10:09
-
-
Save winfried-van-loon/042960ab9b270eeb71a98881a8240771 to your computer and use it in GitHub Desktop.
WordPress Plugins as JSON
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
var pluginList = { | |
initialise: function() { | |
const $plugins = $('table.plugins'); | |
if(!$plugins.length) { | |
return; | |
} | |
const plugins = this.getPlugins($plugins); | |
if($.isEmptyObject(plugins)) { | |
return; | |
} | |
this.print(plugins); | |
}, | |
getPlugins: function($plugins) { | |
const $list = $plugins.find('#the-list'); | |
const $items = $list.find('tr:not(.plugin-update-tr)'); | |
const plugins = {}; | |
$items.map(function() { | |
const $link = $(this).find('span.deactivate a, span.activate a').attr('href'); | |
const name = $link.split('&plugin=')[1].split('%2F')[0]; | |
const package = 'wpackagist-plugin/' + name; | |
const $version = $(this).find('div.plugin-version-author-uri').text(); | |
const version = $version.split('Versie: ')[1].split(' | Door ')[0]; | |
plugins[package] = version; | |
}); | |
return plugins; | |
}, | |
print: function(plugins) { | |
plugins = JSON.stringify(plugins); | |
const $textarea = $('<textarea />').addClass('plugins'); | |
$textarea.val(plugins).css({ | |
width: '100%', | |
height: 250, | |
margin: '30px 0', | |
padding: 10 | |
}); | |
$textarea.insertAfter($('.bottom')); | |
} | |
}; | |
$(function() { | |
pluginList.initialise(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment