ผลต่างระหว่างรุ่นของ "ผู้ใช้:Bebiezaza/iScript/helper.js"
< ผู้ใช้:Bebiezaza | iScript
เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
9.14-019 |
ล 9.14-019a |
||
บรรทัด 311: | บรรทัด 311: | ||
'href': d |
'href': d |
||
}); |
}); |
||
if (document.querySelectorAll('#p-cactions span')[1]) { // this if-else statement is a workaround to separate between old and new vector |
if (document.querySelectorAll('#p-cactions span')[1] != "<span>เปลี่ยนชื่อ</span>") { // this if-else statement is a workaround to separate between old and new vector |
||
newspan = document.createElement("span"); |
newspan = document.createElement("span"); |
||
newspan.appendChild(document.createTextNode(e)); |
newspan.appendChild(document.createTextNode(e)); |
รุ่นแก้ไขเมื่อ 22:18, 3 กันยายน 2564
// ==============================================================
// สคริปต์จัดให้: helper module
// Available functions:
// * JSON - [Object].toJSONString
// * Global Error Handling Support
// * [XMLDOM]
// * dynamicSort
// * [Array].indexOf
// * [Array].every
// * [Array].toSource
// * addTab
// * addToolboxLink
// * addMenu
// * assignToEditForm
// * assignToEditTalkForm
// * getPname
// * getSelText
// * getSelTextArea
// * getUploader
// * getThaiFullMonthName
// * qid_getFileHistory (required for getUploader)
// * SetCaretTo
// * openInNewWindow
// * isIPAddress
// * userIsInGroup
// * [String].trim
// * [String.replaceAll
// * htmlNode
// * [Status]
// * [QueryString]
// * [Wikipedia API]
// * [sprintf]
//
// Copyright (C) 2006-2011, Jutiphan Mongkolsuthree
// Certain functions are copyrighted by their
// respective copyright holders.
//
// No warranty expressed or implied. Use at your own risk.
//
// Created: 1/12/2006
// Replaced: none
//
// Additional Credits Information:
// ==============================================================
// JSON - [Object].toJSONString
// 2008-03-14 Public Domain
// See //www.JSON.org/js.html
// TODO: This is now superceded by json2 and needs to be updated later
//
// ==============================================================
// Array functions
// Taken from //www.dustindiaz.com/basement/sugar-arrays.html
// TODO: This needs to be replaced by uniformed JS 1.6 Library for non-supported browsers
//
// ==============================================================
// getUploader and qid_getFileHistory functions
// Source: en:User:Howcheng/quickimgdelete.js, adapted & further modified by user:Jutiphan
// Current version: 1.13.1
// Created by [[User:Howcheng|Howard Cheng]]
// Released under the [[GNU Public License]] (GPL)
// Full documentation at [[User talk:Howcheng/quickimgdelete.js]]
// NOTE: DO NOT UPGRADE TO NEWER VER WITHOUT MERGE. This is custom, also included sysop fix.
//
// ==============================================================
// setCaretTo function
// Source: //parentnode.org/javascript/working-with-the-cursor-position/
//
// ==============================================================
// replace function
// Source: //www.irt.org/script/242.htm
// ==============================================================
//
// This information may be incomplete. Apologize if incomplete or inaccurate.
// Feel free to inform at [[User Talk:Jutiphan]]
//
/* <pre><nowiki> */
window.XMLDOM = function window$XMLDOM(a) {
if (!window.DOMParser) {
var b = ['Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument'];
for (var i = 0; i < b.length; i++) {
try {
var c = new ActiveXObject(b[i]);
c.loadXML(a);
c.setProperty('SelectionLanguage', 'XPath');
return c
} catch (ex) {}
}
return null
} else {
try {
var d = new window.DOMParser();
return d.parseFromString(a, 'text/xml')
} catch (ex) {
return null
}
}
return null
};
function dynamicSort(d) {
var e = 1;
if (d[0] === "-") {
e = -1;
d = d.substr(1)
}
return function(a, b) {
var c = a[d].localeCompare(b[d]);
return c * e
}
}
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function(a, b) {
var b = b || 0;
for (var i = b; i < this.length; ++i) {
if (this[i] === a) {
return i
}
}
return -1
}
}
if (!Array.prototype.every) {
Array.prototype.every = function(a, b) {
var c = b || window;
for (var i = 0, j = this.length; i < j; ++i) {
if (!a.call(c, this[i], i, this)) {
return false
}
}
return true
}
}
if (!Array.prototype.toSource) {
Array.prototype.toSource = function() {
var L = this.length,
s = '[',
t, i;
for (i = 0; i < L; i++) {
if (i > 0) s += ',';
if (this[i].constructor == Array) s += this[i].toSource();
else switch (typeof this[i]) {
case "number":
s += this[i];
break;
case "boolean":
s += this[i];
break;
default:
s += '"' + this[i].toString().split('"').join('\\"') + '"'
}
}
return s + ']'
}
}
function AddVectorTab(a, b, c, d, e, f) {
var g = document.getElementById('p-views');
var h = g.childNodes[3];
var ha = h.childNodes[1];
var i = createElement('a', b, {
'title': d,
'href': a
});
var k = createElement('li', i, {
'id': c,
'class': 'collapsible'
});
if (f == null) {
var f = document.getElementById('ca-watch')
}
if (f == null) f = document.getElementById('ca-unwatch');
ha.insertBefore(k, f)
}
function addTab(a, b, c, d, e, f) {
return mw.util.addPortletLink('p-cactions', a, b, c, d, e, f)
}
function addToolboxLink(a, b, c, d) {
return mw.util.addPortletLink('p-mScripts', a, b, c, d)
}
function addBookmarkLink(a, b, c, d) {
return mw.util.addPortletLink('p-mBookmarks', a, b, c, d)
}
function addMenu(a, b, c, d, e, f, g) {
addMenuItem('iScript-notify', 'แจ้ง▼', a, b, c, d, e, f, g)
}
function addWPMenu(a, b, c, d, e, f, g) {
addMenuItem('iScript-wpProjects', 'แจ้งอยู่ในโครงการ▼', a, b, c, d, e, f, g)
}
function addMenuItem(a, b, c, d, e, f, g, h, i) {
var j, mn;
var k;
var l = "#1e90ff";
var m = document.getElementById(a);
if (m) {
if (mw.config.get('skin') == "vector") {
m = document.getElementById(a)
} else {
m = m.getElementsByTagName('ul')[0]
}
} else {
if (mw.config.get('skin') == "vector") {
b = b.replace("▼", "");
var n = document.getElementById('right-navigation');
var p = createElement('span', b, "");
var q = createElement('input', "", {
'type': "checkbox",
'class': "vector-menu-checkbox",
'aria-labelledby': "p-iScriptMenu-label"
});
var r = createElement('h3', p, {
'id': "p-iScriptMenu-label"
});
var s = createElement('nav', [q, r], {
'id': "p-iScriptMenu",
'class': "mw-portlet mw-portlet-cactions vector-menu vector-menu-dropdown",
'aria-labelledby': "p-iScriptMenu-label",
'role': "navigation"
});
if (a == 'iScript-wpProjects') {
var t = createElement('div', "", {
'id': a,
'class': "vector-menu-content forced-right iScript-projects-dropdown"
})
} else {
var t = createElement('div', "", {
'id': a,
'class': "vector-menu-content forced-right"
})
}
s.appendChild(t);
m = createElement("ul", "", {
'class': "vector-menu-content-list"
});
t.appendChild(m);
if (document.querySelectorAll('#right-navigation input')[3]) { // this if-else statement is a workaround to separate between old and new vector
var v = document.getElementById("p-search");
n.insertBefore(s, v);
} else n.appendChild(s);
} else {
var n = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if (a == 'iScript-wpProjects') {
m = createElement("ul", "", {
'class': "iScript-menu-monobook-list2 iScript-projects-dropdown"
});
var w = createElement("li", [b, m], {
'id': a,
'class': "iScript-menu-monobook2",
});
} else {
m = createElement("ul", "", {
'class': "iScript-menu-monobook-list"
});
var w = createElement("li", [b, m], {
'id': a,
'class': "iScript-menu-monobook",
});
}
n.appendChild(w)
}
if (!window.XMLHttpRequest && document.all) {
w.onmouseover = function() {
w.style.zIndex = 3;
m.style.display = "block"
};
w.onmouseout = function() {
w.style.zIndex = 0;
m.style.display = "none"
}
}
}
if (c) {
switch (c) {
case 'serious':
l = '#b22222';
break;
case 'content':
l = '#f28500';
break;
case 'style':
l = '#f4c430';
break;
case 'merge':
l = '#9932cc';
break;
case 'notice':
l = '#1e90ff';
break;
case 'growth':
l = '#228b22';
break;
default:
l = c
}
}
if (!f) f = e;
if (!d) d = '#';
j = createElement("a", "", {
'href': d
});
if (document.querySelectorAll('#p-cactions span')[1] != "<span>เปลี่ยนชื่อ</span>") { // this if-else statement is a workaround to separate between old and new vector
newspan = document.createElement("span");
newspan.appendChild(document.createTextNode(e));
j.appendChild(newspan);
} else j.appendChild(document.createTextNode(e));
if (h) {
j.setAttribute("accesskey", h);
g += " [" + h + "]"
}
if (g) j.setAttribute('title', g);
mn = document.createElement("ul");
k = document.createElement("li");
k.appendChild(j);
k.style.cssText = "border-left: 10px solid " + l + ";";
if (f) k.id = f;
if (mw.config.get('skin') == "vector" && m.localName != "ul") {
m = m.getElementsByTagName('ul')[0]
}
if (i) {
m.insertBefore(k, i)
} else {
m.appendChild(k)
}
return mn
}
function assignToEditForm(a, b, c, d, e) {
if (iScriptConfig.useAjaxApi && a.indexOf("addMessageTemplate") == 0) {
AddTemplate(mw.config.get('wgPageName'), b, c, d, e);
return
}
var f = mw.config.get('wgScript') + "?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&iScriptAction=" + a;
if (b != null) {
f += "&iScriptParam1=" + b
}
if (c != null) {
f += "&iScriptParam2=" + c
}
if (d != null) {
f += "&iScriptParam3=" + d
}
if (e != null) {
f += "&iScriptParam4=" + e
}
location.assign(f)
}
function assignToEditTalkForm(a, b, c, d) {
var e = "พูดคุย:";
if (mw.config.get('wgNamespaceNumber') > 0) {
e = mw.config.get('wgPageName').substr(0, mw.config.get('wgPageName').indexOf(":") + 1);
if (mw.config.get('wgNamespaceNumber') % 2 == 0) {
if (e.indexOf("ผู้ใช้") >= 0) {
e = "คุยกับ" + e
} else {
e = "คุยเรื่อง" + e
}
}
}
if (iScriptConfig.useAjaxApi == true) {
if (a.indexOf("doWP") == 0) {
AddWPBanner(e + mw.config.get('wgTitle'), b, c, d)
} else if (a.indexOf("addMessageTemplate") == 0) {
AddTemplate(e + mw.config.get('wgTitle'), b, c, d)
}
return
}
e = encodeURIComponent(e);
if (mw.config.get('wgAction').indexOf("edit") == 0) {
if (a.indexOf("doWP") == 0) {
doWP(b, c, d);
return
} else if (a.indexOf("addMessageTemplate") == 0) {
addMessageTemplate(b, c, d);
return
}
}
var f = mw.config.get('wgScript') + "?title=" + e + encodeURIComponent(mw.config.get('wgTitle')) + "&action=edit&iScriptAction=" + a;
if (b != null) {
f += "&iScriptParam1=" + b
}
if (c != null) {
f += "&iScriptParam2=" + c
}
if (d != null) {
f += "&iScriptParam3=" + d
}
location.assign(f)
}
function createElement(a, b, c) {
var d = document.createElement(a);
if (!(b instanceof Array)) {
b = [b]
}
for (var i = 0; i < b.length; i++) {
var f = b[i];
if (typeof f == 'string') {
f = document.createTextNode(f)
}
if (f) {
d.appendChild(f)
}
}
if (typeof c == 'object') {
for (var k in c) {
switch (k) {
case 'styles':
var g = c.styles;
for (var s in g) {
d.style[s] = g[s]
}
break;
case 'events':
var h = c.events;
for (var e in h) {
addHandler(d, e, h[e])
}
break;
case 'class':
d.className = c[k];
break;
case 'toJSONString':
break;
default:
d.setAttribute(k, c[k])
}
}
}
return d
}
function getPname() {
if (typeof mw.config.get('wgPageName') != 'undefined' && mw.config.get('wgPageName') != null) {
return mw.config.get('wgPageName').replace(/_/g, ' ')
} else {
return document.getElementsByTagName('h1')[0].firstChild.nodeValue
}
}
function getSelText() {
var a = "";
if (window.getSelection && window.getSelection().toString() && $(window.getSelection()).attr('type') != "Caret") {
a = window.getSelection().toString();
return a
} else if (document.getSelection && document.getSelection().toString() && $(document.getSelection()).attr('type') != "Caret") {
a = document.getSelection().toString();
return a
} else {
var b = document.selection && document.selection.createRange();
if (!(typeof b === "undefined") && b.text && b.text.toString()) {
a = b.text;
return a
}
}
if (window.getSelection) {
selText = window.getSelection()
} else if (document.getSelection) {
selText = document.getSelection()
} else if (document.selection) {
selText = document.selection.createRange();
selText = selText.text
} else {
return ""
}
}
function getSelTextArea() {
var a = document.editform.wpTextbox1;
if ($.client.profile().layout == 'gecko') {
if (a.selectionStart || a.selectionStart == '0') {
var b = a.selectionStart;
var c = a.selectionEnd;
return (a.value).substring(b, c)
}
} else {
var d = "";
if (window.getSelection) {
d = window.getSelection()
} else if (document.getSelection) {
d = document.getSelection()
} else if (document.selection) {
d = document.selection.createRange();
d = d.text
}
return d
}
return ""
}
function getUploader() {
var a = qid_getFileHistory();
var b = new Array();
var c = a[0];
do {
c = c.nextSibling;
var d = c.childNodes;
var e = d[(userIsInGroup("sysop") ? 5 : 4)];
b[b.length] = e
} while (c.nextSibling);
var f = new Array();
var g = new RegExp(('/wiki/').replace(/\./g, '\\.') + 'ผู้ใช้:(.*)$');
var h = new RegExp((mw.config.get('wgServer') + mw.config.get('wgScript')).replace(/\./g, '\\.') + '\\?title=ผู้ใช้:([^&]*)');
var j = /(คุยกับ)?ผู้ใช้:(.*?)( \((ยังไม่ได้สร้าง|หน้านี้ไม่มี)\))?$/;
var m;
var l;
var n = "";
var o = 0;
for (var i = 0; i < b.length; i++) {
var p = b[i];
if (!p) continue;
var q = p.childNodes;
if (!q) continue;
for (var k = 0; k < q.length; k++) {
if (q[k].tagName != 'A') continue;
m = j.exec(q[k].title);
if (m) l = encodeURIComponent(m[2]);
m = g.exec(q[k].href);
if (m) l = m[1];
m = h.exec(q[k].href);
if (m) l = m[1];
if (l) break
}
if (n.indexOf(l) == -1) {
if (o > 0) n += "; ";
n += o + " - " + l;
f[f.length] = l;
o += 1
}
}
if (!f || f.length == 0) {
alert("getUploader: ไม่สามารถดึงชื่อผู้ใช้ที่อัปโหลดได้ กรุณาแจ้งผู้ใช้:Jutiphan");
return null
}
if (f.length == 1) return f[0];
var r = parseInt(window.prompt("กรุณาเลือกชื่อผู้ใช้ที่ต้องการจะแจ้ง: " + n, ""));
if (isNaN(r) || r < 0 || r >= f.length) {
alert("getUploader: ไม่มีชื่อผู้ใช้ที่เลือก หยุดการดำเนินการ");
return null
}
return f[r]
}
function GetThaiFullMonthName(a) {
switch (a) {
case 1:
return "มกราคม";
case 2:
return "กุมภาพันธ์";
case 3:
return "มีนาคม";
case 4:
return "เมษายน";
case 5:
return "พฤษภาคม";
case 6:
return "มิถุนายน";
case 7:
return "กรกฎาคม";
case 8:
return "สิงหาคม";
case 9:
return "กันยายน";
case 10:
return "ตุลาคม";
case 11:
return "พฤศจิกายน";
case 12:
return "ธันวาคม";
default:
return ""
}
}
function qid_getFileHistory() {
var a = document.getElementById('mw-imagepage-section-filehistory');
if (!a) {
alert("getUploader: ไม่พบประวัติไฟล์ หยุดการดำเนินงาน กรุณาแจ้งผู้ใช้:Jutiphan");
return null
}
a = a.firstChild;
while (a.nextSibling) {
a = a.nextSibling;
if (a.tagName && a.tagName.toLowerCase() == 'table') break
}
if (!a) {
alert("getUploader: ไม่พบป้าย TABLE หยุดการทำงาน กรุณาแจ้งผู้ใช้:Jutiphan");
return null
}
var b = a.getElementsByTagName('tr');
if (!b) {
alert("getUploader: ไม่พบป้าย TR หยุดการทำงาน กรุณาแจ้งผู้ใช้:Jutiphan");
return null
}
return b
}
function setCaretTo(a, b) {
if (a.createTextRange) {
var c = a.createTextRange();
c.move("character", b);
c.select()
} else if (a.selectionStart) {
a.focus();
a.setSelectionRange(b, b)
}
}
function openInNewWindow(a, b, c) {
if (!b) {
b = '_blank'
}
var d = window.open(a, b);
if (c) {
d.focus()
}
}
function isIPAddress(a) {
var b = /(\d{1,4})\.(\d{1,3})\.(\d{1,3})\.(\d{1,4})/.exec(a);
return b != null && b.slice(1, 5).every(function(e) {
return e < 256
})
}
function userIsInGroup(a) {
for (var i = 0; i < mw.config.get('wgUserGroups').length; i++) {
if (mw.config.get('wgUserGroups')[i] == a) return true
}
return false
}
function replace(a, b, c) {
var d = a.length,
txtLength = b.length;
if ((d == 0) || (txtLength == 0)) return a;
var i = a.indexOf(b);
if ((!i) && (b != a.substring(0, txtLength))) return a;
if (i == -1) return a;
var e = a.substring(0, i) + c;
if (i + txtLength < d) e += replace(a.substring(i + txtLength, d), b, c);
return e
}
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/, '')
};
String.prototype.replaceAll = function(a, b) {
var c = this;
var d = c.indexOf(a);
while (d != -1) {
c = c.replace(a, b);
d = c.indexOf(a)
}
return (c)
};
function htmlNode(a, b, c) {
var d = document.createElement(a);
if (c) {
d.style.color = c
}
d.appendChild(document.createTextNode(b));
return d
}
function errorHandler(a, b, c) {
Status.error("ขออภัย พบเจอข้อผิดพลาด " + a + " บรรทัดที่ " + c + " ใน " + b + ". กรุณาแจ้งปัญหานี้ที่ ผู้ใช้:Jutiphan");
return true
}
window.onerror = errorHandler;
Exception = function(a) {
this.message = a || '';
this.name = "Exception"
};
Exception.prototype.what = function() {
return this.str
};
function Status(a, b, c) {
this.text = this.codify(a);
this.stat = this.codify(b);
this.type = c || 'status';
this.generate();
if (b) {
this.render()
}
}
Status.init = function(a) {
if (!(a instanceof Element)) {
throw new Exception('object not an instance of Element');
}
while (a.hasChildNodes()) {
a.removeChild(a.firstChild)
}
Status.root = a;
var b = document.createElement('style');
b.type = 'text/css';
b.rel = 'stylesheet';
b.appendChild(document.createTextNode(""));
document.getElementsByTagName("head")[0].appendChild(b);
var c = b.sheet ? b.sheet : b.stylesSheet;
c.insertRule(".tw_status_status { color: SteelBlue; }", 0);
c.insertRule(".tw_status_info { color: ForestGreen; }", 0);
c.insertRule(".tw_status_warn { color: OrangeRed; }", 0);
c.insertRule(".tw_status_error { color: OrangeRed; font-weight: 900; }", 0)
};
Status.root = null;
Status.prototype = {
stat: null,
text: null,
type: 'status',
target: null,
node: null,
linked: false,
link: function() {
if (!this.linked && Status.root) {
Status.root.appendChild(this.node);
this.linked = true
}
},
unlink: function() {
if (this.linked) {
Status.root.removeChild(this.node);
this.linked = false
}
},
codify: function(a) {
if (!(a instanceof Array)) {
a = [a]
}
var b;
b = document.createDocumentFragment();
for (var i = 0; i < a.length; ++i) {
if (typeof a[i] == 'string') {
b.appendChild(document.createTextNode(a[i]))
} else if (a[i] instanceof Element) {
b.appendChild(a[i])
}
}
return b
},
update: function(a, b) {
this.stat = this.codify(a);
if (b) {
this.type = b
}
this.render()
},
generate: function() {
this.node = document.createElement('div');
this.node.appendChild(document.createElement('span')).appendChild(this.text);
this.node.appendChild(document.createElement('span')).appendChild(document.createTextNode(': '));
this.target = this.node.appendChild(document.createElement('span'));
this.target.appendChild(document.createTextNode(''))
},
render: function() {
this.node.className = 'tw_status_' + this.type;
while (this.target.hasChildNodes()) {
this.target.removeChild(this.target.firstChild)
}
this.target.appendChild(this.stat);
this.link()
},
status: function(a) {
this.update(a, 'status')
},
info: function(a) {
this.update(a, 'info')
},
warn: function(a) {
this.update(a, 'warn')
},
error: function(a) {
this.update(a, 'error')
}
};
Status.status = function(a, b) {
return new Status(a, b, 'status')
};
Status.info = function(a, b) {
return new Status(a, b, 'info')
};
Status.warn = function(a, b) {
return new Status(a, b, 'error')
};
Status.error = function(a, b) {
return new Status(a, b, 'error')
};
function QueryString(a) {
this.string = a;
this.params = {};
if (a.length == 0) {
return
}
a.replace(/\+/, ' ');
var b = a.split('&');
for (var i = 0; i < b.length; ++i) {
var c = b[i].split('=');
var d = decodeURIComponent(c[0]),
value = d;
if (c.length == 2) {
value = decodeURIComponent(c[1])
}
this.params[d] = value
}
}
QueryString.static = null;
QueryString.staticInit = function() {
if (QueryString.static == null) {
QueryString.static = new QueryString(location.search.substring(1))
}
};
QueryString.get = function(a) {
QueryString.staticInit();
return QueryString.static.get(a)
};
QueryString.prototype.get = function(a) {
return this.params[a] ? this.params[a] : null
};
QueryString.exists = function(a) {
QueryString.staticInit();
return QueryString.static.exists(a)
};
QueryString.prototype.exists = function(a) {
return this.params[a] ? true : false
};
QueryString.equals = function(a, b) {
QueryString.staticInit();
return QueryString.static.equals(a, b)
};
QueryString.prototype.equals = function(a, b) {
return this.params[a] == b ? true : false
};
QueryString.toString = function() {
QueryString.staticInit();
return QueryString.static.toString()
};
QueryString.prototype.toString = function() {
return this.string ? this.string : null
};
QueryString.create = function(a) {
var b = Array();
var c;
for (var i in a) {
if (typeof a[i] == 'undefined') {
continue
}
var d;
if (a[i] instanceof Array) {
var v = Array();
for (var j = 0; j < a[i].length; ++j) {
v[j] = encodeURIComponent(a[i][j])
}
d = v.join('|')
} else {
d = encodeURIComponent(a[i])
}
if (i == 'wpEditToken') {
c = d
} else {
b.push(encodeURIComponent(i) + '=' + d)
}
}
if (typeof c != 'undefined') {
b.push('wpEditToken=' + c)
}
return b.join('&')
};
QueryString.prototype.create = QueryString.create;
Wikipedia = {};
Wikipedia.dump = [];
Wikipedia.numberOfActionsLeft = 0;
Wikipedia.nbrOfCheckpointsLeft = 0;
Wikipedia.actionCompleted = function(a) {
if (--Wikipedia.numberOfActionsLeft <= 0 && Wikipedia.nbrOfCheckpointsLeft <= 0) {
Wikipedia.actionCompleted.event(a)
}
};
Wikipedia.actionCompleted.event = function() {
new Status(Wikipedia.actionCompleted.notice, Wikipedia.actionCompleted.postfix, 'info');
if (Wikipedia.actionCompleted.redirect != null) {
if (!/^\w+\:\/\//.test(Wikipedia.actionCompleted.redirect)) {
Wikipedia.actionCompleted.redirect = mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', encodeURIComponent(Wikipedia.actionCompleted.redirect).replace(/\%2F/g, '/'))
}
window.setTimeout(function() {
window.location = Wikipedia.actionCompleted.redirect
}, Wikipedia.actionCompleted.timeOut)
}
};
wpActionCompletedTimeOut = typeof(wpActionCompletedTimeOut) == 'undefined' ? 5000 : wpActionCompletedTimeOut;
wpMaxLag = typeof(wpMaxLag) == 'undefined' ? 10 : wpMaxLag;
Wikipedia.editCount = 10;
Wikipedia.actionCompleted.timeOut = wpActionCompletedTimeOut;
Wikipedia.actionCompleted.redirect = null;
Wikipedia.actionCompleted.notice = 'Action';
Wikipedia.actionCompleted.postfix = 'เรียบร้อย';
Wikipedia.addCheckpoint = function() {
++Wikipedia.nbrOfCheckpointsLeft
};
Wikipedia.removeCheckpoint = function() {
if (--Wikipedia.nbrOfCheckpointsLeft <= 0 && Wikipedia.numberOfActionsLeft <= 0) {
Wikipedia.actionCompleted.event()
}
};
Wikipedia.api = function(a, b, c, d) {
this.currentAction = a;
this.query = b;
this.query['format'] = 'xml';
this.oninit = c;
if (d) {
d.status(a)
} else {
this.statelem = new Status(a)
}++Wikipedia.numberOfActionsLeft
};
Wikipedia.api.prototype = {
currentAction: '',
oninit: null,
query: null,
responseXML: null,
statelem: null,
counter: 0,
post: function() {
var a = sajax_init_object();
Wikipedia.dump.push(a);
a.obj = this;
a.overrideMimeType('text/xml');
a.open('POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true);
a.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
a.onerror = function() {
this.obj.statelem.error("พบเจอข้อผิดพลาด " + this.target.status + " ระหว่างกำลังดึงข้อมูลผ่าน API")
};
a.onload = function() {
this.obj.responseXML = this.responseXML;
if (this.obj.oninit) {
this.obj.oninit(this.obj)
}
Wikipedia.actionCompleted()
};
a.send(QueryString.create(this.query))
}
};
Wikipedia.wiki = function(a, b, c, d, e, f) {
this.currentAction = a;
this.query = b;
this.oninit = c;
this.onsuccess = d;
this.onerror = e;
this.onretry = f;
this.statelem = new Status(a);
++Wikipedia.numberOfActionsLeft
};
Wikipedia.wiki.prototype = {
currentAction: '',
onsuccess: null,
onerror: null,
onretry: null,
oninit: null,
query: null,
postData: null,
responseXML: null,
statelem: null,
counter: 0,
post: function(l) {
this.postData = l;
if (Wikipedia.editCount <= 0) {
this.query['maxlag'] = wpMaxLag
} else {
--Wikipedia.editCount
}
var m = sajax_init_object();
Wikipedia.dump.push(m);
m.obj = this;
m.overrideMimeType('text/xml');
m.open('POST', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?useskin=monobook&' + QueryString.create(this.query), true);
m.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
m.onerror = function(e) {
var a = this.obj;
a.statelem.error("Error " + e.target.status + " occurred while posting the document.")
};
m.onload = function(e) {
var b = this.obj;
var c = e.target.status;
if (c != 200) {
if (c == 503) {
var d = e.target.getResponseHeader('Retry-After');
var f = e.target.getResponseHeader('X-Database-Lag');
if (f) {
b.statelem.warn("current lag of " + f + " seconds is more than our defined maximum lag of " + wpMaxLag + " seconds, will retry in " + d + " seconds");
window.setTimeout(function(a) {
a.post(a.postData)
}, d * 1000, b);
return
} else {
b.statelem.error("Error " + c + " occurred while posting the document.")
}
}
return
}
var g;
g = b.responseXML = this.responseXML;
var h = 'boolean(//div[@class=\'previewnote\']/p/strong[contains(.,\'Sorry! We could not process your edit due to a loss of session data\')])';
var i = g.evaluate(h, g, null, XPathResult.BOOLEAN_TYPE, null).booleanValue;
if (i) {
var j = g.evaluate('//input[@name="wfEditToken"]/@value', g, null, XPathResult.STRING_TYPE, null).stringValue;
b.postData['wfEditToken'] = j;
b.post(b.postData)
} else {
if (b.onsuccess) {
b.onsuccess(b)
} else {
var k = document.createElement('a');
k.setAttribute('href', mw.config.get('wgArticlePath').replace('$1', b.query['title']));
k.setAttribute('title', b.query['title']);
k.appendChild(document.createTextNode(b.query['title']));
b.statelem.info(['เรียบร้อย (', k, ')'])
}
Wikipedia.actionCompleted()
}
};
m.send(QueryString.create(this.postData))
},
get: function() {
this.onloading(this);
var a = {
'action': 'query',
'titles': this.query['title'],
'redirects': ''
};
var b = new Wikipedia.api("กำลังตรวจสอบและข้ามหน้าเปลี่ยนทาง", a, this.postget, this.statelem);
b.parent = this;
b.post()
},
postget: function() {
var b = self.responseXML = this.responseXML;
var c = b.evaluate('//redirects/r/@to', b, null, XPathResult.STRING_TYPE, null).stringValue;
if (!this.followRedirect) {
this.parent.statelem.info('ไม่สนใจหน้าเปลี่ยนทาง')
} else if (c) {
this.parent.query['title'] = c
}
this.parent.onloading(this);
var d = sajax_init_object();
Wikipedia.dump.push(d);
d.obj = this.parent;
d.overrideMimeType('text/xml');
d.open('GET', mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?useskin=monobook&' + QueryString.create(this.parent.query), true);
d.onerror = function() {
var a = this.obj;
a.statelem.error("Error " + this.status + " occurred while receiving the document.")
};
d.onload = function() {
this.obj.onloaded(this.obj);
this.obj.responseXML = this.responseXML;
this.obj.responseText = this.responseText;
this.obj.oninit(this.obj)
};
d.send(null)
},
onloading: function() {
this.statelem.status('กำลังโหลด...')
},
onloaded: function() {
this.statelem.status('ข้อมูลโหลดแล้ว...')
}
};
function sprintf() {
if (arguments.length == 0) {
throw "Not enough arguments for sprintf";
}
var b = "";
var c = arguments[0];
var d = 1;
var e = 1;
var f = {};
var g = false;
var h = false;
var j = false;
var k = false;
var l = false;
var m = '.';
for (var i = 0; i < c.length; ++i) {
var n = c.charAt(i);
if (g) {
switch (n) {
case 'i':
n = 'd';
break;
case 'F':
n = 'f';
break;
case '%':
case 'c':
case 's':
case 'd':
case 'u':
case 'o':
case 'x':
case 'e':
case 'f':
case 'g':
case 'X':
case 'E':
case 'G':
case 'b':
var o = arguments[e];
if (l) {
r = o.toString().split('');
b += o.toString().split('').map(function(a) {
return sprintf.format(n, a.charCodeAt(), f)
}).join(m)
} else {
b += sprintf.format(n, o, f)
}
if (!k) {
++d
}
e = d;
f = {};
h = false;
g = false;
j = false;
k = false;
l = false;
m = '.';
break;
case 'v':
l = true;
break;
case ' ':
case '0':
case '-':
case '+':
case '#':
f[n] = true;
break;
case '*':
h = true;
break;
case '.':
j = true;
break
}
if (/\d/.test(n)) {
var p = parseInt(c.substr(i));
var q = p.toString().length;
i += q - 1;
var s = c.charAt(i + 1);
if (s == '$') {
if (p <= 0 || p >= arguments.length) {
throw "out of bound";
}
if (h) {
if (j) {
f['precision'] = arguments[p];
j = false
} else if (c.charAt(i + 2) == 'v') {
m = arguments[p]
} else {
f['width'] = arguments[p]
}
h = false
} else {
k = true;
e = p
}++i
} else if (j) {
f['precision'] = p;
j = false
} else {
f['width'] = p
}
} else if (h && !/\d/.test(c.charAt(i + 1))) {
if (j) {
f['precision'] = arguments[e];
j = false
} else if (c.charAt(i + 1) == 'v') {
m = arguments[e]
} else {
f['width'] = arguments[e]
}++d;
if (!k) {
e++
}
h = false
}
} else {
if (n == '%') {
g = true;
continue
} else {
b += n;
continue
}
}
}
return b
}
sprintf.format = function sprintfFormat(a, b, c) {
if (b == undefined) {
if (a == 's') {
return ''
} else {
return '0'
}
}
var d;
var e = '';
var f = '';
var g = ' ';
switch (a) {
case '%':
d = '%';
break;
case 'c':
d = String.fromCharCode(parseInt(b));
break;
case 's':
d = b.toString();
break;
case 'd':
d = parseInt(b).toString();
break;
case 'u':
d = Math.abs(parseInt(b)).toString();
break;
case 'o':
d = (new Number(Math.abs(parseInt(b)))).toString(8);
break;
case 'x':
d = (new Number(Math.abs(parseInt(b)))).toString(16);
break;
case 'b':
d = (new Number(Math.abs(parseInt(b)))).toString(2);
break;
case 'e':
var h = c['precision'] ? c['precision'] : 6;
d = (new Number(b)).toExponential(h).toString();
break;
case 'f':
var h = c['precision'] ? c['precision'] : 6;
d = (new Number(b)).toFixed(h).toString();
case 'g':
var h = c['precision'] ? c['precision'] : 6;
d = (new Number(b)).toPrecision(h).toString();
break;
case 'X':
d = (new Number(Math.abs(parseInt(b)))).toString(16).toUpperCase();
break;
case 'E':
var h = c['precision'] ? c['precision'] : 6;
d = (new Number(b)).toExponential(h).toString().toUpperCase();
break;
case 'G':
var h = c['precision'] ? c['precision'] : 6;
d = (new Number(b)).toPrecision(h).toString().toUpperCase();
break
}
if (c['+'] && parseFloat(b) > 0 && ['d', 'e', 'f', 'g', 'E', 'G'].indexOf(a) != -1) {
e = '+'
}
if (c[' '] && parseFloat(b) > 0 && ['d', 'e', 'f', 'g', 'E', 'G'].indexOf(a) != -1) {
e = ' '
}
if (c['#'] && parseInt(b) != 0) {
switch (a) {
case 'o':
e = '0';
break;
case 'x':
case 'X':
e = '0x';
break;
case 'b':
e = '0b';
break
}
}
if (c['0'] && !c['-']) {
g = '0'
}
if (c['width'] && c['width'] > (d.length + e.length)) {
var j = c['width'] - d.length - e.length;
for (var i = 0; i < j; ++i) {
f += g
}
}
if (c['-'] && !c['0']) {
d += f
} else {
d = f + d
}
return e + d
};
/* </nowiki></pre> */