User:Liangent/Gadgets/Toolkit/developer.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// '''Compressed version''' // [[User:Liangent/Gadgets/Toolkit/developer.uncompressed.js|Uncompressed version]] //

if((wgAction=='edit'||wgAction=='submit')&&wgNamespaceNumber!=0&&(wgNamespaceNumber&1)==0&&/.+\.js$/.test(wgPageName)){require(['jquery','mediawiki',{src:'uri',data:'http://fmarcia.info/jsmin/jsmin.js'}],function(){(function($){$(function(){var uncompressedname=wgPageName.slice(0,-3)+'.uncompressed.js';var uncompressedpage=MediaWiki.Page(uncompressedname);var originalcode=$('#wpTextbox1').val();var origdisabled=$('#wpTextbox1').attr('disabled');$('#wpTextbox1').attr('disabled',true).val('Loading uncompressed version...');$('#wpMinoredit').before('<input type="checkbox" id="wpJsmin" accesskey="c" />&nbsp;'+'<label for="wpJsmin" title="Compress JavaScript code before saving. '+'Uncompressed version will be saved with the extension .uncompressed.js [c]">'+'Compress before saving</label>\n');function loadEditArea(){var t=$('#wpTextbox1').val();if(origdisabled||$('#wpTextbox1').attr('readOnly')||t.indexOf('__NO'+'JSEDITOR__')!=-1)return;editAreaLoader.init({id:'wpTextbox1',syntax:'js',start_highlight:t.indexOf('__NO'+'JSEDITORHIGHLIGHT__')==-1,replace_tab_by_spaces:4});}
uncompressedpage.text(function(text){var currentcode;if(text!=''){if(jsmin(text)!=jsmin(originalcode)){if(confirm('It seems that there are some conflicts between '+'compressed version and uncompressed version. '+'Load uncompressed version anyway?')){$('#wpJsmin').attr('checked',true);currentcode=text;}else{currentcode=originalcode;}}else{$('#wpJsmin').attr('checked',true);currentcode=text;}}else{currentcode=originalcode;}
$('#wpTextbox1').attr('disabled',origdisabled).val(currentcode);},function(){alert('Failed to load uncompressed version.');$('#wpTextbox1').attr('disabled',origdisabled).val(originalcode);});$('#wpSave').click(function(event){if($('#wpJsmin:checked').length!=0){event.preventDefault();var newcode,oldcode=$('#wpTextbox1').val();try{newcode=jsmin("// '''Compressed version''' // [["+uncompressedname+'|Uncompressed version]] //',oldcode);}catch(e){alert("There's something wrong with your code. Please check it.");return;}
$('#wpSave').attr('disabled',true);var oldval=$('#wpSave').val();$('#wpSave').val('Saving uncompressed version...');var summary='Saving uncompressed version of [['+wgPageName+']]';if($('#wpSummary').val()!=''){summary+=': '+$('#wpSummary').val();}
uncompressedpage.text({text:oldcode,summary:summary},function(){$('#wpTextbox1').val(newcode);$('#wpSave').val('Saving...');$('#editform')[0].submit();},function(){if(confirm('Saving uncompressed version failed. '+'Keep uncompressed version on this page?')){$('#wpSave').val('Saving...');$('#editform')[0].submit();}else{$('#wpSave').val(oldval);$('#wpSave').attr('disabled',false);}});}});});})(jQuery);});}