// ==UserScript== // @name InstaSynchP Poll Menu // @namespace InstaSynchP // @description Improves the poll menu // @version 1.0.3 // @author Zod- // @source https://github.com/Zod-/InstaSynchP-Poll-Menu // @license MIT // @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, url) { "use strict"; this.version = version; this.name = 'InstaSynchP Poll Menu'; 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.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-div').length < poll.options.length) { while (poll.options.length > $('#create-poll > .create-poll-option-div').length) { $('#add-poll-options').click(); } } //set the title $('#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://rawgit.com/Zod-/InstaSynchP-Poll-Menu/5214823bc1a16de90f0134c0794efaa9b24494a7/pollMenu.css', 'autoload': true }); function enableDisableButtons() { $('.remove-poll-options').attr('disabled', $('#create-poll .create-poll-option-div').length <= 1 ); $('.add-poll-options').attr('disabled', $('#create-poll > .create-poll-option-div').length >= 10 ); } function removeOption(index) { var sel = '#create-poll .create-poll-option-div'; $(sel).eq(index).remove(); enableDisableButtons(); } function addOption(index) { var sel = '#create-poll > .create-poll-option-div'; var pollOptionElement = $('
', { 'class': 'create-poll-option-div' }).append( $('', { 'class': 'formbox create-poll-option', 'placeholder': 'Option' }) ).append( $('