Skip to content

Instantly share code, notes, and snippets.

@TheAndrey
Last active September 29, 2023 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheAndrey/7d9b4ed9781aea6e927481df59b9c5c0 to your computer and use it in GitHub Desktop.
Save TheAndrey/7d9b4ed9781aea6e927481df59b9c5c0 to your computer and use it in GitHub Desktop.
Кнопка голосования для TopCraft & MCTOP
// ==UserScript==
// @name Кнопка голосования для TopCraft & MCTOP
// @namespace http://theandrey.name/
// @version 1.0
// @description Добавляет кнопку голосования на страницу своего проекта
// @author TheAndrey
// @match https://mctop.su/servers/*
// @match https://topcraft.ru/servers/*
// @match https://topcraft.club/servers/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=topcraft.club
// @grant none
// @run-at document-end
// ==/UserScript==
(function () {
'use strict';
const urlRegex = /\/servers\/(\d+)\/?/;
const wrapper = document.querySelector('.project-btn__vote-btn');
const openVoteModal = (project_id, project_name) => {
const $vote_modal = $('#voteModal');
$vote_modal.modal('show').one('hidden.bs.modal', function () {
var $nick = $vote_modal.find('[name="nick"]');
var $vote_btn = $vote_modal.find('.voteBtn');
$nick.tooltip('destroy').val('');
$vote_btn.tooltip('destroy');
});
$vote_modal.find('.projectName').text(project_name);
$vote_modal.find('input[name="project_id"]').val(project_id);
};
if (urlRegex.test(window.location.href)) {
const matches = window.location.href.match(urlRegex);
const projectId = matches[1];
if (wrapper && !wrapper.querySelector('.openVoteModal')) {
const button = document.createElement('button');
button.type = 'button';
button.className = 'btn btn-info btn-vote';
button.innerHTML = '<i class="fa fa-thumbs-up" aria-hidden="true"></i> Голосовать';
button.addEventListener('click', event => {
event.preventDefault();
openVoteModal(projectId, 'Мой лучший проект');
});
wrapper.textContent = '';
wrapper.appendChild(button);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment