User:Rurin/timeless.js: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
mNo edit summary
mNo edit summary
 
Line 13: Line 13:
     var params = {
     var params = {
         action: 'raw',
         action: 'raw',
         title: 'MediaWiki:ProfileTags'
         title: 'User:Rurin/sandbox'
     };
     };



Latest revision as of 11:24, 26 February 2024

/* ############################################ */
/* ###              ProfileTags             ### */
/* ###             User:RurinGas            ### */
/* ############################################ */

$(function ($) {
    'use strict';

    var conf = mw.config.get([
        'wgTitle'
    ]);

    var params = {
        action: 'raw',
        title: 'User:Rurin/sandbox'
    };

    $.get(mw.util.wikiScript(), params, function (data) {
        if (!data.length) {
            return;
        }

        var escapeRegExp = mw.util.escapeRegExp || (mw.RegExp || {}).escape,
            user = escapeRegExp(conf.wgTitle),
            re = new RegExp('(?:^|\\n)\\s*' + user + '\\s*\\|\\s*(.*?)\\s*(?:\\n|$)'),
            match = re.exec(data);

        if (match !== null) {
            var profileTags = match[1].split(/\s*,\s*/);
            insertTextString(profileTags);
        }
    });

    function insertTextString(profileTags) {
    	var tardisProfileTag = document.createElement("p");
    	tardisProfileTag.id = 'tardisProfileTag';
        var textToInsert = profileTags.join(', ');
        tardisProfileTag.innerHTML = textToInsert;
        $('.mw-page-title-main').append(tardisProfileTag);
    }
});