MediaWiki:Gadget-TemplateScript.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 8: Line 8:
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
pathoschild.TemplateScript.add({
pathoschild.TemplateScript.add({
name:'replace -- with —',
name:'Toggle width',
script: function(editor) {
script: function myFunction() {
editor
  var x = document.getElementsByClassName("ts-inner");
.replace(/--/g, '—')
  for (i in x) {
.appendEditSummary('replaced -- with —')
  if (x[i].style.maxWidth === "none") {
.clickDiff();
    x[i].style.maxWidth = "115em";
}
  } else {
    x[i].style.maxWidth = "none";
  }
}
}
});
});
});
});
// </nowiki>
// </nowiki>

Revision as of 16:28, 12 July 2023

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:Pathoschild/templatescript.js]]
 */
// <nowiki>
mw.config.set('userjs-templatescript', { regexEditor: false });
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
pathoschild.TemplateScript.add({
	name:'Toggle width',
	script: function myFunction() {
  var x = document.getElementsByClassName("ts-inner");
  for (i in x) {
  if (x[i].style.maxWidth === "none") {
    x[i].style.maxWidth = "115em";
  } else {
    x[i].style.maxWidth = "none";
  }
}
}
});
});
// </nowiki>