mw.hook('wikipage.content').add(ShowDClink);
function ShowDClink($content) {
$content.find('a').each( function(i, lnk) {
try {
var path = decodeURIComponent(lnk.pathname);
} catch ( e ) {
// e.g. https://ru.wikipedia.org/wiki/%D0%A7%D0%B8%D0%BA%D0%B0%D1%82%D0%B8%D0%BB%D0%BE,_%D0%90%D0%BD%D0%B4%D1%80%D0%B5%D0%B9_%D0%A0%D0%BE%D0%BC%D0%B0%D0%BD%D0%BE%D0%B2%D0%B8%D1%87
return;
}
if( /[?#]/.test(lnk.href) && lnk.href.indexOf('redlink=1') === -1 ) {
return;
}
var mm, user;
mm = /^\/wiki\/Участни(к|ца):(.*)/.exec(path);
if( !mm ) {
mm = /\/w\/index.php\?title=Участни(к|ца):(.*)$/.exec(decodeURIComponent(lnk.href));
}
if( !mm ) {
return;
}
user = mm[2];
if (user.indexOf("/") >= 0) {
return;
}
var suffix = '%D0%BA%D0%B0';
if (mm[1] == 'ца') suffix = '%D1%86%D1%8B';
var dAddr = 'https://ru.wikipedia.org/wiki/%D0%9E%D0%B1%D1%81%D1%83%D0%B6%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5_%D1%83%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8' + suffix + ':' + encodeURIComponent(user);
var cAddr = 'https://ru.wikipedia.org/wiki/%D0%A1%D0%BB%D1%83%D0%B6%D0%B5%D0%B1%D0%BD%D0%B0%D1%8F:%D0%92%D0%BA%D0%BB%D0%B0%D0%B4/' + encodeURIComponent(user);
var showDLink = !(FindAddr(lnk.nextSibling, 0, '%D0%9E%D0%B1%D1%81%D1%83%D0%B6%D0%B4%D0%B5%D0%BD%D0%B8%D0%B5_%D1%83%D1%87%D0%B0%D1%81%D1%82%D0%BD%D0%B8' + suffix + ':' + encodeURIComponent(user)) || document.URL == dAddr);
var showCLink = !FindAddr(lnk.nextSibling, 0, cAddr);
if (showDLink || showCLink){
var s='(';
if (showDLink) {
s = s + '<a href="' + dAddr + '" title="обсуждение">о</a>';
if (showCLink) s = s + ' • ';
}
if (showCLink) s= s + '<a href="' + cAddr + '" title="вклад">в</a>';
s = s + ')';
$(lnk)
.after('<span class="dclink-wrapper">\u00A0', s, '</span>');
}
var displayMode;
if (typeof displaySignature == 'undefined'){
displayMode = 'nickname';
}else{
displayMode = displaySignature.toLowerCase();
}
if ((displayMode == 'nickname') || (displayMode == 'user')){
var nick = (displayMode == 'nickname')?GetAllText(lnk):user.replace(/_/g,' ');
Clear(lnk);
lnk.appendChild(document.createTextNode(nick));
}
});
}
function FindAddr(node, lvl, addr) {
var found = false;
for (var i = 0; i < 6; i++) {
if (!node) break;
if (node.tagName == 'A') {
if (node.href.indexOf(addr) >= 0) found = true;
}else{
if (lvl < 4) found = FindAddr(node.firstChild, lvl+1, addr);
}
if (found) break;
node = node.nextSibling;
}
return found;
}
function Clear(Node){
var Child;
while (Child = Node.firstChild)
Node.removeChild(Child);
}
function GetAllText(Node){
var Child, text = '';
var Children = Node.childNodes;
for (var i = 0; Child = Children[i]; i++)
text += (Child.nodeType == 3)?Child.nodeValue:GetAllText(Child);
return text;
}