Last active
September 29, 2023 22:56
-
-
Save TheAndrey/7d9b4ed9781aea6e927481df59b9c5c0 to your computer and use it in GitHub Desktop.
Кнопка голосования для TopCraft & MCTOP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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