MediaWiki:Wikia.js

/* */ //- //All junk needed for the interactive tutorial //- var steps = [[''],       '.wds-global-navigation__user-menu.wds-dropdown, a.wds-global-navigation__dropdown-link[data-tracking-label="account.preferences"]',        '.WikiaPageContentWrapper header#WikiHeader div.buttons nav.wikia-menu-button.contribute.secondary.combined, #WikiHeader div.buttons nav.wikia-menu-button.contribute.secondary.combined ul li a.createpage, #wpCreatePageDialogTitle, .buttons button[data-event="create"]',        '.editpage-widemode-trigger',        '.module_templates h3, #stdSummaries',        '.module_insert h3, .EditPage .cke_button > a[title="Convert Photo"]',        '.module_insert h3, .EditPage .cke_button > a.RTEImageButton, #ImageUploadUpload td h1 div, input#ImageUploadName, select#ImageUploadLicense, input[value="Add photo"]',        '.module_insert h3, .EditPage .cke_button > a[id="formatter"], #formatwindow input, #formatwindow textarea',        '.module_insert h3, .EditPage .cke_button > a.tutorialicon, .tutorialicon, .tutorialloader .tutorialhighlight',        '#EditPageEditNotice .mw-editnotice > center > div > p, #cke_toolbar_source_1, #cke_toolbar_source_1 a.expand, #editpage-specialchars',        '.module.module_page_controls .module_content'    ] var tutorialtext = ["Welcome to the Utaite Wiki interactive tutorial! Follow the highlighted areas and get to know how to edit on this wiki! Want to cancel the tutorial? simply press the Tutorial button again to turn off the tutorial, but be sure to watch the whole tutorial if you don't know how to edit!", "Before we start editing, have you set your editor to Source editor in the preferences? If no, please do so by following the blue highlights, and continue to the Editing tab, and set your preferred editor to Source editor!", "Your editor is all set? perfect! Not let's create a page! Follow the instructions to create the page (or skip this if you're already on the editing page ^^)", "This is the editor you will be editing in. But no worries, we will be going over the features this editor has! First of all, is your siderail expanded? If no, do so to see what's inside!", "The first feature to help you editing is the Template section! Navigate to the dropdown and select the preload you want (for example the --Singer preload)! You'll see the preload loads directly into the editing area!", "Next, look at the Add features and media section. If you ever need to upload an image, but it's not in .png format, you can just use this link to get a decent converter (if you don't have one)", "Now that you know how to convert pictures, let's upload some! Be sure to upload in .png, give the picture a good, descriptive name, and categorize/license it, depending on what kind of image it is!", "The next useful feature is this formatter. You will need this for the List of Covered Songs section on Singer pages, as it will automatically get all the items formatted. So you'll just have to copy and paste the list and do minor formatting and such. Try it out! Click the button to hide the formatter again", "If you're unsure, be sure to read the tutorial! You don't need to leave the editing page to do so. In the siderail click the Tutorial button, or above the editor, click the >>Click here to load tutorial<< and use the content box as well as Ctrl + F to search for words (e.g. template fields) and to navigate the tutorial easily! But try to at least read the first few sections before starting to edit, to get acquainted to the wiki syntax! To hide the tutorial again, just click the button again", "So sometimes you may have to insert special characters. Check out these characters to see if you can just insert them from there. Click one to try it out!", "That's basically it! Just go ahead and start creating the page! When you're done write an edit summary, preview your page, and publish the page!"]; var tutorialSetup = function  {    if (checkTutorialCookie != ) {        $('.tutorialButton').html("Turn off interactive Tutorial");        checkTutorial;    } } function checkTutorialCookie {    var name = "tutorial=";    var decodedCookie = decodeURIComponent(document.cookie);    var ca = decodedCookie.split(';');    for (var i = 0; i < ca.length; i++) {        var c = ca[i];        while (c.charAt(0) == ' ') {            c = c.substring(1);        }        if (c.indexOf(name) == 0) {            return c.substring(name.length, c.length);        }    }    return ; } function setTutorialCookie(text) {    document.cookie = "tutorial=" + text + ";path=/;domain=utaite.wikia.com"; } function deleteTutorialCookie {    setTutorialCookie(); } var tutorialButton = function  {    $('.tutorialButton').click(function  {            if (checkTutorialCookie != ) {                deleteTutorialCookie;                $("#tutorialstyle").remove;                $('.tutorialButton').html("Turn on interactive Tutorial");                $('.tutorialoverlay').remove;            }            else {                setTutorialCookie("0");                $('.tutorialButton').html("Turn off interactive Tutorial");                checkTutorial;            }        }    ); } function checkTutorial {    $('#WikiaPage').prepend("  Click here if you want the next step  ");    var currstep = checkTutorialCookie;    console.log(checkTutorialCookie);    $('.tutorialoverlaytext').html(tutorialtext[currstep]);    $(' ' + steps[currstep] + '{box-shadow: inset 0 0 2px 2px #0099ff, 0 0 4px 4px #0099ff !important} ').appendTo('head');    $('.tutorialoverlaybutton').click(function  {        $("#tutorialstyle").remove;        currstep++;        console.log(checkTutorialCookie);        if (currstep>=steps.length) {            deleteTutorialCookie;            $('.tutorialButton').html("Turn on interactive Tutorial");            $('.tutorialoverlay').remove;        } else{            setTutorialCookie(currstep);            $('.tutorialoverlaytext').html(tutorialtext[currstep]);            $(' ' + steps[currstep] + '{box-shadow: inset 0 0 2px 2px #0099ff, 0 0 4px 4px #0099ff !important} ').appendTo('head');        }    }) } tutorialSetup; tutorialButton; //- //get content of the tutorial page //- var tutorial; var gettutorial = function  {    $.ajax({        url: 'http://utaite.wikia.com/wiki/Utaite_Wiki:Tutorial',        success: function (html) {            tutorial = ' ' + $(html).find('#mw-content-text').html + ' ';        }    }); }; gettutorial;

