Adds functionality to tf2pug.me
当前为
// ==UserScript==
// @name Easy PugMe
// @author deetr
// @namespace http://deetr.me
// @description Adds functionality to tf2pug.me
// @include http://www.tf2pug.me/
// @version 1.14
// @grant GM_setValue
// @grant GM_listValues
// @grant GM_getValue
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js
// ==/UserScript==
var easyPugDiv = document.createElement("div");
easyPugDiv.id = "easyPugDiv";
easyPugDiv.style.margin = "auto";
easyPugDiv.style.width = "98%";
var playerCountDiv = document.getElementById('classcheckboxes');
playerCountDiv.parentNode.insertBefore(easyPugDiv, playerCountDiv.nextSibling);
var combatButton = document.createElement("input");
combatButton.type = "button";
combatButton.value = "Add Combat";
combatButton.onclick = addCombat;
easyPugDiv.appendChild(combatButton);
var soldierButton = document.createElement("input");
soldierButton.type = "button";
soldierButton.value = "Add Soldier";
soldierButton.onclick = addSoldier;
easyPugDiv.appendChild(soldierButton);
var favButton = document.createElement("input");
favButton.type = "button";
favButton.value = "Add favs";
favButton.onclick = addUpFavs;
easyPugDiv.appendChild(favButton);
var removeButton = document.createElement("input");
removeButton.type = "button";
removeButton.value = "Remove";
removeButton.onclick = removeAll;
easyPugDiv.appendChild(removeButton);
var middleSpan = document.createElement("span");
middleSpan.id = "middleSpan";
middleSpan.innerHTML = '<a href = "https://greasyfork.org/en/scripts/9404-easy-pugme"><img src = "http://i.imgur.com/V8QkBtQ.png" width = 32px height = 32px></a> ';
easyPugDiv.appendChild(middleSpan);
var dropdownSelect = $("<select>").text('Add to favourites').attr({
id: 'favDropdown',
name: 'favDropdown'
});
var option = $('<option> value ="Scout"').text("Scout");
option.appendTo(dropdownSelect);
option = $('<option> value="Pocket"').text("Pocket");
option.appendTo(dropdownSelect);
option = $('<option> value="Roamer"').text("Roamer");
option.appendTo(dropdownSelect);
option = $('<option> value="Demo"').text("Demo");
option.appendTo(dropdownSelect);
option = $('<option> value="Medic"').text("Medic");
option.appendTo(dropdownSelect);
option = $('<option> value="Captain"').text("Captain");
option.appendTo(dropdownSelect);
dropdownSelect.appendTo(easyPugDiv);
var addFavButton = document.createElement("input");
addFavButton.type = "button";
addFavButton.value = "Add to favs";
addFavButton.onclick = addFav;
easyPugDiv.appendChild(addFavButton);
var removeFavButton = document.createElement("input");
removeFavButton.type = "button";
removeFavButton.value = "Remove from favs";
removeFavButton.onclick = removeFav;
easyPugDiv.appendChild(removeFavButton);
var clearFavButton = document.createElement("input");
clearFavButton.type = "button";
clearFavButton.value = "Clear favs";
clearFavButton.onclick = clearFav;
easyPugDiv.appendChild(clearFavButton);
var favDiv = document.createElement("div");
favDiv.id = "favDiv";
favDiv.innerHTML = '<span id="confirmSpan">Favourite added</span>';
easyPugDiv.appendChild(favDiv);
$("#favDiv").css("visibility", "hidden");
function addCombat() {
if (unsafeWindow.username != null) {
if (!$("#chkScout").is(':checked')) {
$("#chkScout").click();
}
if (!$("#chkPocket").is(':checked')) {
$("#chkPocket").click();
}
if (!$("#chkRoamer").is(':checked')) {
$("#chkRoamer").click();
}
if (!$("#chkDemo").is(':checked')) {
$("#chkDemo").click();
}
} else {
alert("You aren't logged in");
}
}
function addSoldier() {
if (unsafeWindow.username != null) {
if (!$("#chkPocket").is(':checked')) {
$("#chkPocket").click();
}
if (!$("#chkRoamer").is(':checked')) {
$("#chkRoamer").click();
}
} else {
alert("You aren't logged in");
}
}
function removeAll() {
if (unsafeWindow.game.mode == "picking") {
alert("Cannot remove while picking in progress");
} else if (unsafeWindow.username != null) {
if ($("#chkScout").is(':checked')) {
$("#chkScout").click();
}
if ($("#chkPocket").is(':checked')) {
$("#chkPocket").click();
}
if ($("#chkRoamer").is(':checked')) {
$("#chkRoamer").click();
}
if ($("#chkDemo").is(':checked')) {
$("#chkDemo").click();
}
if ($("#chkMedic").is(':checked')) {
$("#chkMedic").click();
}
if ($("#chkCaptain").is(':checked')) {
$("#chkCaptain").click();
}
} else {
alert("You aren't logged in");
}
}
function addFav() {
var newFav = $('#favDropdown').val();
// Using booleans because GM doesn't support storing arrays :/
if (newFav == "Scout") {
GM_setValue("scoutFav", true);
} else if (newFav == "Pocket") {
GM_setValue("pocketFav", true);
} else if (newFav == "Roamer") {
GM_setValue("roamerFav", true);
} else if (newFav == "Demo") {
GM_setValue("demoFav", true);
} else if (newFav == "Medic") {
GM_setValue("medicFav", true);
} else if (newFav == "Captain") {
GM_setValue("captainFav", true);
}
$('#confirmSpan').text(newFav + " added to favourites").css('color', 'green');
$('#confirmSpan').hide().css({
visibility: "visible"
}).fadeIn("fast").delay(1000).fadeOut("fast", function() {
$(this).show().css({
visibility: "hidden"
});
});
}
function addUpFavs() {
if (unsafeWindow.username != null) {
var vals = GM_listValues();
if (vals.indexOf("scoutFav") > -1) {
if (GM_getValue("scoutFav")) {
alert("aa");
if (!$("#chkScout").is(':checked')) {
$("#chkScout").click();
}
}
}
if (vals.indexOf("pocketFav") > -1) {
if (GM_getValue("pocketFav")) {
if (!$("#chkPocket").is(':checked')) {
$("#chkPocket").click();
}
}
}
if (vals.indexOf("roamerFav") > -1) {
if (GM_getValue("roamerFav")) {
if (!$("#chkRoamer").is(':checked')) {
$("#chkRoamer").click();
}
}
}
if (vals.indexOf("demoFav") > -1) {
if (GM_getValue("demoFav")) {
if (!$("#chkDemo").is(':checked')) {
$("#chkDemo").click();
}
}
}
if (vals.indexOf("medicFav") > -1) {
if (GM_getValue("medicFav")) {
if (!$("#chkMedic").is(':checked')) {
$("#chkMedic").click();
}
}
}
if (vals.indexOf("captainFav") > -1) {
if (GM_getValue("captainFav")) {
if (!$("#chkCaptain").is(':checked')) {
$("#chkCaptain").click();
}
}
}
} else {
alert("You aren't logged in");
}
}
function removeFav() {
var oldFav = $('#favDropdown').val();
if (oldFav == "Scout") {
GM_setValue("scoutFav", false);
} else if (oldFav == "Pocket") {
GM_setValue("pocketFav", false);
} else if (oldFav == "Roamer") {
GM_setValue("roamerFav", false);
} else if (oldFav == "Demo") {
GM_setValue("demoFav", false);
} else if (oldFav == "Medic") {
GM_setValue("medicFav", false);
} else if (oldFav == "Captain") {
GM_setValue("captainFav", false);
}
$('#confirmSpan').text(oldFav + " removed from favourites").css('color', 'red');
$('#confirmSpan').hide().css({
visibility: "visible"
}).fadeIn("fast").delay(1000).fadeOut("fast", function() {
$(this).show().css({
visibility: "hidden"
});
});
}
function clearFav() {
GM_setValue("pocketFav", false);
GM_setValue("roamerFav", false);
GM_setValue("demoFav", false);
GM_setValue("medicFav", false);
GM_setValue("captainFav", false);
$('#confirmSpan').text("Cleared favourites").css('color', 'red');
$('#confirmSpan').hide().css({
visibility: "visible"
}).fadeIn("fast").delay(1000).fadeOut("fast", function() {
$(this).show().css({
visibility: "hidden"
});
});
}