|
// ==UserScript== |
|
// @name Add author name to inbox notifications |
|
// @namespace http://stackexchange.com/users/4337810/ |
|
// @version 1.0 |
|
// @description Adds the author's name for comments, answers, and edits in the topbar inbox dialog |
|
// @author ᔕᖺᘎᕊ (http://stackexchange.com/users/4337810/) |
|
// @match *://*.stackexchange.com/* |
|
// @match *://*.stackoverflow.com/* |
|
// @match *://*.superuser.com/* |
|
// @match *://*.serverfault.com/* |
|
// @match *://*.askubuntu.com/* |
|
// @match *://*.stackapps.com/* |
|
// @match *://*.mathoverflow.net/* |
|
// @grant none |
|
// ==/UserScript== |
|
new MutationObserver(function (mutations) { |
|
mutations.forEach(function (mutation) { |
|
var length = mutation.addedNodes.length; |
|
for (var i = 0; i < length; i++) { |
|
var $addedNode = $(mutation.addedNodes[i]); |
|
if (!$addedNode.hasClass('inbox-dialog')) { |
|
return; |
|
} |
|
|
|
for (var x = 0; x < 16; x++) { //first 15 items |
|
getAuthor($addedNode.find('.inbox-item').eq(x)); |
|
} |
|
} |
|
}); |
|
}).observe(document.body, { |
|
childList: true, |
|
attributes: true, |
|
subtree: true |
|
}); |
|
|
|
var getFromAPI = { |
|
'comment': function (d) { |
|
var comment_id = d.link.split('/')[5].split('?')[0]; |
|
$.getJSON("https://api.stackexchange.com/2.2/comments/" + comment_id + "?order=desc&sort=creation&site=" + d.sitename, function (json) { |
|
d.n.find('.item-header .item-type').text(d.n.find('.item-header .item-type').text() + ' (' + json.items[0].owner.display_name + ')'); |
|
}); |
|
}, |
|
'answer': function (d) { |
|
var answer_id = d.link.split('/')[4].split('?')[0]; |
|
$.getJSON("https://api.stackexchange.com/2.2/answers/" + answer_id + "?order=desc&sort=creation&site=" + d.sitename, function (json) { |
|
d.n.find('.item-header .item-type').text(d.n.find('.item-header .item-type').text() + ' (' + json.items[0].owner.display_name + ')'); |
|
}); |
|
}, |
|
'edit suggested': function (d) { |
|
var edit_id = d.link.split('/')[4]; |
|
$.getJSON("https://api.stackexchange.com/2.2/suggested-edits/" + edit_id + "?order=desc&sort=creation&site=" + d.sitename, function (json) { |
|
d.n.find('.item-header .item-type').text(d.n.find('.item-header .item-type').text() + ' (' + json.items[0].proposing_user.display_name + ')'); |
|
}); |
|
}, |
|
'other': function (d) { |
|
console.log('Script does not currently support getting author information for type "' + d.n.find('.item-header .item-type').text() + '"!'); |
|
} |
|
}; |
|
|
|
function getAuthor($node) { |
|
var type = $node.find('.item-header .item-type').text(); |
|
(getFromAPI[type] || getFromAPI['other'])({ |
|
n: $node, |
|
link: $node.find('a').eq(0).attr('href'), |
|
sitename: $node.find('a').eq(0).attr('href').split('/')[2].split('.')[0] |
|
}); |
|
} |