User:קיפודנחש/common.js/personalScript.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:קיפודנחש/common.js/personalScript. |
// <source lang="javascript">
// script for script developers: allows you to easilly set and clear personal script to be included
// on startup.
mw.loader.using( 'mediawiki.util' )
.done(function() {
var lsKey = 'personalScript';
function getTop() {return ((lsKey in localStorage) && localStorage[lsKey].split('\n')[0]) || ''}
function allScripts() {
return (localStorage[lsKey] || '').split('\n');
}
function setScript(script) {
var ls = localStorage[lsKey];
if (lsKey in localStorage)
{
var
lsa = allScripts(),
ind = $.inArray(script, lsa);
if (ind < 0)
ind = 10;
if (! lsa[0])
lsa.shift(); // if first is empty, remove it.
lsa.splice(ind, 1); // remove current if exists, or last if length >= 10
lsa.unshift(script);
localStorage[lsKey] = lsa.join('\n');
} else
localStorage[lsKey] = script;
loadScript(script);
}
function loadScript(s) {
if (!s)
return;
try {
var isCss = /\.css$/i.test(s);
if (/\/\//.test(s))
mw.loader.load(s, isCss ? 'text/css' : 'text/javascript');
else
return isCss ? importStylesheet(s) : importScript(s);
} catch(e) {}
}
function mySetSpecialScript() {
mw.loader.using('jquery.ui', function() {
var
inputBox = $('<input>').val(getTop()).css({width: '22em', direction: 'ltr'}),
selector = $('<select>')
.css({direction: 'ltr'})
.change(function() {inputBox.val(this.value)});
$.each(allScripts(), function(ind, item) {
selector.append($('<option>', {value: item, text: item.substr(0, 80) + (item.length > 80 ? '...':'')}));
});
$('<div>')
.css({direction: 'ltr'})
.dialog(
{title: 'Personal script',
modal: true,
position: [60, 60],
buttons: [
{text: 'OK', click: function() {
setScript(inputBox.val());
$(this).dialog('close');
}},
{text: 'Cancel', click: function() {
setScript('');
$(this).dialog('close');
}}]
})
.append(inputBox)
.append($('<p>'))
.append(selector)
.dialog('option', 'height', 'auto');
});
}
loadScript(getTop());
mw.util.addPortletLink('p-cactions', '#noAnchor', 'Personal script').onclick = mySetSpecialScript;
if ($.inArray( mw.config.get('wgAction'), ['edit', 'submit']) + 1)
importScript('User:קיפודנחש/TemplateParamWizard.js');
});
// </source>