MediaWiki:Wikia.js

/* */ var tutorial; var gettutorial = function { $.ajax({           url: 'http://utaite.wikia.com/wiki/Tutorial/tmp',        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; } }

function onPreloadArrival { if ($('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source').length) { insertAtCursor($('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source')[0], this.text); tutloader('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source'); } else { insertAtCursor(document.getElementById('wpTextbox1'), this.text); tutloader('#wpTextbox1'); } } /* 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); tutloader('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source'); } else { insertAtCursor(document.getElementById('wpTextbox1'), data); tutloader('#wpTextbox1'); }               });            }        });

$('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); tutloader('#cke_wpTextbox1 #cke_contents_wpTextbox1 .cke_source'); } else { insertAtCursor(document.getElementById('wpTextbox1'), data); tutloader('#wpTextbox1'); }   }); }

//link to converter in editor; thanks to UltimateSupreme with helping to put it for visual editors as well w:c:Thread:608344 $(function converter {   converticon = "  Convert  ";    $('.cke_button.RTEImageButton.cke_button_big').append(converticon);    if (window.CKEDITOR) {        CKEDITOR.on("instanceReady", function  { $(converter); });   } }); //formatbutton for List of Covered Songs $(function formatbutton {   formaticon = "  Format   ";    $('.cke_button.RTEImageButton.cke_button_big').append(formaticon);    if (window.CKEDITOR) {        CKEDITOR.on("instanceReady", function  { $(formatbutton); formatcaller; });   } else {        formatcaller;    } });

//Custom YT & TM player $(function loader {   if (document.querySelector('.ytvideo') !== null) {        load(".ytvideo", " ");   }    if (document.querySelector('.ytsample') !== null) {        load(".ytsample", " ");   }    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);        }); }; }

var formatcaller = function { $('#formatter').click(function {        if ($('#formatter').hasClass('formatteropen')) {            $('#formatter').removeClass('formatteropen');            $('#formatcontent').empty;            return;        }        $('#formatter').addClass('formatteropen');        $('#formatcontent').append("   NND mylists    BB userspace    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'>  TmBox ID  <input type='text' name='tm' placeholder='soraruru uni_mafumafu'>  SoundCloud ID  <input type='text' name='sc' placeholder='sumashu missingnumber'>  <input type='button' value='Format!'> "); format; });   function song(title, yt, nnd, tm, sc, bb, date) {        this.title = title;        this.yt = yt;        this.nnd = nnd;        this.tm = tm;        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 tm = [];            var sc = [];            var bb = [];            var list = [];            var listtm = [];            var listsc = [];

$.ajaxPrefilter(function (options) {               if (options.crossDomain && jQuery.support.cors && (options.url.includes("tmbox.net") || 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=tm]').val == '') { tm = $('input[name=tm]').val.split(" "); var u1 = "https://tmbox.net/user/" var u2 = "?page="; for (var i = 0; i < tm.length; i++) { tmformat(u1 + tm[i] + u2, 1, listtm); }           }            ;            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 outtm = '===Songs on TmBox===\n\n');               if (listtm.length <= 0) {                    outtm = '';                }                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 + outtm + " "); $('#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 tmformat = function (url, page, listtm) { var t = false; $.ajax({           url: url + page,            crossDomain: true,            processData: false,            success: function (html) {                html=html.split(" ")[0].replace(/(?:\r\n|\r|\n)/g, '');                t = (html.indexOf(" ") > -1);                var items = html.split(" ");                for (var q = 1; q < items.length; q++) {                    $.ajax({ indexValue: { title: items[q].split(" ")[1].split("</a>")[0], link: items[q].split(" ")[0] },                       crossDomain: true, processData: false, url: 'https://tmbox.net' + items[q].split(" ")[0], success: function (h) { h = h.split("<i class='icon clock fitted'></i>")[1].split(" ")[0].trim.replace("/", ".").replace("/", "."); listtm.push(new song(this.indexValue.title, , , this.indexValue.link, , , h)); }                   })                }                if (t) {                    page++;                    tmformat(url, page, listtm);                }            }        }); };   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; }   } } /*  */