Permalink
Browse files

perf(optimization): code tweaks

reorganized code, made it modular

BREAKING CHANGE: we now moved to GitHub
  • Loading branch information...
tomaski committed Apr 16, 2018
1 parent beeb727 commit 957de40b6048160a0158dad8c04433d2ae7d1911
Showing with 294 additions and 173 deletions.
  1. +12 −1 GRCRTMain.js
  2. +0 −1 bin/build.js
  3. +9 −61 common/RepConvTool.js
  4. +139 −0 modules/GRCRTMovedFrames.js
  5. +8 −1 modules/GRCRTOceanNumbers.js
  6. +123 −108 modules/RepConvGRC.js
  7. +3 −1 package.json
@@ -401,6 +401,7 @@ function _GRCRTMain(){
ga('create', 'UA-6635454-10', 'auto');
ga('send', 'pageview');
}
this.sChbxs = {};
this.init = function() {
if (typeof Game != 'object' && typeof MousePopup != 'function' && typeof GameEvents != 'object') {
setTimeout(function(){RepConv.init();},1000);
@@ -432,7 +433,7 @@ function _GRCRTMain(){
this.CookieStatsGRC2 = this._cookie + "_statsGRC2",
this.CookieStatsGRCL = this._cookie + "_statsGRCL",
this.CookieUnitsCost = this._cookie + "_unitsCost",
this.CookieOceanNumber = this._cookie + "_oceanNumber",
// this.CookieOceanNumber = this._cookie + "_oceanNumber",
this.CookieReportFormat = this._cookie + "_repFormat",
this.CookieUnitsRecr = this._cookie + "_unitsRecr",
this.CookieUnitsABH = this._cookie + "_unitsRecrABH",
@@ -441,6 +442,16 @@ function _GRCRTMain(){
this.CookieWall = this._cookie + "_wall",
this.hash = $.md5(this._cookie);
this.sChbxs[RepConv.CookiePower] = { label : 'CHKPOWERNAME' , default : true},
this.sChbxs[RepConv.CookieForumTabs] = { label : 'CHKFORUMTABS' , default : true},
this.sChbxs[RepConv.CookieUnitsCost] = { label : 'CHKUNITSCOST' , default : true},
this.sChbxs[RepConv.CookieReportFormat] = { label : 'CHKREPORTFORMAT' , default : true},
this.sChbxs[RepConv.Cookie+'_idle'] = { label : 'STATS.CHKINACTIVE' , default : true},
this.sChbxs[RepConv.Cookie+'_wonder_trade'] = { label : 'CHKWONDERTRADE' , default : true},
this.sChbxs[RepConv.Cookie+'_town_popup'] = { label : 'CHKTOWNPOPUP' , default : true},
this.sChbxs[RepConv.Cookie+'_mcol'] = { label : 'CHKMCOL' , default : true},
this.sChbxs[RepConv.Cookie+'_bupo'] = { label : 'CHKBUPO' , default : true},
RepConvLangArray = new _GRCRTRepConvLangArray()
if (RepConvLangArray[Game.locale_lang.substring(0,2)] == undefined) {
@@ -91,7 +91,6 @@ try {
function write2file(fileNameIn, fileNameOut, append){
var data = fs.readFileSync(fileNameIn, 'utf8');
var result = data
.replace(/{GRCRT_VERSION}/g, GRCRT_VERSION)
.replace(/{GRCRT_NAME}/g, GRCRT_NAME)
.replace(/{GRCRT_URL}/g, GRCRT_URL)
.replace(/\r\n/g,'\n')
@@ -6,46 +6,24 @@ function _RepConvTool() {
this.checkSettings = function(){
var defData = {}, setOK = true;
defData[RepConv.CookieCmdImg] = true,
defData[RepConv.CookiePower] = true,
defData[RepConv.CookieForumTabs] = true,
defData[RepConv.CookieStatsGRCL] = 'potusek',
defData[RepConv.CookieUnitsCost] = true,
defData[RepConv.CookieOceanNumber] = true,
defData[RepConv.CookieReportFormat] = true,
defData[RepConv.CookieSounds] = { mute: false, volume: 100, url:'', loop:true};
RepConv.settings = RepConv.settings || {}
if(RepConv.settings[RepConv.CookiePower] == undefined){
RepConv.settings[RepConv.CookiePower] = JSON.parse(RepConvTool.getSettings(RepConv.CookiePower, defData[RepConv.CookiePower])),
setOK = false;
RepConv.Debug && console.log(RepConv.CookiePower)
}
if(RepConv.settings[RepConv.CookieForumTabs] == undefined){
RepConv.settings[RepConv.CookieForumTabs] = JSON.parse(RepConvTool.getSettings(RepConv.CookieForumTabs, defData[RepConv.CookieForumTabs])),
setOK = false;
RepConv.Debug && console.log(RepConv.CookieForumTabs)
}
$.each(RepConv.sChbxs, function(opt, optData){
if(RepConv.settings[opt] == undefined){
RepConv.settings[opt] = JSON.parse(RepConvTool.getSettings(opt, optData.default)),
setOK = false;
RepConv.Debug && console.log(RepConv.CookieReportFormat)
}
})
if(RepConv.settings[RepConv.CookieStatsGRCL] == undefined){
RepConv.settings[RepConv.CookieStatsGRCL] = RepConvTool.getSettings(RepConv.CookieStatsGRCL, defData[RepConv.CookieStatsGRCL]),
setOK = false;
RepConv.Debug && console.log(RepConv.CookieStatsGRCL)
}
if(RepConv.settings[RepConv.CookieUnitsCost] == undefined){
RepConv.settings[RepConv.CookieUnitsCost] = JSON.parse(RepConvTool.getSettings(RepConv.CookieUnitsCost,defData[RepConv.CookieUnitsCost])),
setOK = false;
RepConv.Debug && console.log(RepConv.CookieUnitsCost)
}
if(RepConv.settings[RepConv.CookieOceanNumber] == undefined){
RepConv.settings[RepConv.CookieOceanNumber] = JSON.parse(RepConvTool.getSettings(RepConv.CookieOceanNumber, defData[RepConv.CookieOceanNumber])),
setOK = false;
RepConv.Debug && console.log(RepConv.CookieOceanNumber)
}
if(RepConv.settings[RepConv.CookieReportFormat] == undefined){
RepConv.settings[RepConv.CookieReportFormat] = JSON.parse(RepConvTool.getSettings(RepConv.CookieReportFormat, defData[RepConv.CookieReportFormat])),
setOK = false;
RepConv.Debug && console.log(RepConv.CookieReportFormat)
}
if(RepConv.settings[RepConv.CookieUnitsABH] == undefined){
RepConv.settings[RepConv.CookieUnitsABH] = RepConvTool.getSettings(RepConv.CookieUnitsABH, "{}"),
setOK = false;
@@ -76,41 +54,11 @@ function _RepConvTool() {
setOK = false;
RepConv.Debug && console.log(RepConv.CookieEmots)
}
if(RepConv.settings[RepConv.Cookie+'_idle'] == undefined){
RepConv.settings[RepConv.Cookie+'_idle'] = true;//!(typeof QT_saveValue == 'function')
setOK = false;
RepConv.Debug && console.log(RepConv.Cookie+'_idle')
}
if(RepConv.settings[RepConv.CookieSounds] == undefined){
RepConv.settings[RepConv.CookieSounds] = JSON.parse(RepConvTool.getSettings(RepConv.CookieSounds, JSON.stringify(defData[RepConv.CookieSounds]))),
setOK = false;
RepConv.Debug && console.log(RepConv.CookieSounds)
}
if(RepConv.settings[RepConv.Cookie+'_wonder_trade'] == undefined){
RepConv.settings[RepConv.Cookie+'_wonder_trade'] = (RepConv.settings[RepConv.Cookie+'_wonder_trade']==undefined)?true:RepConv.settings[RepConv.Cookie+'_wonder_trade'],
setOK = false;
RepConv.Debug && console.log(RepConv.Cookie+'_wonder_trade')
}
if(RepConv.settings[RepConv.Cookie+'_town_popup'] == undefined){
RepConv.settings[RepConv.Cookie+'_town_popup'] = (RepConv.settings[RepConv.Cookie+'_town_popup']==undefined)?true:RepConv.settings[RepConv.Cookie+'_town_popup'],
setOK = false;
RepConv.Debug && console.log(RepConv.Cookie+'_town_popup')
}
if(RepConv.settings[RepConv.Cookie+'_tacl'] == undefined){
RepConv.settings[RepConv.Cookie+'_tacl'] = (RepConv.settings[RepConv.Cookie+'_tacl']==undefined)?true:RepConv.settings[RepConv.Cookie+'_tacl'],
setOK = false;
RepConv.Debug && console.log(RepConv.Cookie+'_tacl')
}
if(RepConv.settings[RepConv.Cookie+'_mcol'] == undefined){
RepConv.settings[RepConv.Cookie+'_mcol'] = (RepConv.settings[RepConv.Cookie+'_mcol']==undefined)?true:RepConv.settings[RepConv.Cookie+'_mcol'],
setOK = false;
RepConv.Debug && console.log(RepConv.Cookie+'_mcol')
}
if(RepConv.settings[RepConv.Cookie+'_bupo'] == undefined){
RepConv.settings[RepConv.Cookie+'_bupo'] = (RepConv.settings[RepConv.Cookie+'_bupo']==undefined)?true:RepConv.settings[RepConv.Cookie+'_bupo'],
setOK = false;
RepConv.Debug && console.log(RepConv.Cookie+'_bupo')
}
if(!setOK){
RepConv.Debug && console.log(_saveCount);
@@ -132,7 +80,7 @@ function _RepConvTool() {
RepConv.active.ftabs = RepConv.settings[RepConv.CookieForumTabs],//, defData[RepConv.CookieForumTabs]),
RepConv.active.statsGRCL = RepConv.settings[RepConv.CookieStatsGRCL],//, defData[RepConv.CookieStatsGRCL]),
RepConv.active.unitsCost = RepConv.settings[RepConv.CookieUnitsCost],//,defData[RepConv.CookieUnitsCost]),
RepConv.active.oceanNumber = RepConv.settings[RepConv.CookieOceanNumber],//, defData[RepConv.CookieOceanNumber]),
// RepConv.active.oceanNumber = RepConv.settings[RepConv.CookieOceanNumber],//, defData[RepConv.CookieOceanNumber]),
RepConv.active.reportFormat = RepConv.settings[RepConv.CookieReportFormat],//, defData[RepConv.CookieReportFormat]);
RepConv.audioSupport && (RepConv.active.sounds = RepConv.settings[RepConv.CookieSounds]),
this.useSettings()
@@ -0,0 +1,139 @@
function _GRCRTMovedFrames(){
"use strict";
function activity_commands_list(){
if($('#toolbar_activity_commands_list').length==0){
setTimeout(function(){
activity_commands_list()
},500);
return;
}
// command list
if($('#grcrt_taclWrap').length==0){
$('#toolbar_activity_commands_list').wrap($('<div/>',{'class':'grcrt_taclWrap', 'id':'grcrt_taclWrap'}))
if(RepConv.settings[RepConv.Cookie+'_tacl']){
$('#toolbar_activity_commands_list').addClass('grcrt_tacl')
$('#grcrt_taclWrap').draggable().draggable('enable')
} else {
$('#toolbar_activity_commands_list').removeClass('grcrt_tacl')
$('#grcrt_taclWrap').draggable().draggable('disable').removeAttr('style')
}
}
var
tacl_id = '#toolbar_activity_commands_list',
tacl_clk = '.activity.commands',
target_tacl = document.querySelector(tacl_id),
observer_tacl = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if($(target_tacl).hasClass('grcrt_tacl') && ($('#grcrt_taclWrap').attr('style') && $(target_tacl).css('display')=="none")){
$(tacl_clk).trigger('mouseenter')
}
});
});
if($(tacl_id+">.js-dropdown-list>a.cancel").length == 0){
$(tacl_id+">.js-dropdown-list")
.append(
$('<a/>',{'href':'#n','class':'cancel', 'style':'display:none;'})
.click(function(){
$('#grcrt_taclWrap').removeAttr('style')
})
)
}
observer_tacl.observe(target_tacl, { attributes: true, childList: false, characterData: false });
}
// function activity_trades_list(){
// if($('#toolbar_activity_trades_list').length==0){
// setTimeout(function(){
// activity_trades_list()
// },500);
// return;
// }
// var
// tatl_id = '#toolbar_activity_trades_list',
// tatl_clk = '.activity.trades'
// if($('#grcrt_tatlWrap').length==0){
// $('#toolbar_activity_trades_list').wrap($('<div/>',{'class':'grcrt_tatlWrap', 'id':'grcrt_tatlWrap'}))
// if(RepConv.settings[RepConv.Cookie+'_tatl']){
// $('#toolbar_activity_trades_list').addClass('grcrt_tatl')
// $('#grcrt_tatlWrap').draggable().draggable('enable')
// } else {
// $('#toolbar_activity_trades_list').removeClass('grcrt_tatl')
// $('#grcrt_tatlWrap').draggable().draggable('disable').removeAttr('style')
// }
// }
// if($(tatl_clk).hasClass('active')){
// $(tatl_id)
// .append(
// $('<a/>',{'href':'#n','class':'cancel', 'style':'display:none;'})
// .click(function(){
// $('#grcrt_tatlWrap').removeAttr('style')
// })
// )
// } else {
// var
// target_tatl = document.querySelector(tatl_id),
// observer_tatl = new MutationObserver(function(mutations) {
// mutations.forEach(function(mutation) {
// if($(target_tatl).hasClass('grcrt_tatl') && ($('#grcrt_tatlWrap').attr('style') && $(target_tatl).css('display')=="none")){
// $(tatl_clk).trigger('mouseenter')
// }
// });
// });
// $(tatl_id+">.js-dropdown-list")
// .append(
// $('<a/>',{'href':'#n','class':'cancel', 'style':'display:none;'})
// .click(function(){
// $('#grcrt_tatlWrap').removeAttr('style')
// })
// )
// observer_tatl.observe(target_tatl, { attributes: true, childList: false, characterData: false });
// }
// }
$('head')
.append(
$('<style/>')
.append( // frozen lists
$('<style/>')
.append('.showImportant { bisplay: block !important}')
.append('#grcrt_taclWrap { left:312px; position: absolute; top: 29px;}')
.append('#grcrt_taclWrap>#toolbar_activity_commands_list { left: 0 !important; top: 0 !important;}')
.append('.grcrt_tacl { z-index:5000 !important;}')
.append('.grcrt_tacl>.js-dropdown-list>a.cancel { position: relative; float: right; margin-bottom: 11px;display:none; opacity: 0; visibility: hidden; transition: visibility 0s, opacity 0.5s linear;}')
.append('.grcrt_tacl>.js-dropdown-list:hover>a.cancel { display: block !important; visibility: visible; opacity: 0.5;}')
.append('.grcrt_tacl>.js-dropdown-list>a.cancel:hover { opacity: 1;}')
// .append('#grcrt_tatlWrap { left:340px; position: absolute; top: 29px;}')
// .append('#grcrt_tatlWrap>#toolbar_activity_trades_list { left: 0 !important; top: 0 !important;}')
// .append('.grcrt_tatl { z-index:5000 !important;}')
// .append('.grcrt_tatl>a.cancel { position: relative; float: right; margin-bottom: 11px;display:none; opacity: 0; visibility: hidden; transition: visibility 0s, opacity 0.5s linear;}')
// .append('.grcrt_tatl:hover>a.cancel { display: block !important; visibility: visible; opacity: 0.5;}')
// .append('.grcrt_tatl>a.cancel:hover { opacity: 1;}')
// .append('.grcrt_tatl>.js-dropdown-list>a.cancel { position: relative; float: right; margin-bottom: 11px;display:none; opacity: 0; visibility: hidden; transition: visibility 0s, opacity 0.5s linear;}')
// .append('.grcrt_tatl>.js-dropdown-list:hover>a.cancel { display: block !important; visibility: visible; opacity: 0.5;}')
// .append('.grcrt_tatl>.js-dropdown-list>a.cancel:hover { opacity: 1;}')
// .append('.grcrt_tarl>a.cancel,.grcrt_tacl>a.cancel,.grcrt_tatl>a.cancel { position: relative; float: right; margin-bottom: 0px;display:none; opacity: 0; visibility: hidden; transition: visibility 0s, opacity 0.5s linear;}')
// .append('.grcrt_tarl:hover>a.cancel,.grcrt_tacl:hover>a.cancel,.grcrt_tatl:hover>a.cancel { display: block !important; visibility: visible; opacity: 0.5;}')
// .append('.grcrt_tarl>a.cancel:hover,.grcrt_tacl>a.cancel:hover,.grcrt_tatl>a.cancel:hover { opacity: 1;}')
// .append('.grcrt_tacl>.js-dropdown-list:after {content: "___"; float: right; height: 30px; background: transparent url(https://cdn1.iconfinder.com/data/icons/interface-4/96/Cursor-Move-16.png) no-repeat top right; color: transparent;position:relative}')
// .append('.grcrt_tacl>.js-dropdown-list:after:hover {height: 30px;}')
// .append('.grcrt_tacl>.js-dropdown-item-list:after {content: "___"; float: right; height: 19px; background: transparent url(https://cdn1.iconfinder.com/data/icons/interface-4/96/Cursor-Move-16.png) no-repeat top right; color: transparent;position:relative}')
// .append('.grcrt_tacl>.js-dropdown-item-list:after:hover {height: 30px;}')
)
);
RepConv.sChbxs[RepConv.Cookie+'_tacl'] = { label : 'CHKTACL', default : true}
// RepConv.sChbxs[RepConv.Cookie+'_tatl'] = { label : 'CHKTATL', default : true}
$.Observer(GameEvents.grcrt.settings.load)
.subscribe('GRCRTMovedFrames_settings_load', function() {
activity_commands_list();
// activity_trades_list();
});
}
@@ -1,11 +1,12 @@
function _GRCRTOceanNumbers(){
var _cookie = RepConv._cookie + "_oceanNumber";
function oceanNumbers(){
if ($('#map_move_container').length == 0) {
setTimeout(function(){
oceanNumbers();
}, 100);
} else {
if (!RepConv.active.oceanNumber) {
if (!RepConv.settings[_cookie]) {
$('div#grcrt_oceanNumbers').remove()
} else {
if ($('div#grcrt_oceanNumbers').length == 0) {
@@ -25,6 +26,12 @@ function _GRCRTOceanNumbers(){
}
}
}
RepConv.sChbxs[_cookie] = {
label : 'CHKOCEANNUMBER',
default : true
}
$.Observer(GameEvents.grcrt.settings.load)
.subscribe('GRCRTOceanNumbers_settings_load', function() {
oceanNumbers();
Oops, something went wrong.

0 comments on commit 957de40

Please sign in to comment.