//- /* Loads the current source of the page "pagename" (as stored in the database) and inserts it at the cursor position */ //- function doPreload(pagename) { var loader = new ContentLoader; loader.callback = onPreloadArrival; loader.send('/index.php?title=' + pagename + '&action=raw&ctype=text/plain'); }

function insertAtCursor(myField, myValue) { //IE support if (document.selection) { myField.focus; sel = document.selection.createRange; sel.text = myValue; }   //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); }   else { myField.value += myValue; } } /* end preload code */

/* Template Preloads * Original by User:Grunny * Source - w:c:starwars:MediaWiki:Wikia.js * Altered to replace Wiki's template preloads by runescape wiki */ function customPreloadTemplates {

if (( mw.config.get('wgAction') !== 'edit' && mw.config.get('wgCanonicalSpecialPageName') !== 'CreatePage' ) || !$('div.module_content').length) { return; }

var preloadOptionsHtml = '', $preloadOptionsList, preloadBaseHtml = ' Standard preloads: ' +           ' Custom preload pagename: '

$('span.cke_buttons.cke_toolbar_templates').replaceWith(preloadBaseHtml);

$.get(mw.config.get('wgScript'), {       title: 'Template:Stdpreloads',        action: 'raw',        ctype: 'text/plain'    }, function (data) {        var lines = data.split('\n');        for (var i = 0; i < lines.length; i++) {            var value = ( lines[i].indexOf('-- ') === 0 ) ? lines[i].substring(3) : "";            preloadOptionsHtml += '' + lines[i] + ' ';        }        $preloadOptionsList = $(' ').attr('id', 'stdSummaries').html(preloadOptionsHtml).change(function  { var value = $(this).val; if (value !== '') { value = 'Template:' + value + '/preload'; value = value.replace(' ', '_'); $.get(mw.config.get('wgScript'), {title: value, action: 'raw', ctype: 'text/plain'}, function (data) {

if ($('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source').length) { insertAtCursor($('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source')[0], data); } else { insertAtCursor(document.getElementById('wpTextbox1'), data); }               });            }        });

$('div#lf-preload').append($preloadOptionsList); });

$('#lf-preload-pagename-w').html(''); $('#lf-preload-button-w').html('');

} $(customPreloadTemplates);

$(function {    if (window.CKEDITOR) {        CKEDITOR.on("instanceReady", function  { $(customPreloadTemplates); });   } });

function doCustomPreloadOasis { var value = $('#lf-preload-pagename-w > input').val; value = value.replace(' ', '_'); $.get(mw.config.get('wgScript'), {title: value, action: 'raw', ctype: 'text/plain'}, function (data) {

if ($('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source').length) { insertAtCursor($('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source')[0], data); } else { insertAtCursor(document.getElementById('wpTextbox1'), data); }   }); }

//- //link to converter in editor, format, and video-> tutorial; thanks to UltimateSupreme with helping to put it for visual editors as well w:c:Thread:608344 //- $(function addfeatures {   icon = "  Convert    Format    Tutorial   ";

$('.cke_button.RTEImageButton.cke_button_big').append(icon); if (window.CKEDITOR) { CKEDITOR.on("instanceReady", function {            $(addfeatures);            formatcaller;        }); } else { formatcaller; } });

