Skip to content

Instantly share code, notes, and snippets.

@semperrabbit
Last active July 5, 2019 23:06
Show Gist options
  • Save semperrabbit/e3b5a1f63d08bab6f631f56619578297 to your computer and use it in GitHub Desktop.
Save semperrabbit/e3b5a1f63d08bab6f631f56619578297 to your computer and use it in GitHub Desktop.
Screeps client inject object birthdays
/* watcher function to ensure injection is applied */
window.showBirthDate = function(event){
var formatDate = function formatDate(d){;
return ("0" + d.getUTCHours()).slice(-2) + ":" +
("0" + d.getUTCMinutes()).slice(-2) + ":" +
("0" + d.getUTCSeconds()).slice(-2) + " " +
("0" + (d.getUTCMonth()+1)).slice(-2) + "/" +
("0" + d.getUTCDate()).slice(-2) + "/" +
d.getUTCFullYear() + " UTC";
};
var showBdayInternal = function(){
let gameEl = angular.element($('section.game'));
let roomEl = angular.element($('section.room'));
let $rootScope = gameEl.injector().get('$rootScope');
let $compile = gameEl.injector().get('$compile');
let target = $('.object-properties .aside-block-content')[0];
let elem = $('<div class="ng-binding ng-scope"><label>BirthDate: </label>' + formatDate(new Date(parseInt(roomEl.scope().Room.selectedObject._id.substr(0,8), 16)*1000)) + '</div>');
$compile(elem)($rootScope);
if(target.children.length > 1) {
elem.insertBefore(target.children[2]);
} else {
elem.insertBefore(target.children[0].children[2]);
};
};
setTimeout(()=>{
if(event == 'view' && $('.object-properties .aside-block-content')[0]) {
showBdayInternal();
}
}, 100);
};
/* adds watcher to ensure injection is applied */
setTimeout(()=>{
if(!angular.element(document.body).scope().viewChangeCallbacks || !_.find(angular.element(document.body).scope().viewChangeCallbacks, window.showBirthDate))
ScreepsAdapter.onViewChange(window.showBirthDate);
},2000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment