// ==UserScript==
// @name InstaSynchP Poll Menu
// @namespace InstaSynchP
// @description Improves the poll menu
// @version 1.0.1
// @author Zod-
// @source https://github.com/Zod-/InstaSynchP-Poll-Menu
// @license GPL-3.0
// @include http://*.instasynch.com/*
// @include http://instasynch.com/*
// @include http://*.instasync.com/*
// @include http://instasync.com/*
// @grant none
// @run-at document-start
// @require https://greasyfork.org/scripts/5647-instasynchp-library/code/InstaSynchP%20Library.js
// @downloadURL none
// ==/UserScript==
function PollMenu(version) {
"use strict";
this.version = version;
this.oldPolls = [{
'title': '',
'options': [{
'option': '',
'votes': 0
}]
}];
this.index = 0;
}
PollMenu.prototype = {
get index() {
return this._index % this.oldPolls.length;
},
set index(value) {
if (value < 0) {
value = this.oldPolls.length - 1;
}
this._index = value;
}
};
PollMenu.prototype.addOption = function () {
"use strict";
$('#create-poll').append(
$('', {
'class': 'formbox create-poll-option',
'placeholder': 'Option'
})
).append($('
'));
};
PollMenu.prototype.removeOption = function () {
"use strict";
$('#create-poll > :last-child').remove();
$('#create-poll > :last-child').remove();
};
PollMenu.prototype.copyOld = function (poll) {
"use strict";
var i = 0;
$('#clear-poll-options').click();
//add more rows until we got enough to fit the old poll
if ($('#create-poll > .create-poll-option').length < poll.options.length) {
while (poll.options.length > $('#create-poll > .create-poll-option').length) {
$('#add-poll-options').click();
}
}
//set the title
$('#create-poll > #title').val(htmlDecode(poll.title));
//set the options
$(".create-poll-option").each(function () {
$(this).val(htmlDecode(poll.options[i].option));
i += 1;
if (i >= poll.options.length) {
return false;
}
});
};
PollMenu.prototype.preConnect = function () {
"use strict";
var th = this;
cssLoader.add({
'name': 'poll-menu',
'url': 'https://cdn.rawgit.com/Zod-/InstaSynchP-Poll-Menu/eb259a8da965853880a019ae749fcb08b5c3945f/pollMenu.css',
'autoload': true
});
//recreate the poll menu to add +, -, copy old and clear buttons
//at the top rather than the bottom so they don't move down when adding
//more rows
$('#create-pollBtn').text('Poll Menu');
$('#create-poll').empty().append(
$('