//- //Custom YT & TM player //- $(function loader {   if (document.querySelector('.ytvideo') !== null) {        load(".ytvideo", "<iframe width='300' height='200' src='http://www.youtube.com/embed/", "?version=3&hl=en_US&theme=dark&color=white&loop=1&showinfo=0&autohide=0&disablekb=1&autoplay=0' frameborder='0' allowfullscreen=0> ");   }    if (document.querySelector('.ytsample') !== null) {        load(".ytsample", "<div style='width: 202px; overflow: hidden; height: 21px; margin-top: 5px; margin-bottom: 5px; margin-right: 5px; position:relative; top:0; border: 3px solid #0f0f0f; border-radius:10px'><iframe width='202px' height='21' src='http://www.youtube.com/embed/", "?version=3&hl=en_US&theme=dark&color=white&loop=1&showinfo=0&autohide=0&disablekb=1&autoplay=0' frameborder='0' allowfullscreen=0> ");   }    if (document.querySelector('.tmsample') !== null) {        load(".tmsample", " ");   } }); function load(sample, template1, template2) { $(sample).first.ready(function {        var id = document.querySelector(sample).title;        $(sample).first.append(template1 + id + template2);    }); if ($(sample).length == 2) { $(sample).last.ready(function {            var id = document.querySelectorAll(sample)[1].title;            $(sample).last.append(template1 + id + template2);        }); }   ; }

//- //stuff for the formatter //- var formatcaller = function { $('.tutorialicon').click(function {        if ($('.tutorialicon').hasClass('tutorialopen')) {            $('.tutorialicon').removeClass('tutorialopen');            $('#tutorialcontent').empty;            return;        }        $('.tutorialicon').addClass('tutorialopen');        $('#tutorialcontent').append(tutorial);    });

$('#formatter').click(function {        if ($('#formatter').hasClass('formatteropen')) {            $('#formatter').removeClass('formatteropen');            $('#formatcontent').empty;            return;        }        $('#formatter').addClass('formatteropen');        $('#formatcontent').html(" <img src='http://slot1.images.wikia.nocookie.net/__cb1481713639/common/skins/oasis/images/icon_close.png'>  NND mylists  <input type='text' name='nnd' placeholder='7359936 25396393 31424334 13892546 26633779'>  BB userspace  <input type='text' name='bb' placeholder='11073'>  YT usernames  <input type='text' name='ytun' placeholder='splendiferousfantasy'>  YT channels  <input type='text' name='ytch' placeholder='UCMsNS10PzxzEayT7UHS4p6g'>  YT playlists  <input type='text' name='ytpl' placeholder='PLOA7lc-qUd88NjN4adz8Di8ZHT6jwIFrS PLOA7lc-qUd8_mcFeaVAKWKbg9FSy35SIV'>  SoundCloud ID  <input type='text' name='sc' placeholder='sumashu missingnumber'>  <input type='button' value='Format!'> "); format; });   function song(title, yt, nnd, sc, bb, date) {        this.title = title;        this.yt = yt;        this.nnd = nnd;        this.sc = sc;        this.bb = bb;        this.date = date;    };

