ผลต่างระหว่างรุ่นของ "วิกิพีเดีย:สคริปต์ผู้ใช้"

เนื้อหาที่ลบ เนื้อหาที่เพิ่ม
Jutiphan (คุย | ส่วนร่วม)
Ps (คุย | ส่วนร่วม)
จัดรูปแบบ +เก็บกวาดด้วยสคริปต์จัดให้
บรรทัด 1:
<!--nofixbot-->
{{เว็บย่อ|WP:US}}
'''สคริปต์ผู้ใช้''' (user scripts) เป็นโค้ดภาษา[[จาวาสคริปต์]] ที่ใช้ในการตกแต่ง เปลี่ยนแปลง หรือเพิ่มเติมความสามารถ รูปแบบวิกิพีเดียสำหรับผู้ใช้ดังกล่าว โดยปกติจะใส่ในหน้า monobook.js ของผู้ใช้ ซึ่งความสามารถส่วนนี้สำหรับผู้ที่เป็นสมาชิกวิกิพีเดียเท่านั้น.
 
เส้น 12 ⟶ 13:
 
 
== ตัวอย่างสคริปต์ จากผู้ใช้งานคนอื่น ==
* [[ผู้ใช้:AkiAkira/monobook.js]]
* [[ผู้ใช้:Manop/monobook.js]]
เส้น 37 ⟶ 38:
<pre>
/* <nowiki> */
function addTab(url, name, id, title, key) {
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul') [0];
addlilink(tabs, url, name, id, title, key) ;
}
/* </nowiki> */
เส้น 47 ⟶ 48:
<pre>
/* <nowiki> */
function addlilink(tabs, url, name, id, title, key) {
var na = document.createElement('a') ;
na.href = url;
na.appendChild(document.createTextNode(name)) ;
var li = document.createElement('li') ;
if(id) li.id = id;
li.appendChild(na) ;
tabs.appendChild(li) ;
na.accesskey = key;
var pref = 'alt-';
if(((clientPC.indexOf('AppleWebKit') !=-1) && (clientPC.indexOf('spoofer') ==-1)) || navigator.userAgent.toLowerCase().indexOf( 'mac' ) != -1 ) pref = 'control-';
if(clientPC.indexOf('opera') !=-1) pref = 'shift-esc-';
if(key && title) na.title = title + ' [' + pref + key + ']';
else if(title) na.title = title;
เส้น 71 ⟶ 72:
/* <nowiki> */
function getPname() {
return wgPageName.replace(/_/g, ' ') ;
}
/* </nowiki> */
</pre>
 
=== สคริปต์เฉพาะทาง ===
==== ใส่ข้อความต้องการความช่วยเหลือ ====
ใส่ข้อความต้องการความช่วยเหลือ ที่ส่วนบนของบทความ และทำการเซฟบทความทันที
เส้น 86 ⟶ 87:
document.editform.wpSummary.value = "ช่วยดูหน่อย";
document.editform.wpMinoredit.checked = true;
document.editform.submit() ;
}
 
function addQwikify() {
addTab("javascript:doQwikify() ", "ช่วย", "ca-wikify", "แจ้งว่าช่วยดูหน่อย", "") ;
akeytt() ;
}
 
if (document.title.indexOf("แก้ไข ") == 0) {
if (window.addEventListener) window.addEventListener("load", addQwikify, false) ;
else if (window.attachEvent) window.attachEvent("onload", addQwikify) ;
}
/* </nowiki> */
เส้น 118 ⟶ 119:
document.editform.wpTextbox1.value = "{{โฆษณา}}\n\n" + document.editform.wpTextbox1.value;
document.editform.wpSummary.value = "แจ้งโฆษณา";
document.editform.submit() ;
return;
}
addTab("javascript:doAdvert() ", "แจ้งโฆษณา", "ca-advert", "คำสั่งแจ้งโฆษณา", "") ;
}) ;
function doAdvert() {
//edit page
var title = document.title.substr(0, document.title.lastIndexOf(' - วิกิพีเดีย')) ;
location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=advert") ;
}
/* </nowiki> */
เส้น 149 ⟶ 150:
document.editform.wpTextbox1.value = "{{ลบ}}\n\n" + document.editform.wpTextbox1.value;
document.editform.wpSummary.value = "แจ้งลบ";
document.editform.submit() ;
return;
}
addTab("javascript:doQsd() ", "แจ้งลบ", "ca-sd", "คำสั่งแจ้งลบ", "") ;
}) ;
function doQsd() {
//edit page
var title = document.title.substr(0, document.title.lastIndexOf(' - วิกิพีเดีย')) ;
location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=speedydel") ;
}
/* </nowiki> */
</pre>
 
