MediaWiki:TalkButton/code.js

// Talk page button // Created by Lil' Miss Rarity // MIT OS License $(function($, mw, doc) {   var i18n = {        'en': 'Talk'    };    function getNumberOfHeaders($, page, bubble) {        $.ajax({ url: '/wiki/Talk:' + page + '?action=raw', type: 'GET', success: function(data) { var headers = data.match(/==[^=]*==/g); bubble.textContent = headers.length; },           error: function(err, status) { console.log('FAILED ' + err + ': ' + status); bubble.textContent = '0'; }       });    }    if (mw.config.get('wgNamespaceNumber') === 0) {        var talk_button = doc.createElement('a');            talk_button.setAttribute('accesskey', 't');            talk_button.setAttribute('class', 'wikia-button comments secondary talk');            talk_button.setAttribute('href', '/wiki/Talk:' + mw.config.get('wgPageName'));            talk_button.textContent = (i18n[mw.config.get('wgUserLanguage')] || 'Talk');        var talk_bubble = doc.createElement('span');            talk_bubble.setAttribute('class', 'commentsbubble');        getNumberOfHeaders($, mw.config.get('wgPageName'), talk_bubble);        talk_button.appendChild(talk_bubble);        doc.getElementById('WikiaPageHeader').appendChild(talk_button);    } }($, mw, document));