User:Quarl/userscript.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:Quarl/userscript. |
// User:Quarl/userscript.js - utilities to help develop user scripts
// - adds "raw" tab to user script pages
// - automatically refreshes the raw version when you save a user script page
// requires addlilink.js, get_page_name.js
// quarl 2006-01-10 initial version
function userscriptMakeUrl(pagename) {
pagename = escape(pagename.replace(' ','_'));
return 'http://en.wikipedia.org/w/index.php?title=' + pagename + '&action=raw&ctype=text/javascript&dontcountme=s';
}
function addTab_UserScriptRaw() {
var pname = getPname();
if (pname.match(/[.]js$/)) {
addTab(userscriptMakeUrl(pname), 'raw', 'ca-raw', "Show raw version of user script");
}
}
function addTab_UserScriptRefresh() {
var pname = getPname();
if (pname.match(/[.]js$/)) {
addTab('javascript:userscript_DoRefresh()', 'refresh', 'ca-refresh', "Force browser to refresh this script");
}
}
/*function userscript_AutoRefresh_Load() {
if (get_query_vars()['refresh'] == 'userscript') {
userscript_DoRefresh();
}
userscript_ModifyPageRefreshOnSave();
}*/
function userscript_DoRefresh() {
var url = userscriptMakeUrl(getPname());
window.frames['userscript_refresher'].window.location.replace(url);
}
/*function userscript_ModifyPageRefreshOnSave() {
document.editform.action += '&refresh=userscript';
}*/
addOnloadHook(addTab_UserScriptRaw);
addOnloadHook(addTab_UserScriptRefresh);
//addOnloadHook(userscript_AutoRefresh_Load);
document.write('
<div style="position:absolute;left:0px;top:0px;visibility:hidden;" id="hidden_userscript_iframe_div">
<iframe src="about:blank" height="0" width="0" name="userscript_refresher"></iframe>
</div>');