User:LNDDYL/cate-langlinks.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:LNDDYL/cate-langlinks. |
/**
[[User:YFdyh000]]于2012.11.14修改,增加鼠标穿过时选中文本功能
[[User:YFdyh000]]于2014.01.02修改,去除复制跨语言链接。
The code from [[:zh:User:Zuohaocheng/cate-langlinks.js]]
Author: ZUO Haocheng [[User:zuohaocheng]]
Email: Please feel free to email me via http://en.wikipedia.org/wiki/Special:EmailUser/Zuohaocheng
电邮: 请通过 http://zh.wikipedia.org/wiki/Special:EmailUser/Zuohaocheng 给我发送电邮
Date: 2011年11月21日, 星期一 (11个月25日前), 09:35 PM (UTC+8)
用途: 显示当前条目的分类所对应的其他语言版本.
Usage: Shows categories in other langs of current article.
*/
if (typeof(targetLang) === 'undefined') {
var targetLang = 'en';
}
$(function() {
var apiURIprefix = '/w/api.php';
var targetLoc = (function() {
var targetL = $('<div></div>', {
id : 'cate-langlinks'
});
var seperator = $('<div></div>').css({
height: '1px',
'margin-top' : '0.5em',
'margin-bottom' : '0.5em',
'background-color' : '#aaa'
});
$('div#catlinks').append(seperator).append(targetL);
return targetL;
})();
var targetWiki = '//' + targetLang + '.wikipedia.org/wiki/'
var pageTitle = wgTitle;
var pageName = encodeURIComponent(wgPageName);
var categoriesURI = apiURIprefix + '?format=xml&action=query&generator=categories&gclshow=!hidden&gcllimit=50&prop=langlinks&lllimit=500&titles=' + pageName;
$.get(categoriesURI, function(result) {
var locCates = [];
var selector = "langlinks ll[lang='" + targetLang + "']";
$(result).find('pages page').each(function() {
var cateName = $(this).attr('title');
var localLink = $(this).find(selector);
if (localLink.length !== 0) {
locCates.push(localLink.text());
}
});
var copyText = [];
var copyZone = $('<div></div>');
targetLoc.empty();
targetLoc.append($('<a></a>', {
'href': '#',
'text': "Localized Categories",
title : 'Show wiki text'
}).click(function(event) {
event.preventDefault();
copyZone.slideToggle();
}));
targetLoc.append('(' + locCates.length + '): ');
var targetUl = $('<ul></ul>');
targetLoc.append(targetUl);
for (i = 0; i<locCates.length; ++i) {
var targetCateName = locCates[i];
var linkURI = targetWiki + targetCateName;
var cateName = targetCateName.replace(/^.*?:(.*)$/, '$1');
$('<li></li>').append($('<a></a>', {
'href': linkURI,
'title': targetCateName,
'text': cateName
})).appendTo(targetUl);
copyText.push('[[' + $('<p></p>').text(targetCateName).html() + ']]');
}
copyZone.html(copyText.join('<br />')).hide();
targetLoc.after(copyZone);
});
});
/**************************************************/
var SelectText = function(element) {
//var text = document.getElementById(element);
var text = element;
if ($.browser.msie) {
var range = document.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if ($.browser.mozilla || $.browser.opera) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
} else if ($.browser.safari) {
var selection = window.getSelection();
selection.setBaseAndExtent(text, 0, text, 1);
}
}
$('#catlinks div:last').live('mouseenter', function(){SelectText(this);});