// ==UserScript== // @name InstaSynchP Poll Menu // @namespace InstaSynchP // @description Improves the poll menu // @version 1.0.2 // @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, 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://cdn.rawgit.com/Zod-/InstaSynchP-Poll-Menu/8a21e16d6e4238205df1eca353f2a46fb39c26ac/pollMenu.css', 'autoload': true }); function removeOption(index) { if ($('#create-poll > .create-poll-option-div').length <= 1) { return; } //readd the + button on the last element if ($('#create-poll > .create-poll-option-div').length === 10) { if ($('#create-poll > :last-child').children().length === 2) { $('#create-poll > :last-child').children().eq(0).after( $('