User:Enterprisey/CustomSummaryPresets.js
Appearance
From Wikipedia, the free encyclopedia
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.
This code will be executed when previewing this page.
This user script seems to have a documentation page at User:Enterprisey/CustomSummaryPresets.
/* * CustomSummaryPresets.js * * Displays a highly configurable menu of custom edit summaries. * See documentation at [[User:Enterprisey/CustomSummaryPresets]]. * * Mostly copied on 2018年07月24日 from https://en.wikipedia.org/w/index.php?title=&oldid=807346245, * some code also taken from https://en.wikipedia.org/w/index.php?title=&oldid=498931785 * * Older history: * Imported as of 09/06/2011 from [[User:ErrantX/defaultsummaries.js]] * Edited version from [[User:MC10/defaultsummaries.js]] * Implements default edit summary dropdown boxes */ var$summaryBox=$('#wpSummary'); if(typeofcustomGeneralSummaries==="undefined"){ customGeneralSummaries=[]; if(typeofcustomsum1!="undefined")customGeneralSummaries.push(customsum1); if(typeofcustomsum2!="undefined")customGeneralSummaries.push(customsum2); if(typeofcustomsum3!="undefined")customGeneralSummaries.push(customsum3); if(typeofcustomsum4!="undefined")customGeneralSummaries.push(customsum4); if(typeofcustomsum5!="undefined")customGeneralSummaries.push(customsum5); if(typeofcustomsum6!="undefined")customGeneralSummaries.push(customsum6); if(typeofcustomsum7!="undefined")customGeneralSummaries.push(customsum7); if(typeofcustomsum8!="undefined")customGeneralSummaries.push(customsum8); if(typeofcustomsum9!="undefined")customGeneralSummaries.push(customsum9); if(typeofcustomsum10!="undefined")customGeneralSummaries.push(customsum10); if(typeofcustomsum11!="undefined")customGeneralSummaries.push(customsum11); if(typeofcustomsum12!="undefined")customGeneralSummaries.push(customsum12); if(typeofcustomsum13!="undefined")customGeneralSummaries.push(customsum13); if(typeofcustomsum14!="undefined")customGeneralSummaries.push(customsum14); if(typeofcustomsum15!="undefined")customGeneralSummaries.push(customsum15); if(typeofcustomsum16!="undefined")customGeneralSummaries.push(customsum16); if(typeofcustomsum17!="undefined")customGeneralSummaries.push(customsum17); if(typeofcustomsum18!="undefined")customGeneralSummaries.push(customsum18); if(typeofcustomsum19!="undefined")customGeneralSummaries.push(customsum19); if(typeofcustomsum20!="undefined")customGeneralSummaries.push(customsum20); } functionaddOptionsToDropdown(dropdown,optionTexts){ dropdown.menu.addItems((optionTexts||[]).map(function(optionText){ returnnewOO.ui.MenuOptionWidget({label:optionText}); })); } functiononSummarySelect(option){ // Save the original value of the edit summary field vareditsummOriginalSummary=$summaryBox.val(), canned=option.getLabel(), newSummary=editsummOriginalSummary; // Append old edit summary with space, if exists, // and last character != space if(newSummary.length!==0&&newSummary.charAt(newSummary.length-1)!==' '){ newSummary+=' '; } newSummary+=canned; $summaryBox.val(newSummary).trigger('change'); } functioninsertSummaryOptions($insertBeforeThis,dropdownWidth){ // For convenience, add a dropdown box with some canned edit // summaries to the form. varnamespace=mw.config.get('wgNamespaceNumber'), dropdown=newOO.ui.DropdownWidget({ label:'Custom edit summaries – click to use' }); dropdown.$element.css('width',dropdownWidth); dropdown.menu.on('select',onSummarySelect); addOptionsToDropdown(dropdown,customGeneralSummaries); if(typeofcustomNamespaceSummaries!="undefined"&&customNamespaceSummaries[namespace+'']){ addOptionsToDropdown(dropdown,customNamespaceSummaries[namespace+'']); } $insertBeforeThis.before(dropdown.$element); } // VisualEditor mw.hook('ve.saveDialog.stateChanged').add(function(){ vartarget,$saveOptions; // .ve-init-mw-viewPageTarget-saveDialog-checkboxes if($('body').data('wppresent')){return;} $('body').data('wppresent','true'); target=ve.init.target; $saveOptions=target.saveDialog.$saveOptions; $summaryBox=target.saveDialog.editSummaryInput.$input; if(!$saveOptions.length){ return; } insertSummaryOptions($saveOptions); }); // WikiEditor (i.e. the normal wikicode editor) $.when(mw.loader.using('oojs-ui-core'),$.ready).then(function(){ var$editCheckboxes=$('.editCheckboxes'); // If we failed to find the editCheckboxes class if(!$editCheckboxes.length){ return; } insertSummaryOptions($editCheckboxes,'38%'); });