-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
116 lines (95 loc) · 3 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
var BG = chrome.extension.getBackgroundPage();
var pluginsContainer = $('#plugins');
var pluginsSettingsLoaded = {};
for (var pluginId in mbkPluginsList) {
pluginInfo = mbkPluginsList[pluginId];
pluginHtmlRow = '<li class="menu-entry" id="plugin_container_' + pluginId + '"><input type="checkbox" id="plugin_switcher_' + pluginId + '"> ' + pluginInfo.name + '</li>';
pluginHtmlRow += '<li class="menu-entry-settings" id="plugin_settings_' + pluginId + '" class="menu-settings"></li>';
pluginsContainer.append(pluginHtmlRow);
if (localStorage['plugin_' + pluginId] === '1') {
activatePlugin(pluginId);
if (pluginInfo.settings == true) {
showPluginSettings(pluginId);
}
}
}
//
function activatePlugin(pluginId) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {'type': 'startPlugin', 'pluginId': pluginId}, function(response) {});
});
$('#plugin_switcher_' + pluginId).attr('checked', true);
}
//
function deactivatePlugin(pluginId) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {'type': 'stopPlugin', 'pluginId': pluginId}, function(response) {});
});
$('#plugin_switcher_' + pluginId).attr('checked', false);
}
//
function restartPlugin(pluginId) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.tabs.sendMessage(tabs[0].id, {'type': 'restartPlugin', 'pluginId': pluginId}, function(response) {});
});
}
//
function hidePluginSettings(pluginId)
{
$('#plugin_settings_' + pluginId).hide();
}
//
function showPluginSettings(pluginId)
{
if (pluginsSettingsLoaded[pluginId] !== true) {
pluginsSettingsLoaded[pluginId] = true;
loadPluginSettingsJs(pluginId);
}
$('#plugin_settings_' + pluginId).show();
}
//
function loadPluginSettingsJs(pluginId) {
var script = document.createElement('script');
script.src = 'plugins/' + pluginId + '/' + pluginId + '_settings.js';
document.head.appendChild(script);
}
// Click handlers
$(function() {
$(".menu-entry").click(function() {
var pluginId = $(this).attr('id').replace('plugin_container_', '');
var pluginStatus = localStorage['plugin_' + pluginId];
if (pluginStatus === '1') {
localStorage['plugin_' + pluginId] = '0';
deactivatePlugin(pluginId);
if (mbkPluginsList[pluginId].settings == true) {
hidePluginSettings(pluginId);
}
}
else {
localStorage['plugin_' + pluginId] = '1';
activatePlugin(pluginId);
if (mbkPluginsList[pluginId].settings == true) {
showPluginSettings(pluginId);
}
}
});
//var checked = $(this).is(":checked");
});
// custom functions
//
function getUser() {
var id = $.cookie('battle');
var userParams = {};
jQuery.ajax({
url: 'http://mycombats.org/inf.php?' + id + '&short=1',
success: function(data) {
var params = data.replace("\r", '').split("\n");
for (var i = 0; i < params.length; i++) {
var param = params[i].split('=');
userParams[param[0]] = param[1];
}
},
async: false
});
return userParams;
}