ผลต่างระหว่างรุ่นของ "ผู้ใช้:ZilentFyld/Zilentscriptwp.js"

เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
ZilentFyld (คุย | ส่วนร่วม)
ไม่มีความย่อการแก้ไข
ZilentFyld (คุย | ส่วนร่วม)
ไม่มีความย่อการแก้ไข
บรรทัด 5:
var commonsUrl = '//upload.wikimedia.org/wikipedia/commons';
var thmonth = {
'January': 'มกราคม',
'February': 'กุมภาพันธ์',
'March': 'มีนาคม',
'April': 'เมษายน',
'May': 'พฤษภาคม',
'June': 'มิถุนายน',
'July': 'กรกฎาคม',
'August': 'สิงหาคม',
'September': 'กันยายน',
'October': 'ตุลาคม',
'November': 'พฤศจิกายน',
'December': 'ธันวาคม',
};
 
function createAnchor() {
$('.wikiEditor-ui').before(`<div class="toccolours" style="overflow:auto">
<div style="float:left">Anchor (use when searching): <a onclick="clearAnchor()">clear</a></div><div style="float:right">More tools: <a onclick="blockSwitch('#enwiktblock')">wiktionary</a> <a onclick="blockSwitch('#longdoblock')">longdo</a></div>
<div id="enwiktblock" style="float:right;position: absolute;z-index: 10;right: 0px;margin-top: 26px;display:none;width: 50%;min-width: 300px;overflow: auto;height: 45%;" class="toccolours">
บรรทัด 37:
 
function clearAnchor() {
$('#anchor').html('');
}
 
function blockSwitch(ele) {
var ewd = $(ele);
if (ewd.css('display') == 'block') {
ewd.css('display', 'none');
} else {
ewd.css('display', 'block');
}
}
}
 
mw.loader.using('ext.wikiEditor').then(function () {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'main',
'groups': {
'zilentscript': {
'label': "ZilentScript:"
}
}
}
}
} });
$('#wpTextbox1').wikiEditor('addToToolbar', {
'section': 'main',
'group': 'zilentscript',
'tools': {
'qlink': {
'label': 'ลิงค์รวดเร็ว',
'type': 'button',
'icon': commonsUrl + '/b/b7/Interlink_alt.png',
'action': {
'type': 'encapsulate',
'options': {
'pre': '[[', 'peri': 'ลิงค์', 'post': ']]'
}
}
}
}
},
},
'thname': {
label: 'หน้าภาษาไทยที่เชื่อมกับวิกิภาษาอังกฤษ',
type: 'button',
icon: commonsUrl + '/thumb/8/80/Wikipedia-logo-v2.svg/22px-Wikipedia-logo-v2.svg.png',
action: {
type: 'callback',
execute: function () {
var textbox = $('#wpTextbox1');
var selsave = saveSelection('#wpTextbox1');
var val = textbox.val().substring(selsave[0], selsave[1]);
console.log(val);
searchEng(val);
}
}
}
}
},/*
'enwikt':{
label:'ค้นหาวิกิพจนานุกรมอังกฤษ',
บรรทัด 150:
}
},*/
'longdo': {
label: 'ค้นหาลองดู',
type: 'button',
icon: commonsUrl + '/thumb/f/f7/Accessories-dictionary_Faenza.svg/22px-Accessories-dictionary_Faenza.svg.png',
action: {
type: 'callback',
execute: function () {
$('#anchor').html('Seaching...');
$('#enwiktblock').css('display', 'none');
var textbox = $('#wpTextbox1');
var selsave = saveSelection('#wpTextbox1');
var val = textbox.val().substring(selsave[0], selsave[1]);
$.ajax({
method: "GET",
url: 'https://cors-anywhere.herokuapp.com/https://dict.longdo.com/mobile.php',
data: { search: val }
}).done(function (data) {
$('#anchor').html('Done...');
$('#longdodiv').html(data);
$('#longdoblock').css('display', 'block');
setTimeout(function () { clearAnchor() }, 500);
console.log(data);
});
});
}
}
}
}
},
},
'mymemory': {
label: 'แปลอัตโนมัติ',
type: 'button',
icon: commonsUrl + '/thumb/0/0e/Noun_Project_translate_icon_2822454.svg/22px-Noun_Project_translate_icon_2822454.svg.png',
action: {
type: 'callback',
execute: function () {
$('#anchor').html('Seaching...');
$('#enwiktblock').css('display', 'none');
var textbox = $('#wpTextbox1');
var selsave = saveSelection('#wpTextbox1');
var val = textbox.val().substring(selsave[0], selsave[1]);
console.log(val);
$.get('https://api.mymemory.translated.net/get', {
'q': val,
'langpair': 'en|th',
'of': 'json'
}, function (data) {
createAnchor();
$('#anchor').html('<div style="float:left">Translated:</div><textarea id="anchorbox" style="display:inline;float:left;width:200px;resize:none"></textarea>');
$('#anchorbox').val(data.responseData.translatedText);
});
});
}
}
}
}
}
}
}
}
});
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'otherscript': {
'type': 'toolbar',
'label': 'Script อื่น ๆ',
'groups': {
'่dateformat': {
'label': "เปลี่ยนวันที่",
'tools': {
'date': {
label: 'วันที่จากอัง-ไทย',
type: 'button',
icon: commonsUrl + '/thumb/3/34/US_to_Thai_date_format_with_BE.svg/37px-US_to_Thai_date_format_with_BE.svg.png',
action: {
action:{
type: 'replace',
options: {
options:{
regex: /^(.*?)$/g,
regexReplace: function (match) {
var exp = match;
exp = exp.replace(/([0-9]+) ([A-z]+) (|[1-2])(|[0-9])(|[0-9])([0-9])/g, function (match, d, m, y) {
return d + ' ' + thmonth[m] + ' พ.ศ.' + (parseInt(y) + 543);
});
});
exp = exp.replace(/([A-z]+) ([0-9]+), ([0-9]+)/g, function (match, m, d, y) {
return d + ' ' + thmonth[m] + ' พ.ศ.' + (parseInt(y) + 543);
});
});
return exp;
return exp;
}
}
}
}
}
}
},
},
'datece': {
label: 'วันที่จากอัง-ไทยมี ค.ศ.',
type: 'button',
icon: commonsUrl + '/thumb/9/9c/US_to_Thai_date_format_with_CE.svg/37px-US_to_Thai_date_format_with_CE.svg.png',
action: {
action:{
type: 'replace',
options: {
options:{
regex: /^(.*?)$/g,
regexReplace: function (match) {
var exp = match;
exp = exp.replace(/([0-9]+) ([A-z]+) (|[1-2])(|[0-9])(|[0-9])([0-9])/g, function (match, d, m, y) {
return d + ' ' + thmonth[m] + ' ค.ศ. ' + (parseInt(y));
});
});
exp = exp.replace(/([A-z]+) ([0-9]+), ([0-9]+)/g, function (match, m, d, y) {
return d + ' ' + thmonth[m] + ' ค.ศ. ' + (parseInt(y));
});
});
return exp;
return exp;
}
}
}
}
}
}
},
},
'year': {
label: 'คศ-พศ',
type: 'button',
icon: commonsUrl + '/thumb/c/ca/Calendar_icon_2.svg/22px-Calendar_icon_2.svg.png',
action: {
action:{
type: 'replace',
options: {
options:{
regex: /([0-9]+)/g,
regexReplace: function (match, y) {
return 'พ.ศ. ' + (parseInt(y) + 543);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
});
$('#wpTextbox1').wikiEditor('addToToolbar', {
'section': 'otherscript',
'group': 'dateformat',
'tools': {
'dates': {
'date':{
label: 'วันที่จากอัง-ไทย',
type: 'button',
icon: commonsUrl + '/thumb/3/34/US_to_Thai_date_format_with_BE.svg/37px-US_to_Thai_date_format_with_BE.svg.png',
action: {
type: 'replace',
options: {
regex: /^(.*?)$/g,
regexReplace: function (match) {
var exp = match;
exp = exp.replace(/([0-9]+) ([A-z]+) (|[1-2])(|[0-9])(|[0-9])([0-9])/g, function (match, d, m, y) {
return d + ' ' + thmonth[m] + ' พ.ศ.' + (parseInt(y) + 543);
});
});
exp = exp.replace(/([A-z]+) ([0-9]+), ([0-9]+)/g, function (match, m, d, y) {
return d + ' ' + thmonth[m] + ' พ.ศ.' + (parseInt(y) + 543);
});
});
return exp;
}
}
}
}
}
}
},
},
'dateces': {
'datece':{
label: 'วันที่จากอัง-ไทยมี ค.ศ.',
type: 'button',
icon: commonsUrl + '/thumb/9/9c/US_to_Thai_date_format_with_CE.svg/37px-US_to_Thai_date_format_with_CE.svg.png',
action: {
type: 'replace',
options: {
regex: /^(.*?)$/g,
regexReplace: function (match) {
var exp = match;
exp = exp.replace(/([0-9]+) ([A-z]+) (|[1-2])(|[0-9])(|[0-9])([0-9])/g, function (match, d, m, y) {
return d + ' ' + thmonth[m] + ' ค.ศ. ' + (parseInt(y));
});
});
exp = exp.replace(/([A-z]+) ([0-9]+), ([0-9]+)/g, function (match, m, d, y) {
return d + ' ' + thmonth[m] + ' ค.ศ. ' + (parseInt(y));
});
});
return exp;
}
}
}
}
}
}
},
},
'years': {
'year':{
label: 'คศ-พศ',
type: 'button',
icon: commonsUrl + '/thumb/c/ca/Calendar_icon_2.svg/22px-Calendar_icon_2.svg.png',
action: {
type: 'replace',
options: {
regex: /([0-9]+)/g,
regexReplace: function (match, y) {
return 'พ.ศ. ' + (parseInt(y) + 543);
}
}
}
}
}
}
}
}
}
}
});
//test
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'emoticons': {
'type': 'toolbar', // Can also be 'booklet'
'label': 'Emoticons',
'groups': {
'faces': {
'label': 'Faces',
'tools': {
'smile': {
label: 'Smile!', // or use labelMsg for a localized label, see above
type: 'button',
icon: '//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png',
}
}
}
}
},
},
}
}
}
}
}
}
});
});
function searchEng(title) {
$.get('https://en.wikipedia.org/w/api.php', {
action: 'query',
prop: 'langlinks',
titles: title,
lllang: 'th',
format: 'json',
origin: location.origin
}, function (data) {
var langdata = Object.values(data.query.pages)[0];
if (langdata.langlinks) {
createAnchor();
console.log(langdata.langlinks[0]['*']);
$('#anchor').html('<div style="float:left">Wikipedia Search:</div><textarea id="anchorbox" style="display:inline;float:left;width:200px;resize:none"></textarea>');
$('#anchorbox').val(langdata.langlinks[0]['*']);
var selsave = saveSelection('#wpTextbox1');
document.getElementById('anchorbox').select();
document.execCommand('copy');
restoreSelection(selsave, '#wpTextbox1');
} else {
mw.notify('ไม่พบ');
$('#anchor').val('Not found');
}
}
});
}
 
function saveSelection(selection) {
var sele = $(selection);
if (true) {
var exp = [];
exp[0] = sele.prop('selectionStart');
exp[1] = sele.prop('selectionEnd');
console.log(exp);
return exp;
} else {
console.log('not select');
return [0, 0];
}
}
 
function restoreSelection(selection, ele) {
if (selection !== [0, 0]) {
var sele = $(ele);
sele.focus();
sele.prop('selectionStart', selection[0]);
sele.prop('selectionEnd', selection[1]);
console.log(selection);
}
}