Thành viên:Mxn/monobook.js
Bách khoa toàn thư mở Wikipedia
Cache: Sau khi lưu biểu mẫu này, phải bỏ thông tin vùng đệm (cache) của trình duyệt cho những thay đổi hiện ra được: Mozilla, Firefox, Netscape, Safari: Giữ nút Shift trong khi bấm Reload, hay bấm Ctrl+Shift+R. Internet Explorer: Bấm Ctrl+F5. Opera, Konqueror: Bấm F5.
Nếu bạn viết mã JavaScript, chú ý đọc hướng dẫn để tránh mâu thuẫn với mã mặc định của mạng.
// <nowiki>
/* Bottom tabs */
/* function morelinks() {
var tabs = document.getElementById('p-cactions').cloneNode(true);
tabs.id = 'mytabs';
var listitems = tabs.getElementsByTagName('LI');
for (i=0;i<listitems.length;i++) {
if(listitems[i].id) listitems[i].id = 'mytabs-' + listitems[i].id;
}
document.getElementById('column-content').appendChild(tabs);
}
addLoadEvent(morelinks); */
/* Vietnamese Input Method - Wikipedia tiếng Việt */
// method = 3;
// on_off = 0;
dauCu = 1;
// useCookie = 1;
/* [[en:Wikipedia:WikiProject User scripts/Scripts/Fix diff width]] */
function FixDiffWidth() {
var diffSigns = new Array();
var fixDiffWidth = function () {
var tables = document.getElementsByTagName('table');
for (var i = 0; i < tables.length; i++) if (tables[i].className == 'diff') {
var rows = tables[i].getElementsByTagName('tr');
var diffDiv = document.createElement('div');
diffDiv.style.backgroundColor = 'white';
diffDiv.className = 'xdiff';
for (var j = 0; j < rows.length; j++) {
var rowDiv = document.createElement('div');
rowDiv.style.width = '100%';
rowDiv.style.margin = '0 0 3px 0';
rowDiv.style.overflow = 'hidden'; // trick, makes it expand vertically to contain floats
rowDiv.className = 'xdiff-row';
var colDiv = null;
var cols = rows[j].getElementsByTagName('td');
for (var k = 0; k < cols.length; k++) {
if (!colDiv) {
colDiv = document.createElement('div');
colDiv.style.cssFloat = 'left';
colDiv.style.clear = 'none';
colDiv.style.position = 'relative';
colDiv.style.width = '49%';
colDiv.className = 'xdiff-col';
rowDiv.appendChild(colDiv);
}
var innerDiv = document.createElement('div');
if (cols[k].getAttribute('colspan') == 2 || cols[k].className.substring(0,5) == 'diff-') {
innerDiv.style.overflow = 'auto'; // scroll if necessary!
innerDiv.style.padding = '1px';
if (cols[k].getAttribute('colspan') != 2) {
innerDiv.style.margin = '0 0 0 2em';
innerDiv.style.fontSize = '85%'; // from MediaWiki:Monobook.css
if (cols[k].className == 'diff-addedline') innerDiv.style.backgroundColor = '#cfc';
if (cols[k].className == 'diff-deletedline') innerDiv.style.backgroundColor = '#ffa';
if (cols[k].className == 'diff-context') innerDiv.style.backgroundColor = '#eee';
}
innerDiv.style.textAlign = cols[k].getAttribute('align');
innerDiv.className = (cols[k].className ? "x"+cols[k].className : "");
}
else if (cols[k].firstChild && (cols[k].firstChild.nextSibling ||
cols[k].firstChild.nodeType != 3 || cols[k].firstChild.nodeValue.match(/\S/))) {
innerDiv.style.width = '2em';
innerDiv.style.textAlign = 'center';
innerDiv.style.position = 'absolute';
innerDiv.className = 'xdiff-sign';
diffSigns.push(innerDiv);
}
else continue;
for (var node = cols[k].firstChild; node; node = node.nextSibling)
innerDiv.appendChild(node.cloneNode(true));
innerDiv.appendChild(document.createTextNode(String.fromCharCode(0xa0))); // add nbsp
colDiv.appendChild(innerDiv);
if (innerDiv.className != 'xdiff-sign')
colDiv = null; // start new columns
}
// force rowDiv to expand, just in case position trick fails
var clearer = document.createElement('span');
clearer.clear = 'left';
rowDiv.appendChild(clearer);
diffDiv.appendChild(rowDiv);
}
tables[i].parentNode.replaceChild(diffDiv, tables[i]);
}
};
// finally, a kluge to vertically center the +/- signs
var centerDiffSigns = function () {
for (var i = 0; i < diffSigns.length; i++) {
var parentHeight;
if (!( parentHeight = diffSigns[i].parentNode )) continue;
if (!( parentHeight = parentHeight.clientHeight )) continue;
diffSigns[i].style.top = Math.round((parentHeight - diffSigns[i].offsetHeight)/2) + "px";
}
};
fixDiffWidth();
hookEvent('resize', centerDiffSigns);
setTimeout(centerDiffSigns, 250);
}
if (window.addEventListener) addLoadEvent(FixDiffWidth);
/* [[en:Wikipedia:WikiProject User scripts/Scripts/addLink]] */
function addLink(where, url, name, id, title, key, after) {
//* where is the id of the toolbar where the button should be added;
// i.e. one of "p-cactions", "p-personal", or "p-navigation".
//* url is the URL which will be called when the button is clicked.
// javascript: urls can be used to do more complex things.
//* name is what will appear as the name of the button.
//* id is the id of the button; it's best to define one.
// Use a prefix to make sure its unique. Optional.
//* title is the tooltip title that gives a longer description
// of the button; if you define a accesskey, mention it here. Optional.
//* key is the char you want for the accesskey. Optional.
//* after is the id of the button you want to follow this one. Optional.
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
if(after) {
tabs.insertBefore(li,document.getElementById(after));
} else {
tabs.appendChild(li);
}
if(id) {
if(key && title) { ta[id] = [key, title]; }
else if(key) { ta[id] = [key, '']; }
else if(title) { ta[id] = ['', title];}
}
// re-render the title and accesskeys from existing code in wikibits.js
akeytt();
return li;
}
/* </nowiki>[[:en:Wikipedia:WikiProject User scripts/Scripts/Add purge to tabs|addPurge]]<nowiki> */
function AddPurge () {
var x = document.getElementById('ca-history');
if(!x) return;
if(x.children) x = x.children[0].href;
else x = x.childNodes[0].href;
addLink("p-cactions", x.replace(/=history/, "=purge"), 'Làm sạch', 'ca-purge', 'Làm sạch vùng nhớ đệm của trang này', 0);
}
addLoadEvent(AddPurge);
/* Chia ra [[Thành viên:Mxn/Trang Chính 3]] thành tab */
/* Dựa trên mã nguồn của [http://vi.wikipedia.org/skins-1.5/common/wikibits.js] */
// fold sections for Trang Chính
// XXX: needs testing on IE/Mac and safari
// more comments to follow
function tabbedsects() {
var container = document.getElementById('page-sects');
if (!container || !document.createElement) return;
if (container.nodeName.toLowerCase() == 'a') return; // Occasional IE problem
container.className = container.className + 'jsprefs';
var sections = new Array();
children = container.childNodes;
var seci = 0;
for (i = 0; i < children.length; i++) {
if (children[i].nodeName.toLowerCase() == 'div') {
children[i].id = 'prefsection-' + seci;
children[i].className = 'prefsection';
if (is_opera || is_khtml)
children[i].className = 'prefsection operaprefsection';
legends = children[i].getElementsByTagName('h2');
sections[seci] = new Object();
legends[0].className = 'mainLegend';
if (legends[0] && legends[0].firstChild.nodeValue)
sections[seci].text = legends[0].firstChild.nodeValue;
else
sections[seci].text = '# ' + seci;
sections[seci].secid = children[i].id;
seci++;
if (sections.length != 1) children[i].style.display = 'none';
else var selectedid = children[i].id;
}
}
var toc = document.createElement('ul');
toc.id = 'preftoc';
toc.selectedid = selectedid;
for (i = 0; i < sections.length; i++) {
var li = document.createElement('li');
if (i == 0) li.className = 'selected';
var a = document.createElement('a');
a.href = '#' + sections[i].secid;
a.onmousedown = a.onclick = uncoversection;
a.appendChild(document.createTextNode(sections[i].text));
a.secid = sections[i].secid;
li.appendChild(a);
toc.appendChild(li);
}
container.parentNode.insertBefore(toc, container.parentNode.childNodes[0]);
}
addLoadEvent(tabbedsects);
/* ToDo: [https://bugzilla.mozilla.org/show_bug.cgi?id=339127] */
function addHoverEvent(obj, over, out) {
if (window.addEventListener) {
obj.addEventListener("mouseover", over, false);
obj.addEventListener("mouseout", out, false);
}
else if (window.attachEvent) {
obj.attachEvent("onmouseover", over);
obj.attachEvent("onmouseout", out);
}
}
/* Sửa tựa bài */
/* Giống http://userscripts.org/scripts/source/5690.user.js */
function fixTitle() {
var tmpl = document.getElementById("restrictions");
var corr = document.getElementById("correctTitle");
if (!tmpl || !corr) return;
for (var i = 0; h = document.getElementsByTagName("h1")[i]; i++) {
if (h.className != "firstHeading") continue;
hText = h.textContent;
corrText = corr.textContent;
var hClean = hText.replace(/\W|_/g, "").toLowerCase();
var corrClean = corrText.replace(/\W|_/g, "").toLowerCase();
if (hClean != corrClean) return; // Để tránh phá hoại
document.body.className += " wrongTitle";
document.title = document.title.replace(hText, corrText);
h.textContent = corrText;
// Để cho người dùng không liên kết đến bài sai
over = function() { this.textContent = hText; }
out = function() { this.textContent = corrText; }
addHoverEvent(h, over, out);
return;
}
}
addLoadEvent(fixTitle);
// </nowiki>

