GOTA Improvements

Various improvements to Game of Thrones: Ascent

目前为 2014-05-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name GOTA Improvements
  3. // @description Various improvements to Game of Thrones: Ascent
  4. // @namespace https://greasyfork.org/users/1665-nolana
  5. // @include http://gota.disruptorbeam.com/
  6. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  7. // @version 1
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. this.$ = this.jQuery = jQuery.noConflict(true);
  12.  
  13. // $('div.locked').remove();
  14. $(window).bind("load", function() {
  15. init();
  16. });
  17.  
  18.  
  19. function init() {
  20. $('#page-wrap').css('max-width',$(window).width()+'px');
  21. $('#holdings_container').width($(window).width()-10);
  22. // remove locked buildings
  23. $(document).on('click','#navlink-buildings',function (e) {
  24. $('#building_items div.locked').remove();
  25. });
  26. fixChat();
  27. observeChat();
  28. }
  29.  
  30. function fixChat() {
  31. var chatWidth = $(window).width()/3;
  32. 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;"+
  33. "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}");
  34. addGlobalStyle("b {font-weight:bold}");
  35. addGlobalStyle("sub {font-size:11px;color:grey}");
  36. addGlobalStyle(".gamechat .chatscroll p { width: " + (chatWidth - 60) + "px;margin-bottom: 2px;font-size: 14px;");
  37. $('#combatlog').width(chatWidth - 10);
  38. $('#combatlog .jspPane p.pchat').each(function () {
  39. fixChatLine($(this));
  40. });
  41. }
  42.  
  43. function observeChat() {
  44. var target = $('#combatlog .jspPane')[0];
  45. // Create an observer instance
  46. var observer = new MutationObserver(function( mutations ) {
  47. mutations.forEach(function( mutation ) {
  48. var newNodes = mutation.addedNodes; // DOM NodeList
  49. if (newNodes !== null) { // If there are new nodes added
  50. var $nodes = $(newNodes); // jQuery set
  51. $nodes.each(function() {
  52. var $node = $(this);
  53. if ($node.hasClass( "pactivity" )) {
  54. console.log('act:'+$node.text());
  55. // TODO, fix activity line
  56. } else if ($node.hasClass("pchat")) {
  57. console.log('chat:' + $node.text());
  58. fixChatLine($node, new Date().toLocaleString());
  59. }
  60. });
  61. }
  62. });
  63. });
  64. var config = {
  65. attributes: false,
  66. childList: true,
  67. characterData: false
  68. };
  69. observer.observe(target, config);
  70. }
  71.  
  72. function fixChatLine(p, time) {
  73. var text = p.text();
  74. var result = /(.*):(.*)/.exec(text);
  75. if (result == null) return; // already highlighted
  76. var author = result[1];
  77. var line = result[2];
  78. p.find('strong').replaceWith('<strong><b>' + author + '</b>' + line + (time ? ' <sub>' + time + '</sub>' : ''));
  79. }
  80. function addGlobalStyle(css) {
  81. try {
  82. var elmHead, elmStyle;
  83. elmHead = document.getElementsByTagName('head')[0];
  84. elmStyle = document.createElement('style');
  85. elmStyle.type = 'text/css';
  86. elmHead.appendChild(elmStyle);
  87. elmStyle.innerHTML = css;
  88. } catch (e) {
  89. if (!document.styleSheets.length) {
  90. document.createStyleSheet();
  91. }
  92. document.styleSheets[0].cssText += css;
  93. }
  94. }