Misplaced Pages

User:Frietjes/TT.js: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:Frietjes Browse history interactively← Previous editNext edit →Content deleted Content added
Revision as of 14:49, 12 September 2012 view sourceFrietjes (talk | contribs)Autopatrolled, Extended confirmed users, Template editors1,000,827 editsm fix issue with not seeing {{collapsible option|state=foo}}← Previous edit Revision as of 15:47, 10 November 2012 view source Frietjes (talk | contribs)Autopatrolled, Extended confirmed users, Template editors1,000,827 edits add redirect, CO, to collapsible optionNext edit →
Line 25: Line 25:
// add collapsible option if it's not there and the state parameter is there // add collapsible option if it's not there and the state parameter is there
if( myContent.search(/\{\{\{*state/g) >= 0 ) { if( myContent.search(/\{\{\{*state/g) >= 0 ) {
if( myContent.search(/\{\{*ollapsible+option*(?:\||\}\})/g) < 0 ) { if( myContent.search(/\{\{*(?:ollapsible+option|O])*(?:\||\}\})/g) < 0 ) {
myContent = myContent.replace(/(<*noinclude*>)*\n/i, '$1\n{{collapsible option}}\n'); myContent = myContent.replace(/(<*noinclude*>)*\n/i, '$1\n{{collapsible option}}\n');
} }
if( myContent.search(/\{\{*ollapsible+option*(?:\||\}\})/g) < 0 ) { if( myContent.search(/\{\{*(?:ollapsible+option|O])*(?:\||\}\})/g) < 0 ) {
myContent = myContent.replace(/(<*noinclude*>)*/i, '$1\n{{collapsible option}}\n'); myContent = myContent.replace(/(<*noinclude*>)*/i, '$1\n{{collapsible option}}\n');
} }

Revision as of 15:47, 10 November 2012

if(wgNamespaceNumber != -1) addOnloadHook(TTscriptButton)
function TTscriptButton() {
  addPortletLink('p-tb','javascript:collapsibleoptionfunction()','Collapsible option','t-clps');
}

function collapsibleoptionfunction()
{
  var myContent = document.getElementById('wpTextbox1').value;

  // add state parameter if it's not there
  if( myContent.search(/\{\{\{*state/g) < 0 ) {
    myContent = myContent.replace(/(\|*state*=)*(*)()/, '$1 \{\{\{state|$2\}\}\}$3');
  }
  if( myContent.search(/\{\{\{*state/g) < 0 ) {
    myContent = myContent.replace(/(\|*?*)(title*=*)/, '$1$2$1state = \{\{\{state|autocollapse\}\}\}|\n');
    myContent = myContent.replace(/(\|*state*=*\{\{\{state\|*\}\}\})*\|*(*\|)/, '$1$2');
    myContent = myContent.replace(/(\|)*()*\|*?*(state*=*\{\{\{state\|*\}\}\})/, '$1$2$3');
  }
  if( myContent.search(/\{\{\{*state/g) < 0 ) {
    myContent = myContent.replace(/(\|*?*)(name*=*)/, '$1$2$1state = \{\{\{state|autocollapse\}\}\}|\n');
    myContent = myContent.replace(/(\|*state*=*\{\{\{state\|*\}\}\})*\|*(*\|)/, '$1$2');
    myContent = myContent.replace(/(\|)*()*\|*?*(state*=*\{\{\{state\|*\}\}\})/, '$1$2$3');
  }

  // add collapsible option if it's not there and the state parameter is there
  if( myContent.search(/\{\{\{*state/g) >= 0 ) {
    if( myContent.search(/\{\{*(?:ollapsible+option|O])*(?:\||\}\})/g) < 0 ) {
      myContent = myContent.replace(/(<*noinclude*>)*\n/i, '$1\n{{collapsible option}}\n');
    }
    if( myContent.search(/\{\{*(?:ollapsible+option|O])*(?:\||\}\})/g) < 0 ) {
      myContent = myContent.replace(/(<*noinclude*>)*/i, '$1\n{{collapsible option}}\n');
    }
  }

  // too much whitespace
  myContent = myContent.replace(/(\{\{\{*state\|)+(*)*(\}\}\})/g, '$1$2$3');
  myContent = myContent.replace(/(\{\{\{*state\|)*(*)+(\}\}\})/g, '$1$2$3');

  // includeonly with collapsed
  myContent = myContent.replace(/(\|*state*=*\{\{\{state)\|collapsed(\}\}\})/, '$1<includeonly>|collapsed</includeonly>$2');
  myContent = myContent.replace(/(\|*state*=*\{\{\{state)\|<*includeonly*>*collapsed*<*\/*includeonly*>(\}\}\})/i, '$1<includeonly>|collapsed</includeonly>$2');

  // includeonly only half inside state
  myContent = myContent.replace(/(\{\{\{state*\|*)(<\/includeonly>)(*\}\}\})/, '$1$3$2');
  myContent = myContent.replace(/(\{\{\{state*\|*)(<includeonly>)(*\}\}\})/, '$2$1$3');

  if(document.getElementById('wpTextbox1').value != myContent) {
    document.getElementById('wpTextbox1').value = myContent;
    document.getElementById('wpSummary').value  = 'adding \{\{collapsible option\}\} and/or \{\{\{state\}\}\}';
  }
}