User:Mike Dillon/Scripts/convert-kanjitab.js

$(function {    var textBox = document.getElementById('wpTextbox1');    if (!textBox) return;    if (!textBox.value.match(/\{\{ja-kanjitab-top/)) return;    if (textBox.value.match(/addOnloadHook/)) return;

var summary = document.getElementById('wpSummary'); var minor = document.getElementById('wpMinoredit'); var diff = document.getElementById('wpDiff'); if (!summary || !minor || !diff) return;

var li = mw.util.addPortletLink("p-tb", "#", "Replace kanjitab", "ca-kanjitab", "Replace ja-kanjitab-top and ja-kanjitab-bottom"); var a = li.getElementsByTagName("a")[0]; a.onclick = function { var re = /\{\{ja-kanjitab-top\}\}\s*!\s*(\[\^\+\]\](\s*\|\|\s*\[\^\+\]\])*)\s*\{\{ja-kanjitab-bottom\}\}/; var m = textBox.value.match(re); if (!m) return false;

var output = textBox.value.substring(0, m.index);

var kanji = []; var matches = m[1].split(/\s*\|\|\s*/); for (var i = 0; i < matches.length; i++) { kanji.push(matches[i].replace(/\[\[([^\]]+)\]\]/, '$1')); }       output += '';

output += textBox.value.substring(m.index + m[0].length);

textBox.value = output;

return false; }; });