Skip to content

Instantly share code, notes, and snippets.

@klepto
Created September 15, 2016 06:59
Show Gist options
  • Select an option

  • Save klepto/dbf592a221efa950de11832d33e59395 to your computer and use it in GitHub Desktop.

Select an option

Save klepto/dbf592a221efa950de11832d33e59395 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name ShoutboxAdvanced
// @version 0.3
// @namespace ShoutboxAdvanced
// @description Advanced shoutbox mod for Rune-Server.
// @include http://www.rune-server.org/forums.php*
// @require http://userscripts.org/scripts/source/85365.user.js
// ==/UserScript==
var $ = unsafeWindow.jQuery;
function shoutboxAdvanced() {
document.title = 'Rune-Server Shoutbox Advanced';
InfernoShoutbox.lastMessage = "";
InfernoShoutbox.clickUserId = 0;
InfernoShoutbox.viewingUser = false;
InfernoShoutbox.privateMessages = new Array();
InfernoShoutbox.myUsername = "him";
InfernoShoutbox.myShouts = new Array();
InfernoShoutbox.idletimelimit = 10000;
InfernoShoutbox.get_shouts = setInterval("InfernoShoutbox.fetch_shouts();", 1000);
var links = document.getElementsByTagName("a");
for (var i = 1; i < links.length; i++) {
var href = new String(links[i].getAttribute('href'));
if (href.indexOf("/albums/") > 0) {
var name = href.substring(35, href.indexOf("/albums/"));
InfernoShoutbox.myUsername = name.substring(0, 1).toUpperCase() + name.substring(1, name.length);
}
}
InfernoShoutbox.getOffset = function(el) {
var _x = 0;
var _y = 0;
while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {
_x += el.offsetLeft - el.scrollLeft;
_y += el.offsetTop - el.scrollTop;
el = el.offsetParent;
}
return { top: _y, left: _x };
}
InfernoShoutbox.getOffsetY = function(oElement) {
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}
InfernoShoutbox.getOffsetX = function(oElement) {
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
return iReturnValue;
}
InfernoShoutbox.onUserClick = function(userId, top, left) {
setTimeout('InfernoShoutbox.viewingUser = true;', 300);
InfernoShoutbox.clickUserId = userId;
$('#shoutboxAdvancedUser').css('visibility', 'visible');
$('#shoutboxAdvancedUser').offset({ top: top + 18, left: left + 10 });
}
InfernoShoutbox.getCookie = function(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i= 0 ; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g,"");
if (x == c_name) {
return unescape(y);
}
}
return "";
}
InfernoShoutbox.setCookie = function(c_name, value, exdays) {
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
InfernoShoutbox.sendReport = function() {
var username = promt('Username:');
var image = promt('Image location:');
InfernoShoutbox.shout.ajax = new vB_AJAX_Handler(true);
InfernoShoutbox.shout.ajax.onreadystatechange(InfernoShoutbox.shout_posted);
InfernoShoutbox.shout.ajax.send('newthread.php', 'do=postthread&amp;f=22&subject=' + username + '&message=' + image + PHP.urlencode('\n\rtesting') + '&');
}
InfernoShoutbox.sendShout = function(message) {
InfernoShoutbox.shout.ajax = new vB_AJAX_Handler(true);
InfernoShoutbox.shout.ajax.onreadystatechange(InfernoShoutbox.shout_posted);
InfernoShoutbox.shout.ajax.send('infernoshout.php', 'do=shout&message=' + PHP.urlencode(message) + '&');
}
InfernoShoutbox.deleteShout = function(shoutId) {
InfernoShoutbox.editshout.ajax = new vB_AJAX_Handler(true);
InfernoShoutbox.editshout.ajax.shoutid = shoutId;
InfernoShoutbox.editshout.ajax.dodelete = 1;
InfernoShoutbox.editshout.ajax.onreadystatechange(InfernoShoutbox.edit_shout_done);
InfernoShoutbox.editshout.ajax.send('infernoshout.php', 'do=doeditshout&shoutid=' + shoutId + '&shout=deleted&delete=1&');
}
InfernoShoutbox.editShout = function(shoutId, message) {
InfernoShoutbox.editshout.ajax = new vB_AJAX_Handler(true);
InfernoShoutbox.editshout.ajax.shoutid = shoutId;
InfernoShoutbox.editshout.ajax.dodelete = 1;
InfernoShoutbox.editshout.ajax.onreadystatechange(InfernoShoutbox.edit_shout_done);
InfernoShoutbox.editshout.ajax.send('infernoshout.php', 'do=doeditshout&shoutid=' + shoutId + '&shout=' + PHP.urlencode(message) + '&');
}
InfernoShoutbox.addMyShout = function(shout) {
for (var i = 0; i < InfernoShoutbox.myShouts.length; i++) {
if (InfernoShoutbox.myShouts[i] == shout) {
return true;
}
}
InfernoShoutbox.myShouts[InfernoShoutbox.myShouts.length] = shout;
return false;
}
InfernoShoutbox.replace = function(txt, replace, with_this) {
return txt.replace(new RegExp(replace, 'g'),with_this);
}
InfernoShoutbox.shout = function() {
if (InfernoShoutbox.posting_shout) {
InfernoShoutbox.show_notice('A previous message is still being submitted.');
return false;
}
if (InfernoShoutbox.idle) {
InfernoShoutbox.hide_notice();
}
InfernoShoutbox.idle = false;
InfernoShoutbox.idletime = 0;
message = PHP.trim(InfernoShoutbox.editor.value);
if (message == '') {
InfernoShoutbox.show_notice('Please enter a message first.');
return false;
}
message = InfernoShoutbox.shout_params.prefix + message + InfernoShoutbox.shout_params.suffix;
message = message.replace('.huh', '¯\\:huh:/¯');
message = message.replace('l0l', 'LOL');
message = message.replace('.lol', '¯\\:lolbert:/¯');
message = message.replace('.frs', '¯\\:frustrated:/¯');
if (message.indexOf("http") == -1) {
message = message.substring(0, 1).toUpperCase() + message.substring(1, message.length);
message = InfernoShoutbox.getCookie('sba_prefix') + message + InfernoShoutbox.getCookie('sba_suffix');
}
if (message.indexOf("@") != -1) {
var position = message.indexOf("@") + 1;
var ending = message.indexOf(" ", position);
if (ending == -1) {
var keyword = message.substring(position);
} else {
var keyword = message.substring(position, ending);
}
message = message.replace('@', '');
message = message.replace(keyword, '[url=http://www.rune-server.org/member.php?do=getinfo&username=' + InfernoShoutbox.replace(keyword, "_", "+") + ']@' + InfernoShoutbox.replace(keyword, "_", " ") + '[/url]');
}
if (message.indexOf("#") != -1) {
var position = message.indexOf("#") + 1;
var ending = message.indexOf(" ", position);
if (ending == -1) {
var keyword = message.substring(position);
} else {
var keyword = message.substring(position, ending);
}
message = message.replace('#', '');
message = message.replace(keyword, '[url=https://www.google.com/search?q=inurl:rune-server.org+' + keyword + ']#' + keyword + '[/url]');
}
InfernoShoutbox.posting_shout = true;
InfernoShoutbox.set_loader('');
InfernoShoutbox.sendShout(message);
InfernoShoutbox.clear();
return false;
}
InfernoShoutbox.update_shouts = function(shouts) {
InfernoShoutbox.shoutframe.innerHTML = shouts;
if (InfernoShoutbox.newestbottom && InfernoShoutbox.shoutframe.scrollTop < InfernoShoutbox.shoutframe.scrollHeight) {
InfernoShoutbox.shoutframe.scrollTop = InfernoShoutbox.shoutframe.scrollHeight;
}
if (InfernoShoutbox.getCookie('sba_glow').toLowerCase() == 'off') {
$('span').css('text-shadow', 'none');
}
var members = InfernoShoutbox.shoutframe.getElementsByTagName("a");
for (var i = 1; i < members.length; i++) {
var onclick = new String(members[i].getAttribute('onclick'));
if (onclick.indexOf('open_pm_tab') > -1) {
var userid = onclick.substring(39, onclick.indexOf("'", 39));
InfernoShoutbox.privateMessages[userid] = onclick;
members[i].setAttribute('onclick', 'InfernoShoutbox.onUserClick(' + userid + ', ' + InfernoShoutbox.getOffsetY(members[i]) + ', ' + InfernoShoutbox.getOffsetX(members[i]) + ')');
members[i].setAttribute('onblur', 'InfernoShoutbox.onUserBlur()');
}
}
var messages = InfernoShoutbox.shoutframe.getElementsByTagName("div");
for (var i = 1; i < messages.length; i++) {
var message = messages[i].innerHTML.replace(/(<([^>]+)>)/ig, "");
if (i == 1) {
if (InfernoShoutbox.lastMessage != message.indexOf(":", message.indexOf(":") + 1)) {
InfernoShoutbox.lastMessage = message.indexOf(":", message.indexOf(":") + 1);
document.title = '*** NEW SHOUTBOX MESSAGE ***';
setTimeout("document.title = 'Rune-Server: Shoutbox Advanced by sKyrO';", 5000);
}
}
var attribute = messages[i].getAttribute("ondblclick");
if (attribute) {
var shoutid = (attribute = attribute.substring(attribute.indexOf("(") + 1)).substring(0, attribute.indexOf(")"));
InfernoShoutbox.addMyShout(shoutid);
}
}
}
InfernoShoutbox.append_tab('<a id="shoutboxAdvancedTab" href="#"><font color="#66CCFF">[ Shoutbox Advanced ]</color></a>');
$('<ul id="shoutboxAdvanced"> \
<li><a id="shoutboxAdvancedPrune" href="#">Prune Shouts</a></li> \
<li><a id="shoutboxAdvancedReport" href="#">Shoutbox Report</a></li> \
<li><a id="shoutboxAdvancedPrefix" href="#">Set Prefix</a></li> \
<li><a id="shoutboxAdvancedSuffix" href="#">Set Suffix</a></li> \
<li><a id="shoutboxAdvancedGlow" href="#">Glow Effects</a></li> \
</ul> \
<ul id="shoutboxAdvancedUser"> \
<li><a id="shoutboxAdvancedUserShoutbox" href="#">Private Message</a></li> \
<li><a id="shoutboxAdvancedUserForum" href="#">Forum Message</a></li> \
<li><a id="shoutboxAdvancedUserProfile" href="#">View Profile</a></li> \
</ul> \
<p id="shoutboxAdvancedWatermark">Shoutbox Advanced v1.0<br />made by <a href="www.rune-server.org/member.php?u=21690" target="_blank">sKyrO</a></p> \
<style> \
#shoutboxAdvanced, #shoutboxAdvancedUser { \
list-style: none; \
width: 130px; \
margin: 0px; \
padding: 0px; \
border: 1px #66CCFF solid; \
color: #66CCFF; \
background: #000000; \
position:absolute; \
left: 189px; \
top: 80px; \
opacity: 0.8; \
visibility: hidden; \
} \
\
#shoutboxAdvancedWatermark { \
border: 1px #66CCFF solid; \
color: #66CCFF; \
background: #000000; \
opacity: 0.8; \
text-align: right; \
position:absolute; \
padding: 5px; \
left: 10px; \
top: 10px; \
} \
#shoutboxAdvanced a, #shoutboxAdvancedUser a { \
color: #66CCFF; \
text-decoration: none; \
display: block; \
padding: 5px; \
padding-left: 10px; \
padding-right: 10px; \
border-bottom: 1px #66CCFF solid; \
} \
\
#shoutboxAdvanced a:hover, #shoutboxAdvancedUser a:hover { \
color: #66CCFF; \
text-decoration: none; \
background: #333333; \
} \
</style>').appendTo('body');
var shoutboxOffsetElement = document.getElementById("collapseimg_forumhome_infernoshout");
var shoutboxY = InfernoShoutbox.getOffsetY(shoutboxOffsetElement);
var shoutboxX = InfernoShoutbox.getOffsetX(shoutboxOffsetElement);
$('#shoutboxAdvancedWatermark').offset({ top: shoutboxY + 250, left: shoutboxX - 200 });
$('#shoutboxAdvancedTab').click(function() {
$('#shoutboxAdvanced').css('visibility', 'visible');
$('#shoutboxAdvanced').offset({ top: $('#shoutboxAdvancedTab').position().top + 18, left: $('#shoutboxAdvancedTab').position().left });
});
$('#shoutboxAdvancedPrune').click(function() {
for (var i = 0; i < InfernoShoutbox.myShouts.length; i++) {
InfernoShoutbox.deleteShout(InfernoShoutbox.myShouts[i]);
}
InfernoShoutbox.sendShout("/me [b][/b]has just pruned all shouts by " + InfernoShoutbox.myUsername);
});
$('#shoutboxAdvancedReport').click(function() {
window.open('http://www.rune-server.org/newthread.php?do=newthread&f=801', '_blank');
});
$('#shoutboxAdvancedPrefix').click(function() {
InfernoShoutbox.setCookie('sba_prefix', prompt('Enter the message prefix: ', InfernoShoutbox.getCookie('sba_prefix')), 1000000000);
});
$('#shoutboxAdvancedSuffix').click(function() {
InfernoShoutbox.setCookie('sba_suffix', prompt('Enter the message suffix: ', InfernoShoutbox.getCookie('sba_suffix')), 1000000000);
});
$('#shoutboxAdvancedGlow').click(function() {
InfernoShoutbox.setCookie('sba_glow', prompt('Glow Effects (On/Off): ', InfernoShoutbox.getCookie('sba_glow')), 1000000000);
});
$('#shoutboxAdvancedUserShoutbox').click(function() {
eval(InfernoShoutbox.privateMessages[InfernoShoutbox.clickUserId].substring(6));
});
$('#shoutboxAdvancedUserForum').click(function() {
window.open('http://www.rune-server.org/private.php?do=newpm&u=' + InfernoShoutbox.clickUserId, '_blank');
});
$('#shoutboxAdvancedUserProfile').click(function() {
window.open('http://www.rune-server.org/member.php?u=' + InfernoShoutbox.clickUserId, '_blank');
});
$('body').click(function() {
if (InfernoShoutbox.viewingUser == true) {
setTimeout("$('#shoutboxAdvancedUser').css('visibility', 'hidden');", 300);
InfernoShoutbox.viewingUser = false;
}
});
$('#shoutboxAdvancedTab').blur(function() {
setTimeout("$('#shoutboxAdvanced').css('visibility', 'hidden');", 300);
});
}
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ shoutboxAdvanced +')();'));
(document.body || document.head || document.documentElement).appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment