###About:
When you follow a link to a comment or answer you might end-up being confused if the answer or comment is removed.
This little userscript shows a warning on top of the page when the link you just used contains a fragment to an answer or comment that no longer exists on the page.
This is a repost of my original answer on Meta Stack Exchange
###Screenshot:
Here is an Animated GIF to show the script in action
###Download / Install:
You can find it ready to be consumed by TamperMonkey or GreaseMonkey on the Github repository.
###Platform:
The script will run on any browser that support userscripts with the general available userscript managers like Tampermonkey or GreaseMonkey.
###Contact:
If you find a bug or have a feature request either create an issue or leave a comment here.
Allow for 6 to 8 weeks before fixing.
###License:
The code is released under the MIT License
###Code:
The code is written in JavaScript and has a dependency on the jQuery loaded on the page by Stack Exchange.
For interested parties here is the full code:
// ==UserScript==
// @name Check if comment and answer exist
// @namespace http://meta.stackexchange.com/users/158100/rene
// @version 0.1
// @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 ($, window) {
var hash = $(window.location).attr('hash'),
msg = $('<div></div>')
.css('background-color','#CCFFCC')
.css('align','center')
.css('padding', '10px')
.css('text-align', 'center')
.hide();
function showMessage(jqsel, text) {
if (jqsel.length === 0) {
$('div#header').append(
msg
.text('The ' + text + ' is not found. It may have been deleted')
.fadeIn(2000)
.fadeOut(5000));
}
}
if (hash.length > 0) {
cleanHash = hash.substring(1);
if (cleanHash.indexOf('comment') === 0) {
ids = cleanHash.substring(7).split('_');
showMessage($('div#comments-' + ids[1]).find('tr#comment-'+ ids[0]), 'comment');
} else {
if (Number.parseInt(cleanHash, 10) !== NaN) {
showMessage($('div#answer-' + cleanHash), 'answer');
}
}
}
}($ || unsafeWindow.$, window || unsafeWindow ));
Or find it in the GitHub repo: https://github.com/rschrieken/SmallButHandy/blob/master/CheckForExistingCorA.user.js where you're invited to submit pull requests.