Advertisement
Monchoman45

ChatTopic

Mar 16th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(wgCanonicalSpecialPageName == 'Chat') {
  2.     function ChatTopic() {
  3.         var api = new APIQuery();
  4.         api.send(new api.Query(api, 'GET', {action: 'query', prop: 'revisions', rvprop: 'content', titles: 'Project:Chat/Topic', indexpageids: '1'}, function(result) {
  5.             document.getElementById('chat-topic').innerHTML = result.query.pages[result.query.pageids[0]].revisions[0]['*'];
  6.         }));
  7.  
  8.         document.getElementById('ChatHeader').getElementsByTagName('h1')[0].innerHTML += '<div id="chat-topic" style="position:absolute; bottom:2px; z-index:5; font-weight:normal; left:250px; right:160px; height:35px; line-height:17px; font-size:smaller; color:#ccc" contenteditable="true" onblur="var api = new APIQuery(); api.send(new api.Query(api, \'POST\', {action: \'edit\', text: this.innerHTML, title: \'Project:Chat/Topic\', summary: \'changing topic\', bot: 1}, function(result) {if(result.edit.result == \'Success\') {$(\'#Write textarea\').val(\'ätopic:\' + document.getElementById(\'chat-topic\').innerHTML); mainRoom.sendMessage({which: 13, preventDefault: function() {}});} else {window.alert(\'You do not have permission to change the topic.\');}}));">Topic loading...</div>';
  9.     }
  10.     setTimeout(ChatTopic, 1);
  11.    
  12.     mainRoom.model.chats.bind('afteradd', $.proxy(function(data) {
  13.         if(data.attrs.text.indexOf('ätopic:') == 0) {
  14.             document.getElementById('chat-topic').innerHTML = data.attrs.text.substring(data.attrs.text.indexOf(':') + 1);
  15.             this.chatUL.children().last().children('.message')[0].innerHTML = '*** Changed topic to ' + document.getElementById('chat-topic').innerHTML + ' ***';
  16.         }
  17.     }, mainRoom.viewDiscussion));
  18. }
  19. else if(!window.ChatCheck) {
  20.     $(function () {
  21.         if(document.body.className.indexOf('skin-oasis') == -1) {
  22.             var a = document.getElementsByTagName('a');
  23.             for(var i in a) {
  24.                 if(a[i].href && a[i].href.indexOf('/wiki/Special:Chat') != -1) {
  25.                     a[i].href = 'javascript:OpenChatWindow()';
  26.                 }
  27.             }
  28.         }
  29.         else {
  30.             window.chatcheck = setInterval('ChatCheck()', 200);
  31.         }
  32.     });
  33.  
  34.     function ChatCheck() {
  35.         if($('.chat-join button').length != 0) {
  36.             $('.chat-join button').replaceWith('<a class="wikia-button" onclick="OpenChatWindow()">' + $('.chat-join button').html() + '</a>');
  37.             clearInterval(window.chatcheck);
  38.         }
  39.     }
  40.  
  41.     function OpenChatWindow() {
  42.         window.chatwindow = window.open('/index.php?title=Special:Chat&useskin=wikia');
  43.         window.chatwindow.onload = function () {
  44.             //addOnloadHook, importScript, and importStylesheet
  45.             window.chatwindow.$('body').prepend('<script>\nfunction importScript(b){var a=wgScript+"?title="+encodeURIComponent(b.replace(/ /g,"_")).replace(/%2F/ig,"/").replace(/%3A/ig,":")+"&action=raw&ctype=text/javascript";return importScriptURI(a)}\nfunction importScriptURI(a){var b=document.createElement("script");b.setAttribute("src",a);b.setAttribute("type","text/javascript");document.getElementsByTagName("head")[0].appendChild(b);return b}\nfunction importScriptPage(b,d){var a="/index.php?title="+encodeURIComponent(b.replace(/ /g,"_")).replace("%2F","/").replace("%3A",":")+"&action=raw&ctype=text/javascript";if(typeof d=="string"){if(d.indexOf("://")==-1){a="http://"+d+".wikia.com"+a}else{a=d+a}}return importScriptURI(a)}\nfunction importStylesheet(a){return importStylesheetURI(wgScript+"?action=raw&ctype=text/css&title="+encodeURIComponent(a.replace(/ /g,"_")))}\nfunction importStylesheetURI(b,d){var a=document.createElement("link");a.type="text/css";a.rel="stylesheet";a.href=b;if(d){a.media=d}document.getElementsByTagName("head")[0].appendChild(a);return a}\nfunction importStylesheetPage(b,d){var a="/index.php?title="+encodeURIComponent(b.replace(/ /g,"_")).replace("%2F","/").replace("%3A",":")+"&action=raw&ctype=text/css";if(typeof d=="string"){if(d.indexOf("://")==-1){a="http://"+d+".wikia.com"+a}else{a=d+a}}return importStylesheetURI(a)}\n//This isn\'t the same as the regular addOnloadHook, because the regular one runs from a script tag in the body that I don\'t feel like appending. It\'s easier to just make it $(function), which is essentially equivalent\nfunction addOnloadHook(func) {$(func);}\n</script>');
  46.             //global.js
  47.             window.chatwindow.importScriptURI('http://community.wikia.com/index.php?title=User:' + wgUserName + '/global.js&action=raw&ctype=text/javascript');
  48.             //wikia.js
  49.             window.chatwindow.importScriptURI(wgServer + '/index.php?title=User:' + wgUserName + '/wikia.js&action=raw&ctype=text/javascript');
  50.             //global.css
  51.             window.chatwindow.importStylesheetURI('http://community.wikia.com/index.php?title=User:' + wgUserName + '/global.css&action=raw&ctype=text/css');
  52.             //wikia.css
  53.             window.chatwindow.importStylesheetURI(wgServer + '/index.php?title=User:' + wgUserName + '/wikia.css&action=raw&ctype=text/css');
  54.  
  55.             //common.js
  56.             window.chatwindow.importScriptURI(wgServer + '/index.php?title=MediaWiki:Common.js&action=raw&ctype=text/javascript');
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement