This script is now unnecessary in questions and answers, where raw links are replaced by the current question titleraw links are replaced by the current question title. However, this feature is [status-declined] for commentsthis feature is [status-declined] for comments and doesn't work in Chat, which also uses mini-markdown. Chat does have oneboxing, but you can't insert names inline without this script or a bunch of typing or copy-pasting.
httphttps://meta.stackoverflow.com/questions/89378/userscript-to-auto-replace-sofu-links-in-comments
Please change this to use the shorter http://meta.stackoverflow.com/q/89378https://meta.stackoverflow.com/q/89378 and http://meta.stackoverflow.com/q/89378/89389#89389https://meta.stackoverflow.com/q/89378/89389#89389 format. That seems like it would be a trivial Javascript string manipulation. Here's an attempt, I make no assumptions as to its validity, speed, or idiomatic-ness:
function AssertException(message) { this.message = message; }
AssertException.prototype.toString = function () {
return 'AssertException: ' + this.message;
}
function assert_equal(expression, result) {
if (expression != result) {
throw new AssertException('Expression produced "' .. expression .. '" which did not equal "' .. result .. '".');
}
}
// Test function:
function verify_minify()
{
assert_equal('test_str',
'test_str');
// Standard Trilogy question
assert_equal(minify('http://stackoverflow.com/question/12345/some-text'),
'http://stackoverflow.com/q/12345');
//With answer ID:
assert_equal(minify('http://stackoverflow.com/q/12345/some-text/12346#12346'),
'http://stackoverflow.com/q/12345/12346#12346');
//With Meta prefix:
assert_equal(minify('http'https://meta.stackoverflow.com/question/12345/some-text'),
'http'https://meta.stackoverflow.com/q/12345');
//With Meta prefix and answer ID:
assert_equal(minify('http'https://meta.stackoverflow.com/q/12345/some-text/12346#12346'),
'http'https://meta.stackoverflow.com/q/12345/12346#12346');
//With site.stackexchange format:
assert_equal(minify('http://electronics.stackexchange.com/q/12345/some-text'),
'http://electronics.stackexchange.com/q/12345');
//With site.stackexchange format and answer ID:
assert_equal(minify('http://electronics.stackexchange.com/q/12345/some-text/12346#12346'),
'http://electronics.stackexchange.com/q/12345/12346#12346');
//With site.stackexchange format, meta prefix, and answer ID:
assert_equal(minify('http://meta.electronics.stackexchange.com/q/12345/some-text/12346#12346'),
'http://meta.electronics.stackexchange.com/q/12345/12346#12346');
alert('Tests passed.');
}