==== แจ้งละเมิดลิขสิทธิ์ ====
ใส่กล่องข้อความแจ้งละเมิดลิขสิทธิ์พร้อมเติมวันที่ในเวลาไทยให้โดยอัตโนมัติ ที่ส่วนบนของบทความ
<pre>
// ========== แจ้งละเมิดลิขสิทธิ์ (รุ่นใส่เวลาไทย) ==========
function doCopyViolation() {
var currentDay = new Date() ;
var thaiDate = new Date(currentDay.getTime() + 25200000) ; //7*1000*60*60
var month = thaiDate.getUTCMonth() +1;
var year = thaiDate.getUTCFullYear() +543;
 
document.editform.wpTextbox1.value = "{{ละเมิดลิขสิทธิ์ | url= | วันที่=" + thaiDate.getUTCDate()
เส้น 178 ⟶ 179:
}
function addCopyViolation() {
addTab("javascript:doCopyViolation() ", "ละเมิด", "ca-vio", "แจ้งละเมิดลิขสิทธิ์", "") ;
akeytt() ;
}
 
if (document.title.indexOf("แก้ไข ") == 0) {
if (window.addEventListener) window.addEventListener("load", addCopyViolation, false) ;
else if (window.attachEvent) window.attachEvent("onload", addCopyViolation) ;
}
</pre>
เส้น 195 ⟶ 196:
function doCleanupTag() {
text = document.editform.wpTextbox1.value;
text = replace(text,'[[Category:','[[หมวดหมู่:') ;
text = replace(text,'[[category:','[[หมวดหมู่:') ;
text = replace(text,'[[Image:','[[ภาพ:') ;
text = replace(text,'[[image:','[[ภาพ:') ;
text = replace(text,'แหล่งอ้างอิง','อ้างอิง') ;
text = replace(text,'หนังสืออ้างอิง','อ้างอิง') ;
text = replace(text,'เอกสารอ้างอิง','อ้างอิง') ;
text = replace(text,'แหล่งข้อมูลอ้างอิง','อ้างอิง') ;
text = replace(text,'หัวข้ออื่นที่เกี่ยวข้อง','ดูเพิ่ม') ;
text = replace(text,'ดูเพิ่มที่','ดูเพิ่ม') ;
text = replace(text,'เว็บไซต์อื่น','แหล่งข้อมูลอื่น') ;
text = replace(text,'เว็บไซต์ภายนอก','แหล่งข้อมูลอื่น') ;
text = replace(text,'โยงภายนอก','แหล่งข้อมูลอื่น') ;
text = replace(text,'ลิงก์ภายนอก','แหล่งข้อมูลอื่น') ;
text = replace(text,'ลิงค์ภายนอก','แหล่งข้อมูลอื่น') ;
text = replace(text,'Link ภายนอก','แหล่งข้อมูลอื่น') ;
text = replace(text,'ข้อมูลภายนอก','แหล่งข้อมูลอื่น') ;
 
text = replace(text,'*[','* [') ;
document.editform.wpTextbox1.value = text;
document.editform.wpSummary.value = "แก้ไข +เก็บกวาด";
เส้น 219 ⟶ 220:
 
function addCleanupTag() {
addTab("javascript:doCleanupTag() ", "เก็บกวาด", "ca-taclt", "เก็บกวาด", "") ;
}
 
if (document.title.indexOf("แก้ไข ") == 0) {
if (window.addEventListener) window.addEventListener("load", addCleanupTag, false) ;
else if (window.attachEvent) window.attachEvent("onload", addCleanupTag) ;
}
/* </nowiki> */
</pre>
 
==== สลับเปลี่ยนระหว่างตัวเลขอารบิกกับเลขไทย ====
<pre>
/* <nowiki> */
เส้น 239 ⟶ 240:
if ((strLength == 0) || (txtLength == 0)) return string;
 
var i = string.indexOf(text) ;
if ((!i) && (text != string.substring(0,txtLength))) return string;
if (i == -1) return string;
เส้น 246 ⟶ 247:
 
if (i+txtLength < strLength)
newstr += replace(string.substring(i+txtLength,strLength) ,text,by) ;
 
return newstr;
เส้น 255 ⟶ 256:
function doConvertNumber() {
text = document.editform.wpTextbox1.value;
text = replace(text,'๑','1') ;
text = replace(text,'๒','2') ;
text = replace(text,'๓','3') ;
text = replace(text,'๔','4') ;
text = replace(text,'๕','5') ;
text = replace(text,'๖','6') ;
text = replace(text,'๗','7') ;
text = replace(text,'๘','8') ;
text = replace(text,'๙','9') ;
text = replace(text,'๐','0') ;
document.editform.wpTextbox1.value = text;
document.editform.wpSummary.value = "เปลี่ยนเลขไทยเป็นอารบิก";
เส้น 270 ⟶ 271:
 
function addConvertNumber() {
addTab("javascript:doConvertNumber() ", "๒ ->2", "ca-tanum", "เปลี่ยนเลขไทยเป็นอารบิก", "") ;
akeytt() ;
}
 
if (document.title.indexOf("แก้ไข ") == 0) {
if (window.addEventListener) window.addEventListener("load", addConvertNumber, false) ;
else if (window.attachEvent) window.attachEvent("onload", addConvertNumber) ;
}
 
เส้น 283 ⟶ 284:
function doConvertToThaiNumber() {
text = document.editform.wpTextbox1.value;
text = replace(text,'1','๑') ;
text = replace(text,'2','๒') ;
text = replace(text,'3','๓') ;
text = replace(text,'4','๔') ;
text = replace(text,'5','๕') ;
text = replace(text,'6','๖') ;
text = replace(text,'7','๗') ;
text = replace(text,'8','๘') ;
text = replace(text,'9','๙') ;
text = replace(text,'0','๐') ;
document.editform.wpTextbox1.value = text;
document.editform.wpSummary.value = "เปลี่ยนเลขอารบิกเป็นไทย";
}
function addConvertToThaiNumber() {
addTab("javascript:doConvertToThaiNumber() ", "2 ->๒", "ca-atnum", "เปลี่ยนเลขอารบิกเป็นไทย", "") ;
akeytt() ;
}
 
if (document.title.indexOf("แก้ไข ") == 0) {
if (window.addEventListener) window.addEventListener("load", addConvertToThaiNumber, false) ;
else if (window.attachEvent) window.attachEvent("onload", addConvertToThaiNumber) ;
}
/* </nowiki> */
เส้น 315 ⟶ 316:
ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page'];
if (!document.getElementById) return;
x = document.getElementById('ca-edit') ;
if(!x) return;
y = document.createElement('LI') ;
y.id = 'ca-edit-0';
if (x.className == 'selected') {
เส้น 337 ⟶ 338:
x.className = 'istalk';
}
z = document.createElement('A') ;
if (x.children) {
z.href = x.children[0].href + '&section=0';
z.appendChild(document.createTextNode('0')) ;
y.appendChild(z) ;
document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling) ;
} else {
z.href = x.childNodes[0].href + '&section=0';
z.appendChild(document.createTextNode('0')) ;
y.appendChild(z) ;
document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling) ;
}
}
 
if (document.title.indexOf("Editing ") == -1) {
if (window.addEventListener) window.addEventListener("load", addEditSection0, false) ;
else if (window.attachEvent) window.attachEvent("onload", addEditSection0) ;
}
 
เส้น 369 ⟶ 370:
 
function addLastDiff() {
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul') [0];
var l=addlilink(tabs, "javascript:doLastDiff() ", 'ล่าสุด', '') ;
l.lastChild.title="ดูความแตกต่างล่าสุด";
}
เส้น 376 ⟶ 377:
if (document.title.indexOf("แก้ไข") == -1) {
if(wgCanonicalNamespace.indexOf("Special") == -1) {
if (window.addEventListener) window.addEventListener("load", addLastDiff, false) ;
else if (window.attachEvent) window.attachEvent("onload", addLastDiff) ;
}
}