var format = function { $('#formatwindow input[type=button]').click(function {            var nnd = [];            var ytun = [];            var ytch = [];            var ytpl = [];            var sc = [];            var bb = [];            var list = [];            var listsc = [];

$.ajaxPrefilter(function (options) {               if (options.crossDomain && jQuery.support.cors &&  options.url.includes("space.bilibili.com"))) { //console.log('prefilter attached to '+options.url); var http = (window.location.protocol === 'http:' ? 'http:' : 'https:'); options.url = http + '//cors-anywhere.herokuapp.com/' + options.url; options.crossDomain = false; }           });            if (!$('input[name=nnd]').val == '') {                nnd = $('input[name=nnd]').val.split(" ");                for (var i = 0; i < nnd.length; i++) {                    var url = "https://query.yahooapis.com/v1/public/yql?q=select%20title%2CpubDate%2Clink%20from%20rss%20where%20url%3D'http%3A%2F%2Fwww.nicovideo.jp%2Fmylist%2F" + nnd[i] + "%2Fvideo%3Frss%3D2.0'&diagnostics=true";                    $.ajax({ type: "GET", url: url, dataType: "xml", success: function (xml) { $(xml).find('item').each(function {                                list.push(new song($(this).find('title').text, , $(this).find('link').text.split("/watch/")[1], , '', $(this).find('pubDate').text.split(' ')[3] + '.' + getmon($(this).find('pubDate').text.split(' ')[2]) + '.' + $(this).find('pubDate').text.split(' ')[1]))                            }); }                   });                }            }            ;            if (!$('input[name=bb]').val == ) {                bb = $('input[name=bb]').val.split(" ");                var token = "";                for (var i = 0; i < bb.length; i++) {                    bbformat("http://space.bilibili.com/ajax/member/getSubmitVideos?mid=" + bb[i] + "&pagesize=9999&page=", 1, list);                }            }            ;            if (!$('input[name=ytch]').val == ) {                ytch = $('input[name=ytch]').val.split(" ");                var token = "";                for (var i = 0; i < ytch.length; i++) {                    ytchformat(ytch[i], , list);                }            }            ;            if (!$('input[name=ytun]').val == ) {                ytun = $('input[name=ytun]').val.split(" ");                var token = ""; for (var i = 0; i < ytun.length; i++) { ytunformat(ytun[i], '', list); }           }            ;            if (!$('input[name=ytpl]').val == '') { ytpl = $('input[name=ytpl]').val.split(" "); var token = ""; for (var i = 0; i < ytpl.length; i++) { ytplformat(ytpl[i], '', list); }           }            ;            if (!$('input[name=sc]').val == '') { sc = $('input[name=sc]').val.split(" "); var url = ""; for (var i = 0; i < sc.length; i++) { url = "http://api.soundcloud.com/resolve.json?url=http://soundcloud.com/" + sc[i] + "/tracks&client_id=887b335a80f3e625454ebca548c53d96"; $.ajax({                       type: "GET",                        url: url,                        dataType: "json",                        success: function (json) {                            for (var j = 0; j < json.length; j++) {                                listsc.push(new song(json[j].title, , , json[j].permalink_url, '', json[j].created_at.split(' ')[0].replace('/', '.').replace('/', '.')));                            }                        }                    }); }           }            ;            //$(document).ajaxStop(function{}) $(document).ajaxStop(function {                list.sort(function (a, b) { if (a.title < b.title) return -1; if (a.title > b.title) return 1; return 0; });               list.sort(function (a, b) { if (a.date < b.date) return -1; if (a.date > b.date) return 1; return 0; });               for (var i = 0; i < list.length - 1; i++) {                    if ((list[i + 1].title == list[i].title) && (list[i + 1].date == list[i].date)) {                        if (list[i + 1].nnd != '') {                            list[i].nnd = list[i + 1].nnd;                        } else {                            list[i].yt = list[i + 1].yt;                        }                        list.splice(i + 1, 1);                        i--;                    }                }                var rmv = ['【歌ってみた】', 'を歌ってみた', '歌ってみた', '(english cover)', 'english cover', 'cover', 'english', 'vers.', 'ver.', 'vers', 'ver', 'french', 'german', 'chinese', 'spanish', 'rap', 'screamo', 'piano', 'tv size', 'tv-size', 'acapella', 'a capella', 'short', 'band', 'acoustic', 'arrange', 'parody', '替え歌ってみた', '替え歌', '--', '- -'];                var out = '==List of Covered Songs==\n\n'); var outsc = '===Songs on SoundCloud===\n\n');               if (listsc.length <= 0) {                    outsc = '';                }

$('#formatcontent').html(" <img src='http://slot1.images.wikia.nocookie.net/__cb1481713639/common/skins/oasis/images/icon_close.png'> " + out + outsc + " "); $('#formatwindow .close').click(function {                    $('#formatcontent').empty;                }); })       })    }    var verformat = function (title) { var tmp = ' -'; var t = ''; if (title.toLowerCase.indexOf('english') > -1 || title.indexOf('英語') > -1) { tmp += 'English '; }       if (title.toLowerCase.indexOf('french') > -1 || title.toLowerCase.indexOf('français') > -1) { tmp += 'French '; }       if (title.toLowerCase.indexOf('german') > -1 || title.toLowerCase.indexOf('deutsch') > -1) { tmp += 'German '; }       if (title.toLowerCase.indexOf('chinese') > -1 || title.indexOf('中文') > -1) { tmp += 'Chinese '; }       if (title.toLowerCase.indexOf('spanish') > -1 || title.toLowerCase.indexOf('español') > -1) { tmp += 'Spanish '; }       if (title.toLowerCase.indexOf('indonesia') > -1) { tmp += 'Indonesian '; }       if (title.toLowerCase.indexOf('rap') > -1) { tmp += 'Rap '; }       if (title.toLowerCase.indexOf('screamo') > -1) { tmp += 'Screamo '; }       if (title.toLowerCase.indexOf('piano') > -1 || title.indexOf('ピアノ') > -1) { tmp += 'Piano '; }       if (title.toLowerCase.indexOf('tv size') > -1 || title.toLowerCase.indexOf('tv-size') > -1) { tmp += 'TV size '; }       if (title.toLowerCase.indexOf('acapella') > -1 || title.toLowerCase.indexOf('a capella') > -1) { tmp += 'Acapella '; }       if (title.toLowerCase.indexOf('short') > -1) { tmp += 'Short '; }       if (title.toLowerCase.indexOf('band') > -1 || title.indexOf('バンド') > -1) { if (title.toLowerCase.indexOf('band edition') > -1) { t = ' -Band edition-'; } else { tmp += 'Band '; }       }        if (title.toLowerCase.indexOf('acoustic') > -1) { tmp += 'Acoustic '; }       if (title.toLowerCase.indexOf('arrange') > -1 || title.indexOf('アレンジ') > -1) { tmp += 'Arrange '; }       if (title.toLowerCase.indexOf('parody') > -1 || title.indexOf('替え歌') > -1) { tmp += 'Parody '; }       if (tmp == ' -') { return '' + t;       } return tmp + 'ver.-' + t   } var ytunformat = function (url, token, list) { var u = "https://www.googleapis.com/youtube/v3/channels?key=AIzaSyD5bC5qiEP-_25Llg2ciYNM9sW-WP6a6ck&part=id&forUsername=" + url; $.ajax({           type: "GET",            url: u,            dataType: "json",            success: function (json) {                u = "https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&maxResults=50&key=AIzaSyD5bC5qiEP-_25Llg2ciYNM9sW-WP6a6ck&channelId=" + json.items[0].id;                var turl;                if (token == '') {                    turl = u;                } else {                    turl = u + "&pageToken=" + token;                }                $.ajax({ type: "GET", url: turl, dataType: "json", success: function (json) { token = json.nextPageToken; for (var j = 0; j < json.items.length; j++) { if (json.items[j].id.videoId != null) { list.push(new song(json.items[j].snippet.title, json.items[j].id.videoId, , , '', json.items[j].snippet.publishedAt.split('T')[0].replace('-', '.').replace('-', '.'))); }                       }                        if (token != null) { ytunformat(url, token, list); }                   }                });            }        });    };    var ytchformat = function (url, token, list) { var u = "https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&maxResults=50&key=AIzaSyD5bC5qiEP-_25Llg2ciYNM9sW-WP6a6ck&channelId=" + url; var turl; if (token == '') { turl = u;       } else { turl = u + "&pageToken=" + token; }       $.ajax({            type: "GET",            url: turl,            dataType: "json",            success: function (json) {                token = json.nextPageToken;                for (var j = 0; j < json.items.length; j++) {                    if (json.items[j].id.videoId != null) {                        list.push(new song(json.items[j].snippet.title, json.items[j].id.videoId, , , '', json.items[j].snippet.publishedAt.split('T')[0].replace('-', '.').replace('-', '.')));                    }                }                if (token != null) {                    ytchformat(url, token, list);                }            }        }); };   var ytplformat = function (url, token, list) { var u = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&key=AIzaSyD5bC5qiEP-_25Llg2ciYNM9sW-WP6a6ck&playlistId=" + url; var turl; if (token == '') { turl = u;       } else { turl = u + "&pageToken=" + token; }       $.ajax({            type: "GET",            url: turl,            dataType: "json",            success: function (json) {                token = json.nextPageToken;                for (var j = 0; j < json.items.length; j++) {                    if (json.items[j].snippet.resourceId.videoId != null) {                        list.push(new song(json.items[j].snippet.title, json.items[j].snippet.resourceId.videoId, , , '', json.items[j].snippet.publishedAt.split('T')[0].replace('-', '.').replace('-', '.')));                    }                }                if (token != null) {                    ytplformat(url, token, list);                }            }        }); };

var bbformat = function (url, page, list) { var t = false; //console.log('bbformat called with url:'+url+page); $.ajax({           dataType: 'json',            url: url + page,            crossDomain: true,            processData: false,            success: function (json) {                //console.log('ajax successful');                var items = json.data.vlist;                for (var q = 0; q < items.length; q++) {                    var d = new Date(parseInt(items[q].created) * 1000)                    list.push(new song(items[q].title, , , '', "av" + items[q].aid, d.getFullYear + "." + ("0" + d.getMonth).slice(-2) + "." + ("0" + d.getDate).slice(-2)));                }                t = items.length == 9999;                if (t) {                    page++;                    bbformat(url, page, list);                }            }        }); };

var getmon = function (mon) { switch (mon) { case 'Jan': return '01'; break; case 'Feb': return '02'; break; case 'Mar': return '03'; break; case 'Apr': return '04'; break; case 'May': return '05'; break; case 'Jun': return '06'; break; case 'Jul': return '07'; break; case 'Aug': return '08'; break; case 'Sep': return '09'; break; case 'Oct': return '10'; break; case 'Nov': return '11'; break; case 'Dec': return '12'; break; }   } } /*  */