Board Thread:Support Requests - Getting Technical/@comment-24014422-20161103104144

About two weeks ago, I stumbled upon a JS code that allows for placing the Talk Template at the head of a talk page by just creating a new talk page, or editing a talk page that doesn't have one automatically. However, the code only works perfectly if the (Rich-text editor) is disabled, or the code will always repeat adding the template to a talk page even if it has one already once a user edits a talk page.

The JS code that allows for that is:

/** * Add Template:Talk if it's not there. */ var mNamespaceNumber = mw.config.get('wgNamespaceNumber'), mAction         = mw.util.getParamValue('action'), mSection        = mw.util.getParamValue('section'); if (mNamespaceNumber % 2 == 1 && mNamespaceNumber != 3 && !mSection && mAction !== 'submit') { var vText = $('#wpTextbox1').val.replace(/{\{[Tt]alk/, '{\{Talk'); if (!vText.match('{\{Talk') && !vText.match('{\{Delete')) { $('#wpTextbox1').val('{\{Talk}}\n\n' + vText); } } And I want to ask for a help on how to alter it in order to make it take into account the Rich-Text editor, and not to repeat placing the template after every edit on a talk page. 