', {
class: 'tab-pane',
id: 'tabs_plugin_list_content'
})
);
};
Settings.prototype.createPluginFields = function () {
'use strict';
var _this = this;
Object.keys(_this.pluginNames).forEach(function (sectionName) {
var section = _this.pluginNames[sectionName];
section.forEach(function (pluginName, index) {
var id;
var disabled = false;
if (sectionName === 'Commands') {
id = 'InstaSynchP {0} Command'.format(pluginName);
} else {
id = 'InstaSynchP {0}'.format(pluginName);
}
if (sectionName === 'Core') {
disabled = true;
}
_this.pluginNames[sectionName][index] = id;
_this.fields.push({
id: id,
label: pluginName,
type: 'checkbox',
destination: 'plugin',
disabled: disabled,
'default': true,
section: [sectionName]
});
});
_this.plugins = _this.plugins.concat(_this.pluginNames[sectionName]);
});
_this.fields.push({
id: 'plugins-count',
type: 'int',
hidden: true,
'default': _this.plugins.length
});
};
Settings.prototype.disablePlugins = function () {
'use strict';
var _this = this;
Object.keys(window.plugins).forEach(function (pluginName) {
var plugin = window.plugins[pluginName];
plugin.enabled = _this.get(plugin.name.replace(/ /g, '-'), true);
});
};
Settings.prototype.collectSettings = function () {
'use strict';
var _this = this;
Object.keys(window.plugins).forEach(function (pluginName) {
var plugin = window.plugins[pluginName];
if (Array.isArray(plugin.settings)) {
_this.fields = _this.fields.concat(plugin.settings);
}
if (Array.isArray(plugin.styles)) {
plugin.styles.forEach(function (style) {
_this.fields.push({
label: '',
id: style.name + '-css-content',
type: 'text',
hidden: true,
value: '',
section: ['Core']
});
_this.fields.push({
label: '',
id: style.name + '-css-url',
type: 'text',
hidden: true,
value: '',
section: ['Core']
});
events.on(plugins.cssLoader, 'ExecuteOnce', function () {
plugins.cssLoader.addStyle(style);
});
});
}
});
};
Settings.prototype.persistentSettings = function () {
'use strict';
var _this = this;
events.on(_this, 'SettingChange[instasync-autosync]', function (ig, v) {
window.room.autosync = v;
if (v) {
sendcmd('resynch');
}
});
events.on(_this, 'SettingChange[instasync-yt-controls]', function (ig, v) {
window.room.showYTcontrols = v;
reloadPlayer();
});
events.on(_this, 'SettingChange[instasync-greynames-chat]', function (ig, v) {
window.room.filterGreyname = !v;
});
events.on(_this, 'SettingChange[instasync-disable-player]', function (ig, v) {
window.room.playerDisabled = v;
if (v) {
$('#media').html('');
} else {
reloadPlayer();
}
});
};
Settings.prototype.executeOnce = function () {
'use strict';
var _this = this;
function startTimer(timeString) {
if (_this.updateIntervalId) {
clearInterval(_this.updateIntervalId);
_this.updateIntervalId = undefined;
}
if (timeString === 'on refresh') {
return;
}
_this.updateIntervalId = setInterval(function () {
_this.searchPluginUpdates();
}, getTime(timeString) * 1000);
}
events.on(_this, 'SettingChange[update-timer]', function (ignore, newVal) {
_this.searchPluginUpdates();
startTimer(newVal);
});
startTimer(_this.get('update-timer'));
};
Settings.prototype.searchPluginUpdates = function () {
'use strict';
var _this = this;
var updatesCount = 0;
if (_this.get('plugins-count') !== _this.plugins.length) {
updatesCount += Math.abs(_this.get('plugins-count') - _this.plugins.length);
_this.set('plugins-count', _this.plugins.length);
}
function done() {
if (updatesCount > 0) {
$('.updates').text(updatesCount);
}
}
function updateLabel(data) {
if (!_this.plugins.contains(data.name)) {
return;
}
var url = data.url;
var label = '';
var name = '';
var install = '';
var version = '';
var info = '';
var feedback = '';
var plugin = {};
Object.keys(window.plugins).forEach(function (pluginName) {
var p = window.plugins[pluginName];
if (p.name === data.name) {
plugin = p;
}
});
name = data.name.replace(/^InstaSynchP/i, '')
.replace(/Command$/i, '').trim();
install = ('
{2}')
.format(url, 'code.user.js');
info = ('
info').format(url);
feedback = ('
{1}').format(url, 'feedback');
if (plugin.version) {
version = '
v{0}'
.format(plugin.version, '{0}');
if (plugin.version === data.version) {
install = '';
version = version.format('current_version_link');
} else {
updatesCount += 1;
install = install.format('', '', 'update');
version = version.format('outdated_version_link');
}
} else {
install = install.format('', '', 'install');
}
if (_this.pluginNames.Core.contains(data.name) && name !== 'Core') {
install = '';
}
label = '{0} {1} {2} {3} {4}'
.format(name, version, install, info, feedback).replace(/\s+/, ' ');
_this.fields[data.name.replace(/ /g, '-')].setLabel(label);
_this.fields[data.name.replace(/ /g, '-')].setTitle(data.description);
}
$.getJSON('https://greasyfork.org/en/scripts.json?set=1666', function (data) {
data.forEach(function (plugin) {
updateLabel(plugin);
});
done();
});
};
Settings.prototype.executeOnceCore = function () {
'use strict';
var _this = this;
_this.collectSettings();
_this.removeInstaSyncSettings();
_this.persistentSettings();
_this.createPluginTab();
_this.createPluginFields();
_this.createResetButtons();
_this.createFields();
_this.addFieldsToSite();
_this.disablePlugins();
_this.searchPluginUpdates();
$('#tabs_playlist_settings').append(
$('#tabs_playlist_settings .mod-control').detach()
);
};
Settings.prototype.reset = function (destination) {
'use strict';
this.forEachField(function (destinationPair, sectionPair, field) {
if (destinationPair.name === destination && !field.hidden) {
field.set(field.default);
}
});
};
Settings.prototype.log = function (opts) {
'use strict';
var args = [];
opts.type = opts.type || 'debug';
args.push(this.name);
args.push(opts.event);
logger()[opts.type].apply(logger(), args);
};
Settings.prototype.get = function (id, fallback) {
'use strict';
var _this = this;
if (!_this.fields.hasOwnProperty(id)) {
_this.log({
event: 'getting a setting that does not exist ' + id,
type: 'warn'
});
return fallback;
}
return _this.fields[id].get();
};
Settings.prototype.set = function (id, newVal) {
'use strict';
var _this = this;
if (_this.fields.hasOwnProperty(id)) {
_this.fields[id].set(newVal);
} else {
_this.log({
event: 'setting a setting that does not exist ' + id,
type: 'warn'
});
}
};
Settings.prototype.save = function () {
'use strict';
};
window.plugins = window.plugins || {};
window.plugins.settings = new Settings();
//TODO remove after removing references in other plugins
window.gmc = window.plugins.settings;