-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCheckForExistingCorA.user.js
More file actions
56 lines (51 loc) · 2.41 KB
/
CheckForExistingCorA.user.js
File metadata and controls
56 lines (51 loc) · 2.41 KB
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
// ==UserScript==
// @name Check if comment and answer exist
// @namespace http://meta.stackexchange.com/users/158100/rene
// @version 1.2
// @description Show a message if the answer or comment in the hash of the url doesn't exist
// @author rene
// @match *://*.stackexchange.com/questions/*
// @match *://stackoverflow.com/questions/*
// @match *://serverfault.com/questions/*
// @match *://askubuntu.com/questions/*
// @match *://mathoverflow.net/questions/*
// @match *://stackapps.com/questions/*
// @match *://superuser.com/questions/*
// @grant none
// ==/UserScript==
(function (document, window, StackExchange) {
var hash = (window.location && window.location.hash)?window.location.hash:'';
function showMessage(jqsel, text) {
if (jqsel === null) {
// wait for SE to be ready
StackExchange.initialized.done(function() {
var classid = 'missing-post-or-comment';
// put a notify on top
StackExchange.notify.show('The ' + text + ' is not found. It may have been deleted', classid);
// remove it automagically after 5 seconds
setTimeout(function () { StackExchange.notify.close(classid);}, 5000);
});
}
}
StackExchange.ready( function() {
if (hash.length > 0) {
cleanHash = hash.substring(1);
if (cleanHash.indexOf('comment') === 0) {
ids = cleanHash.substring(7).split('_');
var lnk = document.getElementById('comments-link-' + ids[1]);
if (lnk !== null) {
StackExchange.comments.loadAll(lnk).done(function() {
showMessage(document.getElementById('comment-'+ ids[0]), 'comment');
});
} else {
showMessage(document.getElementById('comment-'+ ids[0]), 'comment');
}
// Make sure the hash is not the ID of the question.
} else if (window.location.pathname.indexOf('/questions/' + cleanHash) !== 0) {
if (!isNaN(Number.parseInt(cleanHash, 10))) {
showMessage(document.getElementById('answer-' + cleanHash), 'answer');
}
}
}
});
}(document || unsafeWindow.document, window || unsafeWindow, StackExchange || unsafeWindow.StackExchange ));