User:Porter21/ForumTools.js

// // ============================================================ // BEGIN ForumTools // ============================================================

// Description: Improvements for DPL forum: check for signature on submission, preserve forum header // Credit:     User:Porter21

function forumTools { if (wgNamespaceNumber == 110 && (wgAction == 'edit' || wgAction == 'submit')) { // Configuration var config = window.ForumToolsConfig = $.extend(true, {        enableSigCheck: true,         forumHeaderTemplate: 'Forumheader',         forumHeaderComment: 'Please put your content under this line. Be sure to sign your edits with four tildes (~) or by using the signature button.',         userLang: true,         // English         en: {            noSig: "Please sign your edits on talk and forum pages with four tildes  or by using the signature button."         }      }, window.ForumToolsConfig || {});

// Function for multi-language support (by Daniel Friesen aka User:Dantman) function msg(name) { if ( config.userLang && wgUserLanguage in config && name in config[wgUserLanguage] ) return config[wgUserLanguage][name]; if ( wgContentLanguage in config && name in config[wgContentLanguage] ) return config[wgContentLanguage][name]; return config.en[name]; }

function checkForumPost { var threadContent = $('#wpTextbox1').val;

// No signature if (config.enableSigCheck) { var sigCount = threadContent.match(/[~]{4}/g) ? threadContent.match(/[~]{4}/g).length : 0; var sigCountHeader = config.forumHeaderComment.match(/[~]{4}/g) ? config.forumHeaderComment.match(/[~]{4}/g).length : 0;

if (sigCount <= sigCountHeader && ($('#forumtools-nosig').length == 0)) { var editToolbar = (skin == 'monobook') ? '#editOptions' : '#edit_enhancements_toolbar';

$(' ' + msg('noSig') + ' ').prependTo(editToolbar);

return false; }        }

return true; }

$('#editform').submit(checkForumPost); } }

addOnloadHook(forumTools);

// ============================================================ // END ForumTools // ============================================================ //