-
Notifications
You must be signed in to change notification settings - Fork 1
/
newMetaQuestionModAlert.user.js
78 lines (73 loc) · 3.35 KB
/
newMetaQuestionModAlert.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// ==UserScript==
// @name Meta new question alert
// @namespace http://stackexchange.com/users/4337810/
// @version 1.2
// @description Adds an extra mod button to the topbar to alert you of new meta questions
// @author ᔕᖺᘎᕊ (http://stackexchange.fcom/users/4337810/)
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.askubuntu.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// ==/UserScript==setTimeout(function() {
var metaName = 'meta.' + $(location).attr('hostname').split('.')[0],
lastQuestions = {},
unread = "rgb(30, 126, 203)",
read = "rgb(136, 136, 136)";
var apiLink = "https://api.stackexchange.com/2.2/questions?pagesize=5&order=desc&sort=activity&site=" + metaName;
$('.topbar-links').prepend('<span id="mod-extra-icon" class="reputation links-container" style="font-size: 2em; vertical-align: top; padding-top: 3px; color: '+unread+';">♦</span>');
$('.js-topbar-dialog-corral').prepend('<div class="topbar-dialog help-dialog js-help-dialog dno" id="newMetaQuestionsDialog" style="top: 34px; left: 380px; display: none;">\
<div class="modal-content" id="newMetaQuestionsList"><span id="closeNewQuestionList" style="float:right">x</span>\
<ul>\
<li>\
<a>No new questions!<span class="item-summary">\
No new meta questions!</span>\
</a>\
</li>\
</ul>\
</div>\
</div>')
$('#mod-extra-icon').css('cursor', 'pointer').click(function() {
$('#newMetaQuestionsDialog').show();
});
$('#closeNewQuestionList').css('cursor', 'pointer').click(function() {
$('#newMetaQuestionsDialog').hide();
});
$(document).mouseup(function (e) {
var container = $('#newMetaQuestionsDialog');
if (!container.is(e.target) && container.has(e.target).length === 0) {
container.hide();
}
});
if (GM_getValue("metaNewQuestionAlert-lastQuestions", -1) == -1) {
GM_setValue("metaNewQuestionAlert-lastQuestions", JSON.stringify(lastQuestions));
} else {
lastQuestions = JSON.parse(GM_getValue("metaNewQuestionAlert-lastQuestions"));
}
$.getJSON(apiLink, function(json) {
var latestQuestion = json.items[0].title;
if(latestQuestion == lastQuestions[metaName]) {
//if you've already seen the stuff
$('#mod-extra-icon').css('color', read);
} else {
$('#newMetaQuestionsList ul').text("");
$('#mod-extra-icon').css('color', unread);
for(i=0;i<json.items.length;i++){
var title = json.items[i].title,
link = json.items[i].link,
author = json.items[i].owner.display_name;
$('#newMetaQuestionsList ul').append("<li><a href='"+link+"'>"+title+"<br>("+author+")</a>");
}
lastQuestions[metaName] = latestQuestion;
$('#mod-extra-icon').css('cursor', 'pointer').click(function() {
GM_setValue("metaNewQuestionAlert-lastQuestions", JSON.stringify(lastQuestions));
});
}
});
}, 500);