Something Awful Forums functions.
Από την
// ==UserScript==
// @name SA Buttons
// @namespace http://uberg.nu/
// @version 1.31
// @description Something Awful Forums functions.
// @author Ubergnu
// @match https://forums.somethingawful.com/*
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
// Some UI values
var BUTTON_TEXT_COLOR = "#444444";
var BUTTON_TEXT_COLOR_ACTIVE = "#DDDDDD";
var BUTTON_BACKGROUND = "";
var BUTTON_BACKGROUND_ACTIVE = "#888888";
var ELEM_VISIBLE = 1;
var ELEM_HIDDEN = 0;
var ELEM_DIMMED = 0.3;
// This is global because GM_getValue() is borked in events
var avatarState;
// Completly hide ignored users posts.
//$("a[title=\"DON'T DO IT!!\"]").parent().parent().parent().parent().hide();
$("a[title=\"DON'T DO IT!!\"]").parent().eq(3).hide();
// Add Menu buttons
//
$("#content #thread .profilelinks").append("<li class='liStop btnStop'>Stop</li>");
$("#content #thread .profilelinks").append("<li class='liStop btnFold'>Fold</li>");
$("#content #thread .profilelinks").append("<li class='liStop btnFade'>Avs</li>");
$("#content #thread .profilelinks").append("<li class='liStop btnCtrl'>Buts</li>");
$("#content #thread .profilelinks").append("<li class='liStop btnProb'>Prob</li>");
// Insert CSS into <head> on page.
//
function addCss(cssString) {
var s = "";
s += ".btnClosePopup {";
s += "font-family: 'Roboto',sans-serif; !important";
s += "border: none !important;";
s += "outline: 0 !important;";
s += "background-color: #3b6d7d !important;";
s += "color: #EEEEEE !important;";
s += "border-radius: 6px !important;";
s += "width: 120px !important;";
s += "height: 30px !important;";
s += "margin-top: 5px !important;";
s += "float: right !important;";
s += "}";
s += ".btnClosePopup:hover {";
s += "background-color: #red !important;";
s += "color: #000000! important;";
s += "}";
s += ".msgContent {";
s += "font-family: 'Roboto',sans-serif;";
s += "font-size: 14px;";
s += "width: 412px;";
s += "height: 154px;";
s += "background-color: #FFFFFF;";
s += "margin: 0 auto;";
s += "padding: 5px;";
s += "border-radius: 5px; ";
s += "}";
s += ".msgPopup {";
s += "background-color: #3b6d7d;";
s += "border-radius: 10px;";
s += "padding-top: 10px;";
s += "display:none;";
s += "}";
s += "#thread ul.profilelinks li:nth-last-of-type(-n+5) { ";
s += "max-height: 15px !important; ";
s += "padding: 0px 13px 10px 13px !important; ";
s += "margin: 5px 0px 10px 0px; ";
s += "line-height: 25px !important; ";
s += "}";
var head = document.getElementsByTagName('head')[0];
//return unless head;
var newCss = document.createElement('style');
newCss.type = "text/css";
//newCss.innerHTML = cssString;
newCss.innerHTML = s;
head.appendChild(newCss);
}
//addCss('#thread ul.profilelinks li:nth-last-of-type(-n+4) { max-height: 15px !important; padding: 0px 13px 10px 13px !important; margin: 5px 0px 10px 0px; line-height: 25px !important; }');
addCss('');
// Menu buttons layout
//
var li = $(".postlinks .liStop");
li.css({
"border-radius": "11px",
"position": "relative",
"font-size": "11px",
"height": "22px !important",
"padding": "2px",
"margin": "0px 0 0px 0 !important;",
"cursor": "pointer",
"color": BUTTON_TEXT_COLOR
});
li.hover(
function(){
//$(this).css("background-color", BUTTON_BACKGROUND_ACTIVE);
$(this).css("color", BUTTON_TEXT_COLOR_ACTIVE);
$(this).css("height", "20px !important;");
$(this).css("max-height", "20px !important;");
$(this).css("border-radius", "10px;");
$(this).animate({backgroundColor: BUTTON_BACKGROUND_ACTIVE}, 'fast',
function(){
if (!$(this).is(":hover"))
li.css("background-color", BUTTON_BACKGROUND);
}
);
}, function() {
li.css("background-color", BUTTON_BACKGROUND);
li.css("color", BUTTON_TEXT_COLOR);
}
);
// Prob button click.
//
$(".postlinks ul .btnProb").click(function(){
//var time = $(this).parent().parent().parent().children(":first").text().trim();
//time = time.substr(time.length - 5)
// Check if the user was banned/probed in this post. If so, call showProbInfo().
var probContent = $(this).parents().eq(3).find('td[class="postbody"]').find('b').last();
var linkAddress = "";
if (typeof probContent.html() === "undefined")
{
var userID = $(this).parents().eq(2).find('td').eq(0).find('a').eq(1).attr('href');
var parts = userID.split("=");
userID = parts[2];
linkAddress = "/banlist.php?userid=" + userID;
showProbInfo(linkAddress);
}
else
{
var link = $(probContent).find('a');
if (typeof link != 'undefined' && $(link).text().startsWith('(USER WAS'))
{
linkAddress = $(link).attr('href');
showProbInfo(linkAddress);
//alert(linkAddress);
}
}
});
// Show popup with ban/probation reason (if the user ate a probe in that post).
//
function showProbInfo(address) {
// Get text from the Leper's Colony page.
$.get(address, function (data) {
$(".result").html(data);
var infoText = $('a[name="list"]', $(data)).nextAll().eq(0).children(":first").children('tr').eq(1).children('td').eq(3).text();
// HTML for the popup.
var win = "<div class='msgPopup' id='msgPopupWindow'>";
win += "<p class='msgContent' id='msgPopupContent'>";
win += infoText;
win += "</p></div>";
// Insert popup HTML in page.
var html = $.parseHTML(win);
$("#something_awful").append(html);
// Open dialog window.
$(html).dialog({
autoOpen: true,
width: 450,
height: 300,
modal: true,
resizable: true,
open: function(event, ui) {
// Clear all classes from jquery dialog.
var main = $("div[aria-describedby='msgPopupWindow']");
$(main).removeClass();
$(main).find("div").removeClass();
$(main).find("button").removeClass();
// Add own classes
$(".ui-dialog-titlebar-close", ui.dialog | ui).hide();
$(".msgContent").html(infoText);
$("#msgPopupWindow").addClass('msgPopup');
$("#msgPopupContent").addClass('msgContent');
$(main).find("button").addClass('btnClosePopup');
$(main).find("button").eq(0).hide();
},
buttons: [
{
text: "Close",
"class": 'btnClosePopup',
click: function () {
$(this).dialog("close");
$("#msgPopupWindow").remove();
}
},
],
});
});
}
// Stop avatar animations
//
$(".postlinks ul .btnStop").click(function(){
var avs = $(".title img");
for(i=0; i<avs.length; i++)
setFirstFrame(avs[i], i);
gmSetValue("SA_animations", false);
});
// Toggle dim/hide/show all avatars
//
$(".postlinks ul .btnFade").click(function(){
if (avatarState == "on"){
$(".title img").animate({opacity: ELEM_DIMMED});
$(".title canvas").animate({opacity: ELEM_DIMMED});
gmSetValue("SA_avatars", "dim");
avatarState = "dim";
}
else if(avatarState == "dim"){
$(".title img").animate({opacity: ELEM_HIDDEN});
$(".title canvas").animate({opacity: ELEM_HIDDEN});
gmSetValue("SA_avatars", "off");
avatarState = "off";
}
else if(avatarState == "off"){
$(".title img").animate({opacity: ELEM_VISIBLE});
$(".title canvas").animate({opacity: ELEM_VISIBLE});
gmSetValue("SA_avatars", "on");
avatarState = "on";
}
});
// Remove special titles.
//
$(".special_title").hide();
// Toggle visibility for report/quote buttons
//
$(".postlinks ul .btnCtrl").toggle(
function(){
$(".postlinks .postbuttons").children().animate({opacity: ELEM_VISIBLE});
gmSetValue("SA_reportButtons", true);
}, function(){
$(".postlinks .postbuttons").children().animate({opacity: ELEM_HIDDEN});
gmSetValue("SA_reportButtons", false);
}
);
// Hide/show posts
//
$(".postlinks ul .btnFold").click(function () {
$(this).parents().eq(2).prev().find("dl[class='userinfo']").slideToggle(300);
$(this).parents().eq(2).prev().children().last().slideToggle(300);
//$(this).parents().eq(2).prev().children().first().children().first().children().slideToggle(500);
});
// #########################################################################################
// Stop avatar animations if set
//
if (!GM_getValue("SA_animations", true))
{
var avs = $(".title img");
for(i=0; i<avs.length; i++)
{
setFirstFrame(avs[i]);
//console.log(avs[i]);
}
}
// Hide/show Report/Quote buttons depending on settings
//
if (GM_getValue("SA_reportButtons", false))
$(".postlinks .postbuttons").children().animate({opacity: ELEM_VISIBLE});
else
$(".postlinks .postbuttons").children().animate({opacity: ELEM_HIDDEN});
// Hide/show avatars depending on settings
//
avatarState = GM_getValue("SA_avatars");
switch(avatarState)
{
case "on":
$(".title img").animate({opacity: ELEM_VISIBLE});
$(".title canvas").animate({opacity: ELEM_VISIBLE});
GM_setValue("SA_avatars", "on");
break;
case "off":
$(".title img").animate({opacity: ELEM_HIDDEN});
$(".title canvas").animate({opacity: ELEM_HIDDEN});
GM_setValue("SA_avatars", "off");
break;
case "dim":
$(".title img").animate({opacity: ELEM_DIMMED});
$(".title canvas").animate({opacity: ELEM_DIMMED});
GM_setValue("SA_avatars", "dim");
break;
default:
$(".title img").animate({opacity: ELEM_VISIBLE});
$(".title canvas").animate({opacity: ELEM_VISIBLE});
GM_setValue("SA_avatars", "on");
break;
}
// Hide the whole user Title (avatar+text+tags)
//
$(".postlinks ul .btnText").click(function(){
//var userTitle = $(this).parent().parent().parent().parent().find(".userinfo .title");
var userTitle = $(this).parents().eq(3).find(".userinfo .title");
var opa;
if (avatarState == "on"){ opa = ELEM_VISIBLE; }
else if(avatarState == "dim"){ opa = ELEM_DIMMED; }
else if(avatarState == "off"){ opa = ELEM_HIDDEN; }
if (userTitle.css('opacity') == ELEM_HIDDEN) {
userTitle.animate({ opacity: opa });
}else{
userTitle.animate({ opacity: ELEM_HIDDEN });
}
});
// -------------------------------------------
// Misc stuff
// -------------------------------------------
// Stop avatar animations
//
function setFirstFrame (img, idx) {
var newCanvas = document.createElement("canvas");
newCanvas.height = img.height;
newCanvas.width = img.width;
newCanvas.id = "cnvAv";
newCanvas.getContext("2d").drawImage(img, 0, 0);
img.parentNode.replaceChild(newCanvas, img);
if (avatarState == "on")
$(newCanvas).animate({opacity: ELEM_VISIBLE});
else if(avatarState == "dim")
$(newCanvas).animate({opacity: ELEM_DIMMED});
else if(avatarState == "off")
$(newCanvas).animate({opacity: ELEM_HIDDEN});
}
function replaceImg (img, ref) {
//console.log('REF: ' + ref);
img.onload = ref;
img.src += '#';
}
// Workaround for getting/setting values from inside an event
//
function gmSetValue(key, val)
{
setTimeout(function() {
GM_setValue(key, val);
}, 0);
}
function gmGetValue(key, defaultval)
{
setTimeout(function() {
avatarState = GM_getValue(key, defaultval);
}, 0);
return avatarState;
}