Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ==UserScript==
// @name Stack Overflow Critical User History Information
// @namespace https://github.com/edcottrell/
// @version 0.2.6
// @description Highlights key information from the user history inline with the user's profile
// @author Ed Cottrell
// @license MIT
// @match *://*.askubuntu.com/users*
// @match *://*.mathoverflow.net/users*
// @match *://*.serverfault.com/users*
// @match *://*.stackapps.com/users*
// @match *://*.stackexchange.com/users*
// @match *://*.stackoverflow.com/users*
// @match *://*.superuser.com/users*
// @grant none
// ==/UserScript==
var currentURL = document.location.toString(),
emcAnnotations = $('<div id="emcAnnotations"><h2>Critical Events from User History</h2></div>'),
userHistoryURL = document.location.toString().replace(/\/users\/(?:\D+\/)*(\d+).*/, '/users/history/$1');
/**
* Load a URL and add it to the annotations list
*/
function getUserHistoryURL(userHistoryURL) {
$.get(userHistoryURL,
function (data) {
var filteredData = $(data).find('#user-history'),
next = $(data).find('a[rel=next]');
filteredData.find('tr').each(
function () {
var action = $(this).find('td:eq(1) span'),
comment = $(this).find('td:eq(2)');
if ($(this).find('th').length) {
return;
}
if (!action.text().match(/edit display\s*name|moderator contacts user|moderator edits (?!comment).*|cm team contact|user emailed|user annotated|user (un)?suspended/) ||
comment.text().match(/Bounty (?:Closing|Grace Period)|Chat Event Reminder|New Answers On Your Questions|Swag Email|Thanks for your post on Stack Overflow/i)) {
$(this).remove();
}
}
);
if (filteredData.find('tr').length) {
if (filteredData.find('td').length) {
if ($('#emcAnnotations').length) {
filteredData.find('tr').each(
function () {
if (!$(this).find('th').length) {
$('#emcAnnotations').find('tbody').append($(this));
}
}
);
} else {
emcAnnotations.append(filteredData);
$('.js-user-header').after(emcAnnotations);
}
}
}
if (next.length) {
getUserHistoryURL(userHistoryURL.replace(/[\?&]page=\d+|$/, next.attr('href')));
}
});
}
// Only run on user pages that aren't the history page
if (currentURL.match(/\/users\/(?!history)/)) {
$('body').append('<style>' +
' #emcAnnotations {' +
' background-color: #fee;' +
' border-color: #fcc;' +
' }' +
' #emcAnnotations td:nth-child(2) {' +
' width: 15%;' +
' }' +
' #emcAnnotations td:nth-child(1) {' +
' min-width: 20%;' +
' width: 15%;' +
' }' +
' #emcAnnotations table td {' +
' padding: 3px 8px 3px 3px;' +
' vertical-align: middle;' +
' }' +
'</style>');
getUserHistoryURL(userHistoryURL);
}
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.