-
Notifications
You must be signed in to change notification settings - Fork 1
/
BotReportPostChecker.user.js
80 lines (65 loc) · 2.15 KB
/
BotReportPostChecker.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
79
80
// ==UserScript==
// @name Post checker from https://bot.dharman.net/
// @homepage https://github.com/kamil-tekiela/userscripts
// @version 1.2
// @description Checks if the post is deleted
// @author Dharman
// @match *://bot.dharman.net/reports*
// @match *://bot.dharman.net/search*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function($) {
'use strict';
const API_KEY = 'gS)WzUg0j7Q5ZVEBB5Onkw((';
removeBanner();
checkPosts();
async function checkPosts() {
let posts = $('.postID');
var postLinks = posts.map(function() {
return this.innerHTML;
}).get();
let idMap = JSON.parse(sessionStorage.getItem("botIdMap")) || {};
postLinks = postLinks.filter(id => !(id in idMap));
var result = [];
if(postLinks.length) {
// Call API endpoint
var response = await getHistory(postLinks.join(';'), 1);
result = response.items.map(a => a.answer_id);
}
posts.map(function() {
let item = parseInt(this.innerHTML);
if(!result.includes(item) && !idMap[item]){
$(this).closest('.container').css('background-color', 'rgb(185 57 57 / 12%)');
idMap[item] = false;
} else {
idMap[item] = true;
}
})
sessionStorage.setItem("botIdMap", JSON.stringify(idMap));
}
function getHistory (ids, page=1) {
console.log("Made an API call");
return new Promise(resolve => {
GM_xmlhttpRequest({
method: 'GET',
url: 'https://api.stackexchange.com/2.2/answers/'+ ids +'?page='+page+'&pagesize=100&site=stackoverflow&key=' + API_KEY,
onload: function(data) {
resolve(JSON.parse(data.responseText));
}
});
});
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function removeBanner() {
const styles = `
<style>
.userscriptAlert {
display: none;
}
</style>
`;
$('body').append(styles);
}
})(jQuery);