Raw Source
Fireblend / MafiEraVoteTool

// ==UserScript==
// @name        MafiEraVoteTool
// @version     3
// @namespace   http://www.fireblend.com/
// @updateURL   https://openuserjs.org/meta/Fireblend/era_userscript.meta.js
// @downloadURL https://openuserjs.org/src/scripts/Fireblend/era_userscript.user.js
// @license     MIT
// @icon        https://media.discordapp.net/attachments/165286383257255936/429860317649174529/imageedit__4571108207.png
// @homepageURL http://www.fireblend.com/
// @author      Sergio Morales
// @description The MafiEra Vote Tool, made easier!
// @include     http*://www.resetera.com/threads/*
// @include     http*://www.resetera.com/threads/*/*
// @require     https://code.jquery.com/ui/1.12.1/jquery-ui.js
// @require     http://code.jquery.com/ui/1.11.4/jquery-ui.js
// @resource    customCSS https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css
// @run-at      document-idle
// @grant       GM_addStyle
// @grant       GM_getResourceText
// ==/UserScript==

(function () {
  'use strict';

  function addButton() {
    var buttonLocations1 = document.querySelectorAll('fieldset.breadcrumb');
    var buttonLocations2 = document.querySelectorAll('div.PageNav');
    if (buttonLocations1.length > 0) {
      var a1 = makeButtonOld();
      buttonLocations1[0].appendChild(a1);
      var b1 = makeButtonOld();
      buttonLocations1[2].appendChild(b1);
    }
    else if (buttonLocations2.length > 3) {
      var a2 = makeButton();
      buttonLocations2[1].appendChild(a2);
      var b2 = makeButton();
      buttonLocations2[3].appendChild(b2);
    }
    else if (buttonLocations2.length < 3) {
      var a2 = makeButton();
      buttonLocations2[0].appendChild(a2);
      var b2 = makeButton();
      buttonLocations2[1].appendChild(b2);
    }
  }

  function openDialog() {
    var url = window.location.href;
    var page = "https://vote.fireblend.com/" + url.split("/threads/")[1].split("/")[0] + "/simple";

    var $dialog = $('<div></div>')
      .html('<iframe id="myDialog" style="background-color: #ffffff; border: 0px; " src="' + page + '" width="100%" height="100%"></iframe>')
      .dialog({
        autoOpen: false,
        modal: true,
        height: 600,
        width: 500,
        title: "MafiEra Vote Count",
        resizable: false
      });
    $dialog.dialog('open');
  }

  function makeButtonOld() {
    var a = document.createElement('span');
    var url = window.location.href;
    a.setAttribute('style', 'cursor:pointer;');
    a.setAttribute('class', "crumb bottomLink videob");
    a.addEventListener("click", openDialog, false);
    a.setAttribute('target', '_blank');
    a.appendChild(document.createTextNode("Vote Count"));
    return a;
  }

  function makeButton() {
    var a = document.createElement('a');
    var url = window.location.href;
    a.setAttribute('style', 'cursor:pointer;width="100%" height="100%";display: inline-block;');
    a.addEventListener("click", openDialog, false);
    a.setAttribute('target', '_blank');
    a.appendChild(document.createTextNode("Vote Count"));
    return a;
  }
  var newCSS = GM_getResourceText("customCSS");
  GM_addStyle(newCSS);
  GM_addStyle('.ui-dialog .ui-dialog-content { overflow: hidden; }');
  addButton();
})();