').attr('class', 'value').css({
'position': 'absolute',
'left': '32px',
'top': '3px',
'width': '115px',
'height': '25px',
'line-height': '25px',
'pading': '0 5px',
'color': '#f8c57c',
'font-size': '13pt',
'text-align': 'right',
'user-select': 'none',
'background': 'url("https://westzzs.innogamescdn.com/images/interface/custom_unit_counter_sprite.png?2") no-repeat 0 -36px',
'z-index': '1'
}).append(valText).prepend(vetIcon);
var vetCounter = $('
').attr({
'class': 'xsht_custom_unit_counter',
'id': 'magic_vp_counter',
'title': '
Veteran Points You earn Veteran Points by fighting on Adventures!
Veteran points can be spent in the Union Pacific Store.'
}).css({
'position': 'absolute',
'top': '32px',
'left': '50%',
'margin-left': '-250px',
'z-index': '16',
'width': '180px',
'height': '36px',
'text-align': 'left',
'text-shadow': '1px 1px 1px #000',
'background': 'url("https://westzzs.innogamescdn.com/images/interface/custom_unit_counter_sprite.png?2") no-repeat 50% 0',
'cursor': 'pointer'
}).append(vetValue).click(function() {
west.window.shop.open();
});
$("#ui_topbar").before(vetCounter)
WestUi.TopBar._redraw($("#magic_vp_value"), Character.veteranPoints);
EventHandler.listen("veteran_points_changed", function(amount) {
WestUi.TopBar._redraw($("#magic_vp_value"), Character.veteranPoints);
});
}
/*
* It replaces the +/- button inside the job window with a dropdowon.
*/
var enableJobRework = function() {
JobWindow.getJobAmount = function() {
var amount = parseInt(this.window.$("#tw_work_menu_value").children("option").filter(":selected").text(), 10);
return isNaN(amount) ? 1 : amount;
};
JobWindow.getJobAmountSelector = function() {
var title = _('How often do you want to start the job?').escapeHTML(),
cb = this.setJobAmount.bind(this);
return $(s('
' +
' ' +
'
', title)).click(cb).mousewheel(cb);
};
}
/*
* It sends a request to the user to enable the browser notifications.
*/
var requestNotification = function() {
if (!window.Notification) {
new UserMessage("Sorry, notifications are not supported.").show();
} else {
Notification.requestPermission(function(p) {
if (p === 'denied') {
new UserMessage("Permission wasn\'t granted.").show();
} else if (p === 'granted') {
new UserMessage("Notifications have been enabled!").show();
}
});
}
}
/*
* For some reason displaying coloured message brings out some HTML tags as well. Using this to remove them.
*/
var stripHTML = function(html)
{
var tmp = document.createElement("DIV");
tmp.innerHTML = html;
return tmp.textContent || tmp.innerText || "";
}
/*
* It enables the better-notifications feature. This feature replaces the standard in-game popup.
*/
var enableNotifications = function() {
/*Keeping this here for later.
var emotes = {
"sore": ":/",
"invader": "=:)",
"angry": ">:(",
"cry": ":'(",
"smile": ":)",
"grin": ":D",
"frown": ":(",
"smirk": ";)",
"tongue": ":P",
"ohmy": ":o",
"muted": ":x",
"silent": ":|",
"palm": ">_<",
"nc": "-.-",
"happy": "^_^",
"oo": "o_O",
"xx": "x_x",
"cry": "T_T",
"elpollodiablo": "el pollo diablo!",
"elpollodiablo_mirror": "!el pollo diablo",
"elpollodiablo_front": "el pollo diablo?!"
};*/
requestNotification();
EventHandler.listen("chat_tell_received", function(room) {
function notify() {
var regex = /
(.*)<\/td>/ig;
var final = regex.exec(room.history[room.history.length - 1])[3];
new Notification('New Message from ' + room.client.pname, {
body: stripHTML(final.replace(//g, "")),
icon: 'http://puu.sh/oaqQS/1c5bbb0c5c.jpg'
});
}
if (Notification.permission !== 'granted')
new UserMessage("Please enable notifications.").show();
else
notify();
});
}
/*
* Creating a local storage if it doesn't exist. If there is one, I'm updating the MagicFeatures objects with data from it.
*/
var initialiseStorage = function() {
$.each(MagicFeatures, function(key) {
if (localStorage.getItem("magicbundle_feature_" + key) === null) {
localStorage.setItem("magicbundle_feature_" + key, "deactivated");
MagicFeatures[key]["status"] = "deactivated";
} else if (localStorage.getItem("magicbundle_feature_" + key) === "activated") {
MagicFeatures[key]["status"] = "activated";
enableFeature(key);
} else if (localStorage.getItem("magicbundle_feature_" + key) === "deactivated") {
MagicFeatures[key]["status"] = "deactivated";
}
})
}
/*
* Changing the status of a feature, from deactivated to activated and the other way around.
* @param {String} key
*/
var changeFeatureStatus = function(key) {
var s1 = MagicFeatures[key]['status'];
var s2 = localStorage.getItem('magicbundle_feature_' + key);
if (s1 != s2) {
return "Error"; //Should never happen, hopefully.
} else {
if (s1 == "activated") {
new UserMessage("'" + MagicFeatures[key]["fullName"] + "' is now disabled.").show();
MagicFeatures[key]['status'] = "deactivated";
localStorage.setItem('magicbundle_feature_' + key, "deactivated");
} else {
new UserMessage("'" + MagicFeatures[key]["fullName"] + "' is now enabled.").show();
MagicFeatures[key]['status'] = "activated";
localStorage.setItem('magicbundle_feature_' + key, "activated");
}
}
}
/*
* Building a window object, setting the initial tab to "notifications"
* @type {Object}
*/
window.MagicWindow = {
window: null,
currentTab: "notifications",
};
/*
* Manually injecting some styling to the game. Don't ever do this pls.
*/
var styling = '';
$('head').append(styling);
/*
* Building a Table Row containing the Toggle Buttom
* @param {String} key
* @param {String} status
* @returns {HTMLTableRow}
*/
var buildToggleTableRow = function(key, status) {
var tColOne = $('').text('Toggle: ').css('font-weight', 'bold');
var toggleButton = $('').attr({
'id': 'xsht-toggle-' + key,
'class': 'xsht-button ' + status
}).css({
'width': '50px',
'height': '17px',
'border-radius': '20px',
'background-image': 'url("https://puu.sh/o9HHe/afc2d04137.png")',
'background-size': '114px 18px',
'background-position': '-17px',
'transition': 'background-position 0.5s'
}).click(function() {
$(this).toggleClass('activated');
changeFeatureStatus(key);
});
var tColTwo = $(' ').append(toggleButton);
var tRow = $(' | ').append(tColOne).append(tColTwo);
return tRow;
}
/*
* Building a Table Row containing the release date of the feature
* @param {String} date
* @returns {HTMLTableRow}
*/
var buildReleaseDateRow = function(date) {
var tColOne = $('').text('Release Date: ').css('font-weight', 'bold');
var tColTwo = $(' | ').text(date);
var tRow = $(' | ').append(tColOne).append(tColTwo);
return tRow;
}
/*
* Building a Table Row containing the description of the feature
* @param {String} data
* @returns {HTMLTableRow}
*/
var buildDescriptionRow = function(data) {
var tColOne = $('').attr('colspan', 2).html(data).css({
'font-style': 'italic',
'padding-top': '10px'
});
var tRow = $(' | ').append(tColOne);
return tRow;
}
/*
* Building a Table Row containing a warning informing the user that he should reload the game
* @returns {HTMLTableRow}
*/
var buildWarningRow = function() {
var tColOne = $('').attr('colspan', 2).css({
'font-weight': 'bold',
'color': 'red'
}).text("Please reload the game in order to apply the changes!");
var tRow = $(' | ').append(tColOne);
return tRow;
}
/*
* Generating and opening the window. Eventually, you can open the window at a certain tab, otherwise it'll open at the most recent visited.
* @param {String} tab
*/
MagicWindow.open = function(tab) {
if (undefined === tab) tab = this.currentTab;
var tabclick = function(win, id) {
MagicWindow.showTab(id);
}
MagicWindow.window = wman.open("magicwindow", "Magic Window").setMiniTitle("Magic Window").setSize(420, 370);
$.each(MagicFeatures, function(key) {
var contentTable = $('').css('padding-top', '10px');
contentTable.append(buildToggleTableRow(key, MagicFeatures[key]["status"]));
contentTable.append(buildReleaseDateRow(MagicFeatures[key]["releaseDate"]));
contentTable.append(buildDescriptionRow(MagicFeatures[key]["description"]));
contentTable.append(buildWarningRow());
var par = $('').attr({
'class': 'magic-content',
'id': 'magic-' + key,
'display': 'none'
}).html(contentTable);
if(key === 'multipurchase' && Game.locale === 'de_DE')
console.log('MultiPurchase is apparently not legal on the German Server. Sorry! <3');
else
MagicWindow.window.addTab(' ', key, tabclick).appendToContentPane(par);
});
this.showTab(tab);
};
/*
* Using this method to change between the active tabs, for the window. Should not be ran unless the window is open.
* @param {String} id
*/
MagicWindow.showTab = function(id) {
if (!this.window) return;
this.currentTab = id;
this.window.activateTab(id);
$.each($('#magic-' + id).parent().children(), function() {
var elID = $(this).attr('id');
if (elID != "magic-" + id)
$(this).hide();
else
$(this).slideDown('1000');
});
this.window.setTitle(MagicFeatures[id]["fullName"]);
this.window.setMiniTitle(MagicFeatures[id]["fullName"]);
};
/*
* Creating a button used to open the window.
*/
var initialiseButton = function() {
var icon = $(' ').attr({
'title': 'Magic Menu',
'class': 'menulink'
}).css({
'background': 'url("http://puu.sh/gbV7X/4703da6942.png")',
'background-position': '0px 0px'
}).mouseleave(function() {
$(this).css("background-position", "0px 0px");
}).mouseenter(function(e) {
$(this).css("background-position", "25px 0px");
}).click(function() {
MagicWindow.open('notifications');
});
var cap = $(' ').attr({
'class': 'menucontainer_bottom'
});
$("#ui_menubar").append($(' ').attr({
'class': 'ui_menucontainer',
'id': 'magicbundle_init_button'
}).append(icon).append(cap));
}
/*
* Registering the userscript to the game API.
*/
var registerToWestApi = function() {
scriptInfo = " Features:";
$.each(MagicFeatures, function(key) {
scriptInfo += " " + MagicFeatures[key]["fullName"] + ": ";
if(MagicFeatures[key]["status"] === "activated") {
scriptInfo += "" + MagicFeatures[key]["status"] + "";
} else {
scriptInfo += "" + MagicFeatures[key]["status"] + "";
}
});
scriptInfo += "Originally built by xShteff";
scriptInfo += "If you want to contribute to any of my scripts you are welcome to contact me on GitHub. ";
window.scriptyscript = {
script: TheWestApi.register('twmagicbundle', 'The West Magic', '2.1', Game.version.toString(), 'xShteff', 'https://xshteff.github.io'),
setGui: function() {
this.script.setGui(scriptInfo);
},
init: function() {
this.setGui();
}
};
window.scriptyscript.init();
}
/*
* Initialising the localstorage, registering the script to the API and adding the button.
*/
var initialiseScript = function() {
initialiseStorage();
registerToWestApi();
initialiseButton();
}
initialiseScript();
}).toString() + ')()';
document.head.appendChild(script);
| |