Участник:T kns/tinyhash.js
Материал из Википедии — свободной энциклопедии
$(function() {
var tinyhash = function(e) {
if(e.which > 1) {return;}
var _this = $(this);
_this.addClass('tinyhash');
// var href = /^([^#]+)#?.*$/.exec(location.href)[1]+'#'+$(this).attr('id');
$.ajax({
url:'http://json-tinyurl.appspot.com/?callback=?&url='+encodeURIComponent(mw.config.get('wgPageName'))+'#'+_this.attr('id'),
dataType: 'json',
success: function(data) {
var shorturl = $('<input type="text" readonly="readonly"/>')
.click(function(){$(this).select();});
shorturl.val(data.tinyurl);
_this.append($('<span> — </span>').append(shorturl))
.css('background-color','#eee6a3');
},
error: function() {
_this.removeClass('tinyhash').css('background-color','#cd5c5c');
}
});
}
$('h2').delegate('span.mw-headline:not(.tinyhash)','click',tinyhash);
});
Text is available under the CC BY-SA 4.0 license; additional terms may apply.
Images, videos and audio are available under their respective licenses.