GOTA Improvements

Various improvements to Game of Thrones: Ascent

目前為 2014-05-20 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        GOTA Improvements
// @description Various improvements to Game of Thrones: Ascent
// @namespace   https://greasyfork.org/users/1665-nolana
// @include     http://gota.disruptorbeam.com/
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @version     1
// @grant       none
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

// $('div.locked').remove();
$(window).bind("load", function() {
   init();                        
});


function init() {
    $('#page-wrap').css('max-width',$(window).width()+'px');
    $('#holdings_container').width($(window).width()-10);
    // remove locked buildings
    $(document).on('click','#navlink-buildings',function (e) {
      $('#building_items div.locked').remove();
   });
   fixChat();
   observeChat();     
}

 
function fixChat() {
    var chatWidth = $(window).width()/3;
    addGlobalStyle(".gamechat{bottom:auto;float:none;height:auto;left:auto;right:188px;margin-left:2px;margin-top:8px;padding:1px 10px 15px;position:absolute;top:3px;width:" + chatWidth +"px;"+
                   "background:url(http://disruptorbeamcdn-01.insnw.net/images/pvp/actionbg.png?t=e2e9110ff577) repeat-x scroll 0 0 #000;border:1px solid #444;border-radius:12px;color:#FFF;font-size:16px;text-align:left;z-index:3}");
    addGlobalStyle("b {font-weight:bold}");
    addGlobalStyle("sub {font-size:11px;color:grey}");
    addGlobalStyle(".gamechat .chatscroll p { width: " + (chatWidth - 60) + "px;margin-bottom: 2px;font-size: 14px;");
    
   $('#combatlog').width(chatWidth - 10);
    
    $('#combatlog .jspPane p.pchat').each(function () {
        fixChatLine($(this));
    });
}

function observeChat() {
    var target = $('#combatlog .jspPane')[0];
    // Create an observer instance
    var observer = new MutationObserver(function( mutations ) {
       mutations.forEach(function( mutation ) {
       var newNodes = mutation.addedNodes; // DOM NodeList
       if (newNodes !== null) { // If there are new nodes added
    	var $nodes = $(newNodes); // jQuery set
    	$nodes.each(function() {
    		var $node = $(this);
    		if ($node.hasClass( "pactivity" )) {
                console.log('act:'+$node.text());
                // TODO, fix activity line
    		} else if ($node.hasClass("pchat")) {
                console.log('chat:' + $node.text());
                fixChatLine($node, new Date().toLocaleString());
            }
    	});
       }
     });    
    });
    var config = { 
	   attributes: false, 
	   childList: true, 
	   characterData: false 
    };
    observer.observe(target, config);
}

function fixChatLine(p, time) {
    var text = p.text();
    var result = /(.*):(.*)/.exec(text);
    if (result == null) return; // already highlighted
    var author = result[1];
    var line = result[2];
   
    p.find('strong').replaceWith('<strong><b>' + author + '</b>' + line + (time ? '  <sub>' + time + '</sub>' : ''));
  
}
function addGlobalStyle(css) {
		try {
			var elmHead, elmStyle;
			elmHead = document.getElementsByTagName('head')[0];
			elmStyle = document.createElement('style');
			elmStyle.type = 'text/css';
			elmHead.appendChild(elmStyle);
			elmStyle.innerHTML = css;
		} catch (e) {
			if (!document.styleSheets.length) {
				document.createStyleSheet();
			}
			document.styleSheets[0].cssText += css;
		}
}