משתמש:1Or/sandbox.js
הערה: לאחר הפרסום, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.
- פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload) או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
- גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
- אדג': להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh) או ללחוץ על צירוף המקשים Ctrl-F5.
function tagUserScript (userName, displayName) {
var newDisplay = "";
if (userName == displayName) {
newDisplay = "{{א|" + displayName + "}}";
} else {
newDisplay = "{{א|" + userName + "|" + displayName + "}}";
}
$( '#wpTextbox1' ).textSelection('encapsulateSelection',{
pre: '',
peri: newDisplay,
post: ''
});
}
$( function() {
const regexp = /\[\[(?:משתמש|מש|User)\:(.+?)\|(.+?)\]\]/g;
const textbox = $("#wpTextbox1")[0];
if ( !textbox ) {
return;
}
const str = textbox.innerHTML;
const arr = [...str.matchAll(regexp)];
function getUniqueListBy(arr, key) {
return [...new Map(arr.map(item => [item[key], item])).values()];
}
content = "";
function listOfNames(array) {
for (i=0; i < array.length; i++) {
content = content + '<div onclick="tagUserScript(' + "'" + array[i][1] + "', '" + array[i][2] + "'" + ')">' + array[i][2] + "<\div> <br \>";
}
}
firstList = getUniqueListBy(arr, [1]);
listOfNames(firstList);
function openDialog( title, content, raw ) {
mw.loader.using( [ 'jquery.ui', 'mediawiki.api' ] ).then( function() {
var dialog,
api = new mw.Api({ ajax: { cache: false } }),
inside = raw
? $( '<textarea>' )
.attr( { raws: 25, resize: true } )
.val( content )
.css( { 'width': $('body').width() * (window.my_93_width || 0.8),
'height' : $('body').height() * (window.my_93_height || 0.8), overflow: 'auto' } )
: $( '<div>' )
.css( { 'max-width': $('body').width() * 0.9, 'max-height' : $('body').height() * 0.8,
overflow: 'auto' } )
.append( content ),
button = [ {text: 'סגירה', click: doSaveClose} ];
function doSaveClose() {
dialog.dialog( 'close' );
}
dialog = $( '<div>' )
.dialog( {
title: title,
width: 'auto',
height: 'auto',
position: [$('body').width() * 0.05, $('body').height() * 0.05],
buttons: button
} )
.append( inside );
} );
}
if (mw.config.get('wgAction') == 'edit' || mw.config.get('wgAction') == 'submit') {
$('#wpTextbox1').before(
'[',
$('<a>')
.text('תיוג משתמש')
.click(sandbox),
']'
);
}
function sandbox() {
openDialog("לחץ על המשתמש שאתה רוצה לתייג", content);
}
});