Skip to main content
yeah, titles
Link
rene
  • 2.8k
  • 2
  • 17
  • 35

Small but Handy: Show a warning message forwhen you follow a link to a deleted answer or comment

v1.2, added links to source, clarified what the direct install link was.
Source Link
rene
  • 2.8k
  • 2
  • 17
  • 35

You can find it ready to be consumed by TamperMonkey or GreaseMonkey on the Github repository. Here is the Github repositorydirect install aand here it the source.

// ==UserScript==
// @name         Check if comment and answer exist
// @namespace    http://meta.stackexchange.com/users/158100/rene
// @version      1.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 (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');
                }
            } else {
                if (!isNaN(Number.parseInt(cleanHash, 10))) {
                    showMessage(document.getElementById('answer-' + cleanHash), 'answer');
                }
            }
        }
    });

}(document || unsafeWindow.document, window || unsafeWindow, StackExchange || unsafeWindow.StackExchange ));
 // ==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 ));

You can find it ready to be consumed by TamperMonkey or GreaseMonkey on the Github repository.

// ==UserScript==
// @name         Check if comment and answer exist
// @namespace    http://meta.stackexchange.com/users/158100/rene
// @version      1.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 (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');
                }
            } else {
                if (!isNaN(Number.parseInt(cleanHash, 10))) {
                    showMessage(document.getElementById('answer-' + cleanHash), 'answer');
                }
            }
        }
    });

}(document || unsafeWindow.document, window || unsafeWindow, StackExchange || unsafeWindow.StackExchange ));

You can find it ready to be consumed by TamperMonkey or GreaseMonkey on the Github repository. Here is the direct install aand here it the source.

 // ==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 ));
gif updated
Source Link
rene
  • 2.8k
  • 2
  • 17
  • 35

###About:

About:

###Screenshot:

Screenshot:

Here is an Animated GIF to show the script in actionAnimated GIF to show the script in action
GIF kindly provided by user 41686d6564

###Download / Install:

Download / Install:

###Platform:

Platform:

###Contact:

Contact:

###License:

License:

###Code:

Code:

###About:

###Screenshot:

Here is an Animated GIF to show the script in action

###Download / Install:

###Platform:

###Contact:

###License:

###Code:

About:

Screenshot:

Here is an Animated GIF to show the script in action
GIF kindly provided by user 41686d6564

Download / Install:

Platform:

Contact:

License:

Code:

added 2 characters in body
Source Link
rene
  • 2.8k
  • 2
  • 17
  • 35
Loading
updated version to use stack notify
Source Link
rene
  • 2.8k
  • 2
  • 17
  • 35
Loading
added logo and followed suggested template for script posts
Source Link
rene
  • 2.8k
  • 2
  • 17
  • 35
Loading
deleted 3 characters in body
Source Link
rene
  • 2.8k
  • 2
  • 17
  • 35
Loading
Source Link
rene
  • 2.8k
  • 2
  • 17
  • 35
Loading