Skip to content

Instantly share code, notes, and snippets.

@chrisroos chrisroos/README.md
Last active Aug 29, 2015

Embed
What would you like to do?
JavaScript utility to list the pages with most activity on the indiewebcamp.com wiki

I've created this to make it easier to see the pages with most activity on indiewebcamp.com.

It's designed to be used on the recent changes page of the wiki, e.g. http://indiewebcamp.com/wiki/index.php?title=Special:RecentChanges&limit=250&days=14.

Paste this script into Chrome's JavaScript console (it might work in other browsers but I haven't tested it) and inspect the output there.

The easiest way to exclude some dates is to remove the ul for that date using the Chrome developer tools.

var edits = $('ul.special li')
var pageEditCounts = {};
$.each(edits, function(index, value) {
var editSummary = value.innerText;
// Page edits start with '(diff | hist)'
var isPageEdit = editSummary.match(/\(diff | hist\)/)
if (isPageEdit) {
// Look for '. . <page-title>; hh:mm'
var match = this.innerText.match(/\. \. (.*?); \d\d:\d\d/)
if (match) {
var pageName = match[1];
// Group minor page edits along with other edits for that page
var isMinorEdit = pageName.match(/^m /)
if (isMinorEdit) {
pageName = pageName.match(/^m (.*)/)[1];
}
// Group new pages along with the edits for that page
var isNewPage = pageName.match(/^N /)
if (isNewPage) {
pageName = pageName.match(/^N (.*)/)[1];
}
// Create the counter for this page if it doesn't exist
if (typeof(pageEditCounts[pageName]) == 'undefined') {
pageEditCounts[pageName] = 0;
}
// Increment the counter for this page
pageEditCounts[pageName] += 1;
}
}
});
// Create an array of [pageName, pageEditCount] arrays that can be sorted
var pageEditCountsArray = [];
$.each(pageEditCounts, function(key, value) {
pageEditCountsArray.push([key, value]);
});
// Sort the array by number of edits
var sortedPageEditCounts = pageEditCountsArray.sort(function(a, b) {
var firstPageName = a[0];
var firstPageEditCount = a[1];
var secondPageName = b[0];
var secondPageEditCount = b[1];
return secondPageEditCount - firstPageEditCount;
});
// Print the pages ordered by activity
$.each(sortedPageEditCounts, function(index, value) {
var pageName = value[0];
var pageEditCount = value[1];
console.log(pageName + ' (' + pageEditCount + ')');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.