MediaWiki:Gadget-RefToolbarLegacy.js

MediaWiki系统消息页面
/* eslint-disable no-unused-vars */
/* global EditTools */
'use strict';

/* <nowiki> */
/**
 * SPDX-License-Identifier: CC-BY-SA-4.0
 * _addText: '{{Gadget Header|license=CC-BY-SA-4.0}}'
 *
 * @source <zh.wikipedia.org/wiki/MediaWiki:RefToolbarLegacy.js>
 */
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
(function ($, mw) {
  var numforms = 0;
  var citeUserDateFormat;
  var refTagURL;
  var defaultRefTagURL = '';
  var refToolDebug;
  var easyCiteMain = function easyCiteMain() {
    document.querySelector('#citeselect').style.display = '';
    document.querySelector('#citemore').style.display = 'none';
  };
  var addOption = function addOption(script, text) {
    var option = document.createElement('input');
    option.setAttribute('type', 'button');
    option.setAttribute('onclick', script);
    option.setAttribute('value', text);
    return option;
  };
  var refbuttons = function refbuttons() {
    if (mw.toolbar) {
      mw.toolbar.addButton({
        imageFile: '//youshou.wiki/images/e/ea/Button_easy_cite.png',
        speedTip: 'Insert citation',
        onClick: easyCiteMain,
        imageId: 'mw-toolbar-editbutton'
      });
      if (!navigator.userAgent.includes('MSIE')) {
        var citemain = document.createElement('div');
        citemain.style.display = 'none';
        citemain.style.margin = '0 0 6px';
        citemain.style.clear = 'both';
        citemain.style.height = 'auto';
        citemain.setAttribute('Id', 'citeselect');
        citemain.appendChild(addOption('citeWeb()', 'Web'));
        citemain.appendChild(addOption('citeNews()', 'News'));
        citemain.appendChild(addOption('citeBook()', 'Book'));
        citemain.appendChild(addOption('citeJournal()', 'Journal'));
        citemain.appendChild(addOption('citeNamedRef()', 'Named references'));
        citemain.appendChild(addOption('dispErrors()', 'Error check'));
        citemain.appendChild(addOption('showMore()', 'More'));
        citemain.appendChild(addOption('hideInitial()', 'Cancel'));
        var citemore = document.createElement('div');
        citemore.style.display = 'none';
        citemore.setAttribute('Id', 'citemore');
        citemore.appendChild(addOption('citeEncyclopedia()', 'Encyclopedia'));
        citemore.appendChild(addOption('citePressRelease()', 'Press release'));
        citemore.appendChild(addOption('citeMap()', 'Map'));
        citemore.appendChild(addOption('showRefSectionOptions()', 'Ref Section'));
        citemain.appendChild(citemore);
        $(citemain).insertAfter($('#toolbar'));
      } else {
        var citeselect = document.createElement('div');
        citeselect.id = 'citeselect';
        citeselect.style.display = 'none';
        citeselect.innerHTML = '<input type="button" value="Web" onclick="citeWeb()" /><input type="button" value="News" onclick="citeNews()" /><input type="button" value="Book" onclick="citeBook()" /><input type="button" value="Journal" onclick="citeJournal()" /><input type="button" value="Named references" onclick="citeNamedRef()" /><input type="button" value="Error check" onclick="dispErrors()" /><input type="button" value="More" onclick="showMore()" /><input type="button" value="Cancel" onclick="hideInitial()" /><div id="citemore" style="display:none">\
		<input type="button" value="Encyclopedia" onclick="citeEncyclopedia()" />\
		<input type="button" value="Press release" onclick="citePressRelease()" />\
		<input type="button" value="Map" onclick="citeMap()" />\
		<input type="button" value="Ref Section" onclick="showRefSectionOptions()" />\
		</div>';
        document.querySelector('#editform').insertBefore(citeselect, document.querySelector('#editform').firstChild);
      }
      var reftoolformarea = document.createElement('span');
      reftoolformarea.id = 'refToolFormArea';
      $('#citeselect').append(reftoolformarea);
    }
    if ((typeof EditTools === 'undefined' ? 'undefined' : typeof EditTools === "undefined" ? "undefined" : _typeof(EditTools)) === 'object') {
      var placeholder = document.querySelector('#editpage-specialchars');
      EditTools.createEditTools(placeholder);
    }
  };
  var oldFormHide = function oldFormHide() {
    // if (numforms !== 0) {
    //  document..querySelector(`#citediv${numforms}`).style.display = 'none';
    // }
    document.querySelector('#refToolFormArea').innerHTML = '';
    if (document.querySelector('#errorform') !== null) {
      document.querySelector('#citeselect').removeChild(document.querySelector('#errorform'));
    }
  };
  var hideInitial = function hideInitial() {
    document.querySelector('#citeselect').style.display = 'none';
    oldFormHide();
  };
  var showMore = function showMore() {
    document.querySelector('#citemore').style.display = '';
  };
  var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
  var citeGlobalDateFormat = '<date> <monthname> <year>';
  var getTime = function getTime() {
    var datestr = '';
    if (citeUserDateFormat) {
      datestr = citeUserDateFormat;
    } else {
      datestr = citeGlobalDateFormat;
    }
    var DT = new Date();
    var zmonth = '';
    var month = DT.getUTCMonth() + 1;
    if (month < 10) {
      zmonth = "0".concat(month.toString());
    } else {
      zmonth = month.toString();
    }
    month = month.toString();
    var zdate = '';
    var date = DT.getUTCDate();
    if (date < 10) {
      zdate = "0".concat(date.toString());
    } else {
      zdate = date.toString();
    }
    date = date.toString();
    datestr = datestr.replace('<date>', date);
    datestr = datestr.replace('<month>', month);
    datestr = datestr.replace('<zdate>', zdate);
    datestr = datestr.replace('<zmonth>', zmonth);
    datestr = datestr.replace('<monthname>', months[DT.getUTCMonth()]);
    datestr = datestr.replace('<year>', DT.getUTCFullYear().toString());
    return datestr;
  };
  var lastNameToRefname = function lastNameToRefname() {
    // Note: This only works if field 'refname' comes after field 'last', but it always does
    var lastName;
    var fields = document.querySelector("#citediv".concat(numforms)).querySelectorAll('input');
    var _iterator = _createForOfIteratorHelper(fields),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var field = _step.value;
        if (field.id === 'last') {
          lastName = field.value;
        } else if (field.id === 'refname') {
          field.value = lastName.replace(/^\s*(.*?)\s*$/, '$1');
          return;
        }
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
  };
  var setAccessDateToday = function setAccessDateToday() {
    document.querySelector('#access-date').value = getTime();
  };
  var getLastName = function getLastName(authornum) {
    if (/\S/.test(document.querySelector("#last".concat(authornum)).value)) {
      return document.querySelector("#last".concat(authornum)).value;
    }
    var author = document.querySelector("#author".concat(authornum)).value;
    var match = /(\S+)\s*$/.exec(author);
    if (match) {
      return match[1];
    }
    return;
  };
  var makeRefname = function makeRefname() {
    var refname;
    if (document.querySelector('#last1')) {
      refname = document.querySelector('#last1').value + document.querySelector('#last2').value;
    } else {
      refname = document.querySelector('#last').value;
    }
    if (/\S/.test(refname)) {
      var date = document.querySelector('#date').value;
      var match = /\d{4}/.exec(date);
      if (match) {
        refname += match[0];
      }
    } else {
      refname = document.querySelector('#title').value;
    }
    document.querySelector('#refname').value = refname;
  };
  var citeNewsWeb = function citeNewsWeb(templatename) {
    oldFormHide();
    var template = templatename;
    var legend;
    if (template === 'cite web') {
      legend = 'Cite web source';
    } else {
      legend = 'Cite news source';
    }
    var newtime = getTime();
    numforms++;
    var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>").concat(legend, "</legend><table cellspacing=\"5\"><input type=\"hidden\" value=\"").concat(template, "\" id=\"template\"><tr><td width=\"120\"><label for=\"url\">URL: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"url\"></td><td width=\"120\"><label for=\"title\">&nbsp;Title: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"title\"></td></tr><tr><td width=\"120\"><label for=\"last\">Last name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"last\"></td><td width=\"120\"><label for=\"first\">&nbsp;First name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"first\"></td></tr><tr><td width=\"120\"><!-- <label for=\"coauthors\"><s>Coauthors: </s></label> --></td><td width=\"400\"><span style=\"color:#696969;font-style:italic;\">Co-author parameter no longer supported</span><!-- <input type=\"text\" tabindex=1 style=\"width:100%\" id=\"coauthors\" placeholder=\"this parameter no longer supported\"> --></td><td width=\"120\"><label for=\"date\">&nbsp;Publication date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"date\"></td></tr><tr><td width=\"120\"><label for=\"work\">").concat(template === 'cite news' ? 'Newspaper or&nbsp;work' : 'Website or&nbsp;work', ": </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"work\"></td><td width=\"120\"><label for=\"publisher\">&nbsp;Publisher: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"publisher\"></td></tr><tr><td width=\"120\"><label for=\"pages\">Pages: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"pages\"></td><td width=\"120\"><label for=\"language\">&nbsp;Language: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"language\"></td></tr><tr><td width=\"120\"><label for=\"access-date\">Access date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"access-date\" value=\"").concat(newtime, "\"></td>");
    if (template === 'cite news') {
      form += '<td width="120"><label for="location">&nbsp;Location: </label></td><td width="400"><input type="text" tabindex=1 style="width:100%" id="location"></td></tr>';
    } else {
      form += '<td width="120"></td><td width="400"></td></tr>';
    }
    if (template === 'cite web') {
      form += '<tr><td width="120"><label for="archive-url">Archive URL: </label></td><td width="400"><input type="text" tabindex=1 style="width:100%" id="archive-url"></td><td width="120"><label for="archive-date">&nbsp;Archive date: </label></td><td width="400"><input type="text" tabindex=1 style="width:100%" id="archive-date"></td></tr>';
    }
    form += "<tr><td width=\"120\"><label for=\"refname\">Reference name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:60%\" id=\"refname\"><input type=\"button\" value=\"<Last name\" onClick=\"lastNameToRefname()\"></td></tr></table> <input type=\"button\" value=\"Add citation\" onClick=\"addcites()\"> <input type=\"button\" value=\"Preview citation\" onClick=\"previewCitationDefault()\"> \t<img id=\"progress\" src=\"//youshou.wiki/images/d/de/Ajax-loader.gif\" style=\"visibility: hidden\" /><input type=\"checkbox\" tabindex=1 name=\"verbose\" id=\"verbose\" value=\"verbose\"><label for=\"verbose\">Vertical form</label><span style=\"float:right\"><a href=\"//www.qiuwenbaike.cn/wiki/Template:".concat(template.replace(/ /g, '_'), "\" target=\"_blank\">[Template documentation]</a></span></fieldset><span id=\"previewSpan\"></span></div>");
    document.querySelector('#refToolFormArea').innerHTML = form;
  };
  var citeWeb = function citeWeb() {
    citeNewsWeb('cite web');
  };
  var citeNews = function citeNews() {
    citeNewsWeb('cite news');
  };
  var citeBook = function citeBook() {
    oldFormHide();
    var template = 'cite book';
    numforms++;
    var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Cite book source</legend>");
    form += '<table cellspacing="5" width="100%"> \
	<tr><td><label for="title">Title: </label></td> \
	<td colspan=5><input type="text" tabindex=1 style="width:100%" id="title"></td></tr>';
    for (var i = 1; i <= 3; i++) {
      var i_str = i === 1 ? '' : " ".concat(i);
      form += "<tr> \t\t<td width=\"130\"><label for=\"last".concat(i, "\">Author").concat(i_str, " last&nbsp;name: </label></td> \t\t<td><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"last").concat(i, "\"></td> \t\t<td><label for=\"first").concat(i, "\">&nbsp;first&nbsp;name: </label></td> \t\t<td><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"first").concat(i, "\"></td> \t\t<td><label for=\"author-link").concat(i, "\">&nbsp;Author link: </label></td> \t\t<td><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"author-link").concat(i, "\"> \t\t</td> \t\t</tr>");
    }
    form += '<tr><td><!-- <label for="coauthors"><s>Coauthors: </s></label> --></td> \
	<td><span style="color:#696969;font-style:italic;">Co-author parameter no longer supported</span><!-- <input type="text" tabindex=1 style="width:100%" id="coauthors" placeholder="this parameter no longer supported"> --></td> \
	<td><label for="editor">&nbsp;Editor: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="editor"></td> \
	<td><label for="others">&nbsp;Others: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="others"></td></tr> \
	</table> \
	<table cellspacing="5" width="100%"> \
	<tr><td width="130"><label for="publisher">Publisher: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="publisher"></td> \
	<td><label for="location">&nbsp;Location: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="location"></td></tr> \
	\
	<tr><td><label for="date">Publication&nbsp;date or&nbsp;year: </label></td> \
	<td><input type="text" tabindex=1 style="width:140px" id="date"> \
	<input id="dmy" name="dateformat" value="dmy" type="radio" tabindex=1 onclick="reformatDates()"><label for="dmy">dmy</label> \
	<input id="mdy" name="dateformat" value="mdy" type="radio" tabindex=1 onclick="reformatDates()"><label for="mdy">md, y</label> \
	<input id="ymd" name="dateformat" value="ymd" type="radio" tabindex=1 onclick="reformatDates()"><label for="ymd">y-m-d</label> \
	</td> \
	<td><label for="edition">&nbsp;Edition: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="edition"></td></tr> \
	\
	<tr><td><label for="series">Series: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="series"></td> \
	<td><label for="volume">&nbsp;Volume: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="volume"></td></tr> \
	\
	<tr><td><label for="pages">Page number(s):</label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="pages" name="pages" onFocus="this.style.backgroundColor=\'\';"></td> \
	<td><label for="chapter">&nbsp;Chapter: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="chapter"></td></tr> \
	\
	<tr><td><label for="isbn">ISBN: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="isbn"></td> \
	<td><label for="language">&nbsp;Language: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="language"></td></tr> \
	\
	<tr><td><label for="url">URL: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="url"></td> \
	<td><label for="access-date">&nbsp;Access&nbsp;date:</label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="access-date"></td></tr> \
	\
	<tr><td><label for="otherfields">Other&nbsp;fields:</label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="otherfields"></td> \
	<td><label for="refname">&nbsp;Ref&nbsp;name: </label></td> \
	<td><input type="text" tabindex=1 style="width:100%" id="refname"></td> \
	</tr> \
	</table> \
	\
	<input type="radio" tabindex=1 name="template" id="cite_book" value="cite_book" checked="1"><label for="cite_book">{{cite book}}</label> <sup><a href="//www.qiuwenbaike.cn/wiki/Template:Cite_book" target="_blank">[doc]</a></sup> \
	<input type="radio" tabindex=1 name="template" id="citation" value="citation"><label for="citation">{{citation}}</label> <sup><a href="//www.qiuwenbaike.cn/wiki/Template:Citation" target="_blank">[doc]</a></sup> \
	<input type="radio" tabindex=1 name="template" id="plain" value="plain"><label for="plain">plain wikicode (experimental)</label> \
	<input type="checkbox" tabindex=1 name="verbose" id="verbose" value="verbose"><label for="verbose">Vertical form</label> \
	<input type="checkbox" tabindex=1 name="extraparams" id="extraparams" value="extraparams"><label for="extraparams">Extra parameters</label> \
	<br><input type="button" value="Add citation" onClick="makeCiteBook()"> \
	<input type="button" value="Preview citation" onClick="previewCitationBook()"> \
	<img id="progress" src="//youshou.wiki/images/d/de/Ajax-loader.gif" style="visibility: hidden" /> \
	\
 	</fieldset><span id="previewSpan"></span></div>';
    document.querySelector('#refToolFormArea').innerHTML = form;
  };
  var citeJournal = function citeJournal() {
    oldFormHide();
    var template = 'cite journal';
    numforms++;
    var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Cite journal</legend><table cellspacing=\"5\"><input type=\"hidden\" value=\"").concat(template, "\" id=\"template\"><tr><td width=\"120\"><label for=\"last\">Last name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"last\"></td><td width=\"120\"><label for=\"first\">&nbsp;First name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"first\"></td></tr><tr><td width=\"120\"><!-- <label for=\"coauthors\"><s>Coauthors: </s></label> --></td><td width=\"400\"><span style=\"color:#696969;font-style:italic;\">Co-author parameter no longer supported</span><!-- <input type=\"text\" tabindex=1 style=\"width:100%\" id=\"coauthors\" placeholder=\"this parameter no longer supported\"> --></td><td width=\"120\"><label for=\"date\">&nbsp;Publication date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"date\"></td></tr><tr><td width=\"120\"><label for=\"title\">Title: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"title\"></td><td width=\"120\"><label for=\"journal\">&nbsp;Journal: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"journal\"></td></tr><tr><td width=\"120\"><label for=\"publisher\">Publisher: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"publisher\"></td><td width=\"120\"><label for=\"location\">&nbsp;Location: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"location\"></td></tr><tr><td width=\"120\"><label for=\"volume\">Volume: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"volume\"></td><td width=\"120\"><label for=\"issue\">&nbsp;Issue: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"issue\"></td></tr><tr><td width=\"120\"><label for=\"pages\">Pages: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"pages\"></td><td width=\"120\"><label for=\"issn\">&nbsp;ISSN: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"issn\"></td></tr><tr><td width=\"120\"><label for=\"oclc\">OCLC: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"oclc\"></td><td width=\"120\"><label for=\"doi\">&nbsp;DOI: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"doi\"></td></tr><tr><td width=\"120\"><label for=\"pmid\">PMID: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"pmid\"></td><td width=\"120\"><label for=\"quote\">&nbsp;Quote: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"quote\"></td></tr><tr><td width=\"120\"><label for=\"url\">URL: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"url\"></td><td width=\"120\"><label for=\"access-date\">&nbsp;Access date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"access-date\"></td></tr><tr><td width=\"120\"><label for=\"language\">Language: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"language\"></td><td width=\"120\"><label for=\"refname\">&nbsp;Reference name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:60%\" id=\"refname\"><input type=\"button\" value=\"<Last name\" onClick=\"lastNameToRefname()\"></td></tr></table><input type=\"button\" value=\"Add citation\" onClick=\"addcites()\"> <input type=\"button\" value=\"Preview citation\" onClick=\"previewCitationDefault()\"> \t<img id=\"progress\" src=\"//youshou.wiki/images/d/de/Ajax-loader.gif\" style=\"visibility: hidden\" /><input type=\"checkbox\" tabindex=1 name=\"verbose\" id=\"verbose\" value=\"verbose\"><label for=\"verbose\">Vertical form</label><span style=\"float:right\"><a href=\"//www.qiuwenbaike.cn/wiki/Template:").concat(template.replace(/ /g, '_'), "\" target=\"_blank\">[Template documentation]</a></span></fieldset><span id=\"previewSpan\"></span></div>");
    document.querySelector('#refToolFormArea').innerHTML = form;
  };
  var citeEncyclopedia = function citeEncyclopedia() {
    oldFormHide();
    var template = 'cite encyclopedia';
    numforms++;
    var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Cite encyclopedia source</legend><table cellspacing=\"5\"><input type=\"hidden\" value=\"").concat(template, "\" id=\"template\"><tr><td width=\"120\"><label for=\"last\">Last name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"last\"></td><td width=\"120\"><label for=\"first\">&nbsp;First name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"first\"></td></tr><tr><td width=\"120\"><!-- <label for=\"coauthors\"><s>Coauthors: </s></label> --></td><td width=\"400\"><span style=\"color:#696969;font-style:italic;\">Co-author parameter no longer supported</span><!-- <input type=\"text\" tabindex=1 style=\"width:100%\" id=\"coauthors\" placeholder=\"this parameter no longer supported\"> --></td><td width=\"120\"><label for=\"editor\">&nbsp;Editor: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"editor\"></td></tr><tr><td width=\"120\"><label for=\"title\">Entry title: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"title\"></td><td width=\"120\"><label for=\"encyclopedia\">&nbsp;Encyclopedia: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"encyclopedia\"></td></tr><tr><td width=\"120\"><label for=\"publisher\">Publisher: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"publisher\"></td><td width=\"120\"><label for=\"location\">&nbsp;Location: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"location\"></td></tr><tr><td width=\"120\"><label for=\"year\">Year: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"year\"></td><td width=\"120\"><label for=\"volume\">&nbsp;Volume: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"volume\"></td></tr><tr><td width=\"120\"><label for=\"pages\">Pages: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"pages\"></td><td width=\"120\"><label for=\"isbn\">&nbsp;ISBN: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"isbn\"></td></tr><tr><td width=\"120\"><label for=\"url\">URL: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"url\"></td><td width=\"120\"><label for=\"access-date\">&nbsp;Access date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"access-date\"></td></tr><tr><td width=\"120\"><label for=\"language\">Language: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"language\"></td><td width=\"120\"><label for=\"refname\">&nbsp;Reference name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"refname\"></td></tr></table><input type=\"button\" value=\"Add citation\" onClick=\"addcites()\"> <input type=\"button\" value=\"Preview citation\" onClick=\"previewCitationDefault()\"> \t<img id=\"progress\" src=\"//youshou.wiki/images/d/de/Ajax-loader.gif\" style=\"visibility: hidden\" /><input type=\"checkbox\" tabindex=1 name=\"verbose\" id=\"verbose\" value=\"verbose\"><label for=\"verbose\">Vertical form</label><span style=\"float:right\"><a href=\"//www.qiuwenbaike.cn/wiki/Template:").concat(template.replace(/ /g, '_'), "\" target=\"_blank\">[Template documentation]</a></span></fieldset><span id=\"previewSpan\"></span></div>");
    document.querySelector('#refToolFormArea').innerHTML = form;
  };
  var citePressRelease = function citePressRelease() {
    oldFormHide();
    var template = 'cite press release';
    numforms++;
    var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Cite press release</legend><table cellspacing=\"5\"><input type=\"hidden\" value=\"").concat(template, "\" id=\"template\"><tr><td width=\"120\"><label for=\"title\">Title: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"title\"></td><td width=\"120\"><label for=\"publisher\">&nbsp;Publisher: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"publisher\"></td></tr><tr><td width=\"120\"><label for=\"date\">Date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"date\"></td><td width=\"120\"><label for=\"language\">&nbsp;Language: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"language\"></td></tr><tr><td width=\"120\"><label for=\"url\">URL: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"url\"></td><td width=\"120\"><label for=\"access-date\">&nbsp;Access date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"access-date\" value=\"").concat(getTime(), "\"></td></tr><tr><td width=\"120\"><label for=\"refname\">Reference name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"refname\"></td></tr></table><input type=\"button\" value=\"Add citation\" onClick=\"addcites()\"> <input type=\"button\" value=\"Preview citation\" onClick=\"previewCitationDefault()\"> \t<img id=\"progress\" src=\"//youshou.wiki/images/d/de/Ajax-loader.gif\" style=\"visibility: hidden\" /><input type=\"checkbox\" tabindex=1 name=\"verbose\" id=\"verbose\" value=\"verbose\"><label for=\"verbose\">Vertical form</label><span style=\"float:right\"><a href=\"//www.qiuwenbaike.cn/wiki/Template:").concat(template.replace(/ /g, '_'), "\" target=\"_blank\">[Template documentation]</a></span></fieldset><span id=\"previewSpan\"></span></div>");
    document.querySelector('#refToolFormArea').innerHTML = form;
  };
  var citeMap = function citeMap() {
    oldFormHide();
    var template = 'cite map';
    numforms++;
    var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Cite map</legend><table cellspacing=\"5\"><input type=\"hidden\" value=\"").concat(template, "\" id=\"template\"><tr><td width=\"120\"><label for=\"publisher\">Publisher: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"publisher\"></td><td width=\"120\"><label for=\"title\">&nbsp;Title: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"title\"></td></tr><tr><td width=\"120\"><label for=\"url\">URL: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"url\"></td><td width=\"120\"><label for=\"access-date\">&nbsp;Access date: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"access-date\"></td></tr><tr><td width=\"120\"><label for=\"edition\">Edition: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"edition\"></td><td width=\"120\"><label for=\"date\">&nbsp;Date or year: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"date\"></td></tr><tr><td width=\"120\"><label for=\"cartography\">Cartography: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"cartography\"></td><td width=\"120\"><label for=\"scale\">&nbsp;Scale: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"scale\"></td></tr><tr><td width=\"120\"><label for=\"series\">Series: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"series\"></td><td width=\"120\"><label for=\"page\">&nbsp;Page: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"page\"></td></tr><tr><td width=\"120\"><label for=\"section\">Section: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"section\"></td><td width=\"120\"><label for=\"inset\">&nbsp;Inset: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"inset\"></td></tr><tr><td width=\"120\"><label for=\"isbn\">ISBN: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"isbn\"></td><td width=\"120\"><label for=\"refname\">&nbsp;Reference name: </label></td><td width=\"400\"><input type=\"text\" tabindex=1 style=\"width:100%\" id=\"refname\"></td></tr></table><input type=\"button\" value=\"Add citation\" onClick=\"addcites()\"> <input type=\"button\" value=\"Preview citation\" onClick=\"previewCitationDefault()\"> \t<img id=\"progress\" src=\"//youshou.wiki/images/d/de/Ajax-loader.gif\" style=\"visibility: hidden\" /><input type=\"checkbox\" tabindex=1 name=\"verbose\" id=\"verbose\" value=\"verbose\"><label for=\"verbose\">Vertical form</label><span style=\"float:right\"><a href=\"//www.qiuwenbaike.cn/wiki/Template:").concat(template.replace(/ /g, '_'), "\" target=\"_blank\">[Template documentation]</a></span></fieldset><span id=\"previewSpan\"></span></div>");
    document.querySelector('#refToolFormArea').innerHTML = form;
  };
  var showRefSectionOptions = function showRefSectionOptions() {
    oldFormHide();
    var template = 'cite encyclopedia';
    numforms++;
    var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Add references section</legend>\tHeadline:<br>\t<input id=\"references\" name=\"headline\" type=\"radio\" tabindex=1 checked=\"checked\"><label for=\"references\">== References ==</label><br> \t<input id=\"notes\" name=\"headline\" type=\"radio\" tabindex=1><label for=\"notes\">== Notes ==</label><br> \tType:<br> \t<input id=\"type-references\" name=\"type\" type=\"radio\" tabindex=1><label for=\"type-references\">&lt;references/&gt;</label><br> \t<input id=\"type-reflist\" name=\"type\" type=\"radio\" tabindex=1 checked=\"checked\"><label for=\"type-reflist\">{{Reflist}}</label><br> \t<input type=\"checkbox\" tabindex=1 id=\"ldr\"><label for=\"ldr\">List-defined references</label> (<a href=\"//www.qiuwenbaike.cn/wiki/Help:%E5%BC%95%E7%94%A8\" target=\"_blank\">Info 1</a>, <a href=\"//en.wikipedia.org/wiki/Help:Footnotes#List-defined_references\" target=\"_blank\">Info 2</a>)<br>\t<input type=\"button\" value=\"Add references section\" onClick=\"addRefSection()\"></fieldset></div>");
    document.querySelector('#refToolFormArea').innerHTML = form;
  };
  var makeCiteCode = function makeCiteCode() {
    var cites = document.querySelector("#citediv".concat(numforms)).querySelectorAll('input');
    var template = '';
    var citebegin = '<ref';
    var citename = '';
    var citeinner = '';
    var _iterator2 = _createForOfIteratorHelper(cites),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var cite_ = _step2.value;
        var citeid = cite_.id;
        var citevalue = cite_.value;
        citevalue = citevalue.trim(); // Trim leading and trailing whitespace
        if (citeid === 'verbose') {
          if (cite_.checked) {
            citeinner = citeinner.replace(/\|/g, '\n|');
          }
        } else if (citevalue !== '' && cite_.type !== 'button' && cite_.type !== 'image') {
          if (citeid === 'refname') {
            citebegin += " name=\"".concat(citevalue, "\"");
          } else if (citeid === 'template') {
            citename = ">{{".concat(citevalue);
            template = citevalue;
          } else {
            if (citeid === 'pages') {
              if (/^\w+$/.test(citevalue) && template !== 'cite encyclopedia') {
                citeid = 'page'; // Use page= instead of pages= if only one page. Makes p. 5 instead of pp. 5.
              } else {
                citevalue = citevalue.replace(/-/g, '–'); // Replace hyphens with en dashes
              }
            } else if (citeid === 'date' && /^\d{4}$/.test(citevalue)) {
              citeid = 'year'; // Use year= instead of date= if only the year is specified
            }

            citeinner += "|".concat(citeid, "=").concat(citevalue);
          }
        }
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var cite = "".concat(citebegin + citename + citeinner, "}}</ref>");
    return cite;
  };
  var addcites = function addcites(_template) {
    var cite = makeCiteCode();
    $('#wpTextbox1').trigger('focus');
    mw.toolbar.insertTags(cite, '', '');
    // document.querySelector(`#citediv${numforms}`).style.display = 'none';
    oldFormHide();
  };
  var addRefSection = function addRefSection() {
    var wikicode = '\n';
    if (document.querySelector('#references').checked) {
      wikicode += '== References ==\n';
    } else if (document.querySelector('#notes').checked) {
      wikicode += '== Notes ==\n';
    } else {
      alert('No headline selected!');
    }
    if (document.querySelector('#type-references').checked) {
      if (document.querySelector('#ldr').checked) {
        wikicode += '<references>\n\n</references>\n';
      } else {
        wikicode += '<references />\n';
      }
    } else if (document.querySelector('#type-reflist').checked) {
      if (document.querySelector('#ldr').checked) {
        wikicode += '{{Reflist|refs=\n\n}}\n';
      } else {
        wikicode += '{{Reflist}}\n';
      }
    } else {
      alert('No type selected!');
    }
    $('#wpTextbox1').trigger('focus');
    mw.toolbar.insertTags(wikicode, '', '');
    document.querySelector("#citediv".concat(numforms)).innerHTML = '';
  };
  var getNamedRefs = function getNamedRefs(calls) {
    var text = document.querySelector('#wpTextbox1').value;
    var regex;
    if (calls) {
      regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^\s"']*?[^/]\b)) *?\/ *?>/gi; // '
    } else {
      regex = /< *?ref +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^\s"']*?[^/]\b)) *?>/gi; // '
    }

    var namedrefs = [];
    var i = 0;
    var nr = true;
    do {
      var ref = regex.exec(text);
      if (ref !== null) {
        if (ref[5]) {
          namedrefs[i] = ref[5];
        } else if (ref[3]) {
          namedrefs[i] = ref[3];
        } else {
          namedrefs[i] = ref[6];
        }
        i++;
      } else {
        nr = false;
      }
    } while (nr === true);
    return namedrefs;
  };
  var citeNamedRef = function citeNamedRef() {
    var namedrefs = getNamedRefs(false);
    if (namedrefs === '') {
      oldFormHide();
      numforms++;
      var out = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>References in text</legend>There are no named refs (<tt>&lt;ref name=\"Name\"&gt;</tt>) in the text</fieldset></div>");
      document.querySelector('#refToolFormArea').innerHTML = out;
    } else {
      oldFormHide();
      numforms++;
      var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>References in article</legend><table cellspacing=\"5\"><tr><td><label for=\"namedrefs\">&nbsp;Named references in text</label></td><td><select name=\"namedrefs\" id=\"namedrefs\">");
      var _iterator3 = _createForOfIteratorHelper(namedrefs),
        _step3;
      try {
        for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
          var namedref = _step3.value;
          form += "<option value=\"".concat(namedref, "\">").concat(namedref, "</option>");
        }
      } catch (err) {
        _iterator3.e(err);
      } finally {
        _iterator3.f();
      }
      form += '</select></td></tr></table><input type="button" value="Add citation" onClick="addnamedcite()"></fieldset></div>';
      document.querySelector('#refToolFormArea').innerHTML = form;
    }
  };
  var addnamedcite = function addnamedcite() {
    var name = document.querySelector("#citediv".concat(numforms)).querySelectorAll('select')[0].value;
    var ref = "<ref name=\"".concat(name, "\" />");
    $('#wpTextbox1').trigger('focus');
    mw.toolbar.insertTags(ref, '', '');
    document.querySelector("#citediv".concat(numforms)).style.display = 'none';
  };
  var getAllRefs = function getAllRefs() {
    var text = document.querySelector('#wpTextbox1').value;
    var regex = /< *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^\s"']*?[^/]\b)))? *?>((.|\n)*?)< *?\/? *?ref *?>/gim; // "
    var allrefs = [];
    var i = 0;
    var nr = true;
    do {
      var ref = regex.exec(text);
      if (ref !== null) {
        if (ref[0].search(/\S{150}/) !== -1) {
          ref[0] = ref[0].replace(/\|(\S)/g, '| $1');
        }
        ref[0] = ref[0].replace(/</g, '&lt;');
        ref[0] = ref[0].replace(/>/g, '&gt;');
        allrefs[i] = ref[0];
        i++;
      } else {
        nr = false;
      }
    } while (nr === true);
    return allrefs;
  };
  var NRcallError = function NRcallError(namedrefs, refname) {
    var _iterator4 = _createForOfIteratorHelper(namedrefs),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var namedref = _step4.value;
        if (namedref === refname) {
          return true;
        }
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    return false;
  };
  var errorCheck = function errorCheck() {
    var allrefs = getAllRefs();
    var allrefscontent = [];
    var samecontentexclude = [];
    var sx = 0;
    var templateexclude = [];
    var tx = 0;
    var skipcheck = false;
    var namedrefcalls = getNamedRefs(true);
    var _iterator5 = _createForOfIteratorHelper(allrefs.entries()),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _step5$value2 = _slicedToArray(_step5.value, 2),
          _i3 = _step5$value2[0],
          allref = _step5$value2[1];
        allrefscontent[_i3] = allref.replace(/&lt; *?ref( +?name *?= *?(('([^']*?)')|("([^"]*?)")|([^\s"']*?[^/]\b)))? *?&gt;((.|\n)*?)&lt; *?\/? *?ref *?&gt;/gim, '$8'); // "
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    var namedrefs = getNamedRefs(false);
    var errorlist = [];
    var q = 0;
    var unclosed = document.querySelector('#unclosed').checked;
    var samecontent = document.querySelector('#samecontent').checked;
    var templates = document.querySelector('#templates').checked;
    var repeated = document.querySelector('#repeated').checked;
    var undef = document.querySelector('#undef').checked;
    for (var i = 0; i < allrefs.length; i++) {
      if (allrefs[i].search(/&lt; *?\/ *?ref *?&gt;/) === -1 && unclosed) {
        errorlist[q] = "<tr><td width=\"75%\"><tt>".concat(allrefs[i], "</tt></td>");
        errorlist[q] += '<td width="25%">Unclosed <tt>&lt;ref&gt;</tt> tag</td></tr>';
        q++;
      }
      if (samecontent) {
        var _iterator6 = _createForOfIteratorHelper(samecontentexclude),
          _step6;
        try {
          for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
            var element = _step6.value;
            if (allrefscontent[i] === element) {
              skipcheck = true;
            }
          }
        } catch (err) {
          _iterator6.e(err);
        } finally {
          _iterator6.f();
        }
        var p = 0;
        while (p < allrefs.length && !skipcheck) {
          if (allrefscontent[i] === allrefscontent[p] && i !== p) {
            errorlist[q] = "<tr><td width=\"75%\"><tt>".concat(allrefscontent[i], "</tt></td>");
            errorlist[q] += '<td width="25%">Multiple refs contain this content, a <a href="https://www.qiuwenbaike.cn/wiki/Help:%E5%BC%95%E7%94%A8">named reference</a> should be used instead</td></tr>';
            q++;
            samecontentexclude[sx] = allrefscontent[i];
            sx++;
            break;
          }
          p++;
        }
        skipcheck = false;
      }
      if (templates && allrefscontent[i].search(/{{cite/i) === -1 && allrefscontent[i].search(/{{citation/i) === -1 && allrefscontent[i].search(/{{comic (book|strip) reference/i) === -1 && allrefscontent[i].search(/{{editorial cartoon reference/i) === -1 && allrefscontent[i].search(/{{harv/i) === -1) {
        var _iterator7 = _createForOfIteratorHelper(templateexclude),
          _step7;
        try {
          for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
            var _element = _step7.value;
            if (allrefscontent[i] === _element) {
              skipcheck = true;
            }
          }
        } catch (err) {
          _iterator7.e(err);
        } finally {
          _iterator7.f();
        }
        if (!skipcheck) {
          errorlist[q] = "<tr><td width=\"75%\"><tt>".concat(allrefs[i], "</tt></td>");
          errorlist[q] += '<td width="25%">Does not use a <a href="//www.qiuwenbaike.cn/wiki/Category:%E5%BC%95%E7%94%A8%E6%A8%A1%E6%9D%BF">citation template</a></td></tr>';
          q++;
          templateexclude[tx] = allrefscontent[i];
          tx++;
        }
        skipcheck = false;
      }
    }
    if (repeated) {
      var repeatnameexclude = [];
      var rx = 0;
      for (var k = 0; k < namedrefs.length; k++) {
        var _iterator8 = _createForOfIteratorHelper(repeatnameexclude),
          _step8;
        try {
          for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
            var _element2 = _step8.value;
            if (namedrefs[k] === _element2) {
              skipcheck = true;
            }
          }
        } catch (err) {
          _iterator8.e(err);
        } finally {
          _iterator8.f();
        }
        var z = 0;
        while (z < namedrefs.length && !skipcheck) {
          if (namedrefs[k] === namedrefs[z] && k !== z) {
            errorlist[q] = "<tr><td width=\"75%\"><tt>".concat(namedrefs[k], "</tt></td>");
            errorlist[q] += '<td width="25%">Multiple references are given the same <a href="https://www.qiuwenbaike.cn/wiki/Help:%E5%BC%95%E7%94%A8">name</a></td></tr>';
            q++;
            repeatnameexclude[rx] = namedrefs[z];
            rx++;
            break;
          }
          z++;
        }
        skipcheck = false;
      }
    }
    if (undef) {
      var undefexclude = [];
      var ux = 0;
      var _iterator9 = _createForOfIteratorHelper(namedrefcalls.entries()),
        _step9;
      try {
        for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
          var _step9$value2 = _slicedToArray(_step9.value, 2),
            _p = _step9$value2[0],
            namedrefcall = _step9$value2[1];
          var _iterator10 = _createForOfIteratorHelper(undefexclude),
            _step10;
          try {
            for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
              var _element3 = _step10.value;
              var _i2 = void 0;
              if (allrefscontent[_i2] === _element3) {
                skipcheck = true;
              }
            }
          } catch (err) {
            _iterator10.e(err);
          } finally {
            _iterator10.f();
          }
          if (!skipcheck && !NRcallError(namedrefs, namedrefcall)) {
            errorlist[q] = "<tr><td width=\"75%\"><tt>".concat(namedrefcall, "</tt></td>");
            errorlist[q] += '<td width="25%">A <a href="https://www.qiuwenbaike.cn/wiki/Help:%E5%BC%95%E7%94%A8">named reference</a> is used but not defined</td></tr>';
            q++;
            undefexclude[ux] = namedrefs[_p];
            ux++;
          }
          skipcheck = false;
        }
      } catch (err) {
        _iterator9.e(err);
      } finally {
        _iterator9.f();
      }
    }
    if (q > 0) {
      return errorlist;
    }
    return 0;
  };
  var dispErrors = function dispErrors() {
    oldFormHide();
    var form = '<div id="errorform"><fieldset><legend>Error checking</legend><b>Check for:</b><br><input type="checkbox" id="unclosed" /> Unclosed <tt>&lt;ref&gt;</tt> tags<br><input type="checkbox" id="samecontent" /> References with the same content<br><input type="checkbox" id="templates" /> References not using a <a href="//www.qiuwenbaike.cn/wiki/Category:%E5%BC%95%E7%94%A8%E6%A8%A1%E6%9D%BF">citation template</a><br><input type="checkbox" id="repeated" /> Multiple references with the same name<br><input type="checkbox" id="undef" /> Usage of undefined named references<br><input type="button" id="errorchecksubmit" value="Check for selected errors" onclick="doErrorCheck()"/></fieldset></div>';
    document.querySelector('#citeselect').innerHTML += form;
  };
  var doErrorCheck = function doErrorCheck() {
    var errors = errorCheck();
    document.querySelector('#citeselect').removeChild(document.querySelector('#errorform'));
    if (errors === 0) {
      if (numforms !== 0) {
        document.querySelector("#citediv".concat(numforms)).style.display = 'none';
      }
      numforms++;
      var out = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Error checking</legend>No errors found.</fieldset></div>");
      document.querySelector('#citeselect').innerHTML += out;
    } else {
      if (numforms !== 0) {
        document.querySelector("#citediv".concat(numforms)).style.display = 'none';
      }
      numforms++;
      var form = "<div id=\"citediv".concat(numforms, "\"><fieldset><legend>Error checking</legend><table border=\"1px\">");
      var _iterator11 = _createForOfIteratorHelper(errors),
        _step11;
      try {
        for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
          var error = _step11.value;
          form += error;
        }
      } catch (err) {
        _iterator11.e(err);
      } finally {
        _iterator11.f();
      }
      form += '</table></fieldset></div>';
      document.querySelector('#citeselect').innerHTML += form;
    }
  };
  var makeBookCitationCode = function makeBookCitationCode(callback) {
    var cite = '<ref';
    var refname = document.querySelector('#refname').value;
    if (/\S/.test(refname)) {
      cite += " name=\"".concat(refname, "\"");
    }
    cite += '>{{';
    if (document.querySelector('#cite_book').checked || document.querySelector('#plain').checked) {
      cite += 'cite book';
    } else if (document.querySelector('#citation').checked) {
      cite += 'citation';
    } else {
      alert('No template selected.');
    }
    var authorcite = '';
    var prevauthor = 0;
    for (var i = 3; i >= 1; i--) {
      // const author = document.querySelector(`#author${i}`).value;
      var last = document.querySelector("#last".concat(i)).value;
      var first = document.querySelector("#first".concat(i)).value;
      var authorlink = document.querySelector("#author-link".concat(i)).value;
      if (i === 1 && !prevauthor) {
        i = '';
      }
      if (/\S/.test(authorlink)) {
        authorcite = "|author-link".concat(i, "=").concat(authorlink).concat(authorcite);
      }
      if (/\S/.test(last)) {
        authorcite = "|last".concat(i, "=").concat(last, "|first").concat(i, "=").concat(first).concat(authorcite);
        prevauthor = 1;
      }
    }
    cite += authorcite;
    var simplefields = ['editor', 'others', 'title', 'url', 'access-date', 'edition', 'series', 'volume', 'date', 'publisher', 'location', 'language', 'isbn', 'pages', 'chapter'];
    for (var _i4 = 0, _simplefields = simplefields; _i4 < _simplefields.length; _i4++) {
      var fieldname = _simplefields[_i4];
      var value = document.querySelector("#".concat(fieldname)).value;
      if (/\S/.test(value) || fieldname === 'title') {
        if (fieldname === 'pages') {
          if (/^\w+$/.test(value)) {
            fieldname = 'page'; // Use page= instead of pages= if only one page. Makes p. 5 instead of pp. 5.
          } else {
            value = value.replace(/-/g, '–'); // Replace hyphens with en dashes
            value = value.replace(/,\s*/g, ', '); // One space after each comma
          }
        } else if (fieldname === 'date' && /^\d{4}$/.test(value)) {
          fieldname = 'year'; // Use year= instead of date= if only the year is specified
        }

        cite += "|".concat(fieldname, "=").concat(value);
      }
    }
    var otherfields = document.querySelector('#otherfields').value;
    if (/\S/.test(otherfields)) {
      cite += "|".concat(otherfields);
    }
    if (document.querySelector('#extraparams').checked) {
      cite += '|author-mask=';
      if (!document.querySelector('#citation').checked) {
        cite += '|trans-title=';
      }
      cite += '|format=';
      cite += '|orig-date=';
      cite += '|oclc=';
      cite += '|doi=';
      cite += '|bibcode=';
      cite += '|id=';
      if (/\S/.test(document.querySelector('#chapter').value)) {
        if (!document.querySelector('#citation').checked) {
          cite += '|trans-chapter=';
        }
        cite += '|chapter-url=';
      }
      cite += '|quote=';
      cite += '|lay-url=';
      cite += '|lay-date=';
    }
    cite += '}}</ref>';
    if (document.querySelector('#plain').checked) {
      var match = /^(.*?)({{.*}})(.*?)$/.exec(cite);
      if (match) {
        var citebeg = match[1];
        var citemid = match[2];
        var citeend = match[3];
        citemid = citemid.replace(/cite book/, 'Vancite book');
        // alert(citebeg + ':::' + citemid + ':::' + citeend);
        // document.querySelector('#fullcite').value = 'Updating...';
        var url = "api.php?action=expandtemplates&format=xml&text=".concat(encodeURIComponent(citemid));
        document.querySelector('#progress').style.visibility = 'visible';
        var xmlhttpExpand = new XMLHttpRequest();
        xmlhttpExpand.onreadystatechange = function () {
          if (xmlhttpExpand.readyState === 4) {
            if (xmlhttpExpand.status === 200) {
              document.querySelector('#progress').style.visibility = 'hidden';
              var xmlDoc = xmlhttpExpand.responseXML.documentElement;
              var expanded = xmlDoc.querySelectorAll('expandtemplates')[0].textContent;
              if (expanded === undefined) {
                expanded = xmlDoc.querySelectorAll('expandtemplates')[0].childNodes[0].nodeValue;
              }
              expanded = expanded.replace(/<span.*?>/gi, '');
              expanded = expanded.replace(/<\/span>/gi, '');
              expanded = expanded.replace(/<nowiki\/?>/gi, '');
              expanded = expanded.replace(/&#32;/gi, ' ');
              expanded = expanded.replace(/&#59;/gi, ';');
              expanded = expanded.replace(/&#91;/gi, '[');
              expanded = expanded.replace(/&#93;/gi, ']');
              var plaincite = citebeg + expanded + citeend;
              // alert(plaincite);
              callback(plaincite);
            } else {
              alert('The query returned an error.');
            }
          }
        };
        xmlhttpExpand.open('GET', url, true);
        xmlhttpExpand.send(null);
      } else {
        alert('Error A1');
      }
    } else {
      if (document.querySelector('#verbose').checked) {
        cite = cite.replace(/\|/g, '\n|');
      }
      callback(cite);
    }
  };
  var makeCiteBook = function makeCiteBook() {
    makeBookCitationCode(function (cite) {
      $('#wpTextbox1').trigger('focus');
      mw.toolbar.insertTags(cite, '', '');
      if (!refToolDebug) {
        oldFormHide();
      }
    });
  };
  var formatDate = function formatDate(datein, dateformat) {
    if (dateformat === '') {
      return datein;
    }
    datein = datein.replace(/^\s*(.*?)\s*$/, '$1'); // Trim whitespace
    var year = -1;
    var month = -1;
    var date = -1;
    var match = /^(\d\d\d\d)-(\d\d?)(-(\d\d?))?$/.exec(datein);
    if (match) {
      // alert(' match[1]=' + match[1] + ' match[2]=#' + match[2] + '# match[3]=' + match[3] + ' match[4]=' + match[4]  );
      year = Number.parseInt(match[1], 10); // 10 forces decimal conversion
      month = Number.parseInt(match[2], 10);
      if (match[4]) {
        date = Number.parseInt(match[4], 10);
      }
    } else if (/^\d{1,2} \w+ \d{4}$/.test(datein) || /^\w+ \d{1,2}, \d{4}$/.test(datein)) {
      var DT = new Date(datein);
      year = DT.getFullYear();
      month = DT.getMonth() + 1;
      date = DT.getDate();
    } else if (datein === 'today') {
      var _DT = new Date();
      year = _DT.getUTCFullYear();
      month = _DT.getUTCMonth() + 1;
      date = _DT.getUTCDate();
    } else {
      return datein;
    }
    // alert('datein=' + datein + ', y=' + year + ', m=' + month + ', d=' + date);
    var zmonth = '';
    if (month < 10) {
      zmonth = "0".concat(month.toString());
    } else {
      zmonth = month.toString();
    }
    month = month.toString();
    var zdate = '';
    if (date > -1) {
      if (date < 10) {
        zdate = "0".concat(date.toString());
      } else {
        zdate = date.toString();
      }
      date = date.toString();
    } else {
      date = '';
    }
    var datestr = dateformat;
    datestr = datestr.replace('<date>', date);
    datestr = datestr.replace('<month>', month);
    datestr = datestr.replace('<zdate>', zdate);
    datestr = datestr.replace('<zmonth>', zmonth);
    datestr = datestr.replace('<monthname>', months[month - 1]);
    datestr = datestr.replace('<year>', year.toString());
    datestr = datestr.replace(/\s+/, ' ').replace(/^\s+/, '').replace(/(\D),/, '$1').replace(/-$/, '');
    return datestr;
  };
  var getDateFormat = function getDateFormat() {
    var dateformat = '';
    if (document.querySelector('#dmy')) {
      if (document.querySelector('#dmy').checked) {
        dateformat = '<date> <monthname> <year>';
      } else if (document.querySelector('#mdy').checked) {
        dateformat = '<monthname> <date>, <year>';
      } else if (document.querySelector('#ymd').checked) {
        dateformat = '<year>-<zmonth>-<zdate>';
      }
    } else if (citeUserDateFormat) {
      dateformat = citeUserDateFormat;
    } else {
      dateformat = citeGlobalDateFormat;
    }
    return dateformat;
  };
  var reformatDates = function reformatDates() {
    var dateformat = getDateFormat();
    // alert(':' + dateformat + ':');
    document.querySelector('#access-date').value = formatDate(document.querySelector('#access-date').value, dateformat);
    document.querySelector('#date').value = formatDate(document.querySelector('#date').value, dateformat);
    // document.querySelector('#dateformat_hidden').value = getDateFormatShort();
  };
  /* const updateGetButton = () => {
  document.querySelector('#urlget').disabled = document.querySelector('#url').value === '';
  } */
  var preview = function preview(wikitext) {
    document.querySelector('#progress').style.visibility = 'visible';
    wikitext += '<references />';
    var url = "api.php?action=parse&format=xml&prop=text&text=".concat(encodeURIComponent(wikitext));
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
      if (xmlhttp.readyState === 4) {
        if (xmlhttp.status === 200) {
          document.querySelector('#progress').style.visibility = 'hidden';
          var xmlDoc = xmlhttp.responseXML.documentElement;
          var previewHTML = xmlDoc.querySelectorAll('text')[0].textContent;
          if (previewHTML === undefined) {
            previewHTML = xmlDoc.querySelectorAll('text')[0].childNodes[0].nodeValue;
          }
          // alert(previewHTML);
          previewHTML = previewHTML.replace(/href="\//gi, 'href="//www.qiuwenbaike.cn/');
          document.querySelector('#previewSpan').innerHTML = "<fieldset><legend>Citation preview</legend>".concat(previewHTML, "</fieldset>");
        } else {
          alert('The query returned an error.');
        }
      }
    };
    xmlhttp.open('GET', url, true);
    xmlhttp.send(null);
  };
  var previewCitationBook = function previewCitationBook() {
    makeBookCitationCode(preview);
  };
  var previewCitationDefault = function previewCitationDefault() {
    var wikitext = makeCiteCode();
    preview(wikitext);
  };
  var JsonRequest = function JsonRequest(url) {
    var script = document.createElement('script');
    script.setAttribute('src', url);
    script.setAttribute('type', 'text/javascript');
    document.querySelectorAll('head')[0].appendChild(script);
  };
  var pullURL = function pullURL() {
    var url = document.querySelector('#url').value;
    if (url) {
      document.querySelector('#progress').style.visibility = 'visible';
      if (!refTagURL) {
        refTagURL = defaultRefTagURL;
      }
      var baseurl = "".concat(refTagURL, "urlfetchjs.py");
      url = "".concat(baseurl, "?url=").concat(encodeURIComponent(url), "&callback=useUrlData");
      JsonRequest(url);
    } else {
      alert('No URL.');
    }
  };
  var pullISBN = function pullISBN() {
    var isbn = document.querySelector('#isbn').value;
    isbn = isbn.replace(/\D/g, ''); // Digits only
    if (isbn) {
      document.querySelector('#progress').style.visibility = 'visible';
      if (!refTagURL) {
        refTagURL = defaultRefTagURL;
      }
      var baseurl = "".concat(refTagURL, "getdiberri.py");
      var url = "".concat(baseurl, "?isbn=").concat(isbn, "&callback=useDiberriData");
      JsonRequest(url);
    } else {
      alert('No ISBN.');
    }
  };
  var pullDOI = function pullDOI() {
    var doi = document.querySelector('#doi').value;
    if (doi) {
      document.querySelector('#progress').style.visibility = 'visible';
      if (!refTagURL) {
        refTagURL = defaultRefTagURL;
      }
      var baseurl = "".concat(refTagURL, "doifetchjs.py");
      var url = "".concat(baseurl, "?doi=").concat(encodeURIComponent(doi), "&callback=useDoiData");
      JsonRequest(url);
    } else {
      alert('No DOI.');
    }
  };
  var pullJs = function pullJs() {
    var book_url = document.querySelector('#url').value;
    if (book_url) {
      document.querySelector('#progress').style.visibility = 'visible';
      var book_url_enc = encodeURIComponent(book_url);
      if (!refTagURL) {
        refTagURL = defaultRefTagURL;
      }
      var baseurl = "".concat(refTagURL, "googlebooksjs.py");
      var url = "".concat(baseurl, "?book_url=").concat(book_url_enc, "&callback=setFormValues");
      JsonRequest(url);
    } else {
      alert('No URL.');
    }
  };
  var pullPMID = function pullPMID() {
    alert('Not implemented yet...');
  };
  var setFormValues = function setFormValues(bookdata) {
    document.querySelector('#progress').style.visibility = 'hidden';
    // alert(bookdata);
    // alert(bookdata.page);
    if (bookdata.title.length > 0) {
      document.querySelector('#title').value = bookdata.title;
    }
    if (bookdata.isbn.length > 0) {
      document.querySelector('#isbn').value = bookdata.isbn;
    }
    if (bookdata.publisher.length > 0) {
      document.querySelector('#publisher').value = bookdata.publisher;
    }
    if (bookdata.pages.length > 0) {
      document.querySelector('#pages').value = bookdata.pages;
      document.querySelector('#pages').style.backgroundColor = '#FFFF99';
    }
    if (bookdata.url.length > 0) {
      document.querySelector('#url').value = bookdata.url;
    }
    if (bookdata.date.length > 0) {
      document.querySelector('#date').value = bookdata.date;
    }
    for (var i = 0; i < bookdata.authors.length && i <= 2; i++) {
      var authorn = i + 1;
      var author = bookdata.authors[i];
      var match = /(.+)\s+(.+)/.exec(author);
      if (match) {
        document.querySelector("#first".concat(authorn)).value = match[1];
        document.querySelector("#last".concat(authorn)).value = match[2];
      } else {
        document.querySelector("#last".concat(authorn)).value = author;
      }
    }
    document.querySelector('#coauthors').value = bookdata.authors.splice(3).join(', ');
    setAccessDateToday();
    makeRefname();
  };
  var useDiberriData = function useDiberriData(bookdata) {
    document.querySelector('#progress').style.visibility = 'hidden';
    if (bookdata.title.length > 0) {
      document.querySelector('#title').value = bookdata.title;
    }
    if (bookdata.isbn.length > 0) {
      document.querySelector('#isbn').value = bookdata.isbn;
    }
    if (bookdata.publisher.length > 0) {
      document.querySelector('#publisher').value = bookdata.publisher;
    }
    if (bookdata.location.length > 0) {
      document.querySelector('#location').value = bookdata.location;
    }
    if (bookdata.year.length > 0) {
      document.querySelector('#date').value = bookdata.year;
    }
    if (bookdata.authors.length > 0) {
      var authors = bookdata.authors.split(';', 4);
      for (var i = 0; i < authors.length && i <= 2; i++) {
        var authorn = i + 1;
        var nameparts = authors[i].split(',', 2);
        document.querySelector("#last".concat(authorn)).value = nameparts[0].trim();
        if (nameparts.length === 2) {
          document.querySelector("#first".concat(authorn)).value = nameparts[1].trim();
        }
      }
      if (authors[3]) {
        document.querySelector('#coauthors').value = authors[3].trim();
      }
    }
    makeRefname();
  };
  var useDoiData = function useDoiData(bookdata) {
    document.querySelector('#progress').style.visibility = 'hidden';
    if (bookdata.title) {
      document.querySelector('#title').value = bookdata.title;
    }
    // if (bookdata.isbn.length !== 0) { document..querySelector('#isbn').value = bookdata.isbn; }
    // if (bookdata.publisher.length !== 0) { document..querySelector('#publisher').value = bookdata.publisher; }
    // if (bookdata.location.length !== 0) { document..querySelector('#location').value = bookdata.location; }
    if (bookdata.year) {
      document.querySelector('#date').value = bookdata.year;
    }
    if (bookdata.issn) {
      document.querySelector('#issn').value = bookdata.issn;
    }
    if (bookdata.journal) {
      document.querySelector('#journal').value = bookdata.journal;
    }
    if (bookdata.volume) {
      document.querySelector('#volume').value = bookdata.volume;
    }
    if (bookdata.issue) {
      document.querySelector('#issue').value = bookdata.issue;
    }
    if (bookdata.pages) {
      document.querySelector('#pages').value = bookdata.pages;
    }
    if (bookdata.authors) {
      var coauthors = [];
      bookdata.authors.forEach(function (author, i) {
        var authorn = i + 1;
        if (authorn === 1) {
          if (author.last) {
            document.querySelector('#last').value = author.last.trim();
          }
          if (author.first) {
            document.querySelector('#first').value = author.first.trim();
          }
        } else {
          var authorparts = [];
          if (author.first) {
            authorparts.push(author.first.trim());
          }
          if (author.last) {
            authorparts.push(author.last.trim());
          }
          coauthors.push(authorparts.join(' '));
        }
      });
      if (coauthors[0]) {
        document.querySelector('#coauthors').value = coauthors.join(', ');
      }
    }
    makeRefname();
  };
  var useUrlData = function useUrlData(data) {
    document.querySelector('#progress').style.visibility = 'hidden';
    if (data.title) {
      document.querySelector('#title').value = data.title;
    }
    if (data.work) {
      document.querySelector('#work').value = data.work;
    }
    if (data.page) {
      document.querySelector('#pages').value = data.page;
    }
    if (data.date) {
      document.querySelector('#date').value = formatDate(data.date, getDateFormat());
    }
    if (data.authors) {
      var coauthors = [];
      data.authors.forEach(function (author, i) {
        var authorn = i + 1;
        if (authorn === 1) {
          var match = /(.+)\s+(.+)/.exec(author);
          if (match) {
            document.querySelector('#first').value = match[1].trim();
            document.querySelector('#last').value = match[2].trim();
          } else {
            document.querySelector('#last').value = author.trim();
          }
        } else {
          coauthors.push(author);
        }
      });
      if (coauthors[0]) {
        document.querySelector('#coauthors').value = coauthors.join(', ');
      }
    }
  };
  mw.hook('mw.toolbar').add(function () {
    refbuttons();
  });
})(jQuery, mediaWiki);

/* </nowiki> */