Skip to content

Instantly share code, notes, and snippets.

@Tsunder
Last active February 28, 2023 23:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tsunder/77e1e135362a21653da71e8e0e298576 to your computer and use it in GitHub Desktop.
Save Tsunder/77e1e135362a21653da71e8e0e298576 to your computer and use it in GitHub Desktop.
Pardus Messaging + Pardus Multi Message. TWO scripts, please scroll down to get to the second.
// INTENDED TO BE USED WITH PARDUS MESSAGING
// ==UserScript==
// @name Pardus Multi Message
// @namespace http://userscripts.xcom-alliance.info/
// @version 3.5
// @author Miche (Orion) / Sparkle (Artemis), Pincedragon (Orion)
// @description Enhances the Pardus message window to allow multiple recipients seperated by commas or newlines as well as configurable lists of pilot names that remain independent across universe. Based on work by Ivar (Artemis).
// @include http*://*.pardus.at/sendmsg.php*
// @include http*://*.pardus.at/msgframe.php
// @updateURL https://github.com/Tsunder/pardus-script-fun-pack/raw/master/userscripts/pardus_multi_message.user.js
// @downloadURL https://github.com/Tsunder/pardus-script-fun-pack/raw/master/userscripts/pardus_multi_message.user.js
// @icon http://userscripts.xcom-alliance.info/multi_message/icon.png
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// ==/UserScript==
/*****************************************************************************************
Version Information
3.5 ( 28-Nov-2018)
- download migration
3.4 ( 31-Oct-2018)
- added compatibility with PardusMessaging
3.3 ( 29-Mar-2018)
- removed old debugging code
- implemented a delay between each message being sent to prevent dropped requests
3.2 ( 27-May-2013)
- disable the send message button as soon as it is clicked to prevent double-clicks
3.1 ( 10-May-2013 )
- released for general use
- moved configuration to show on the side of the screen (to accomodate small screens)
- added ability to restrict alerting when you attempt to send yourself a message
- updated reflow of the send message page to be more robust
- settings changes are applied immediately when the "Save and Close" button is pressed
- removed default "first run" settings and incorporated into the open settings code
- css only added to the page once
- moved the resize link so that it won't disappear off screen for small screens
3.01 ( 10-Apr-2012 )
- implemented universe independent custom lists and settings
- added settings panel to allow customising the settings via the send message window
1.07 ( 10-Jul-2011 )
- added hard coded custom lists of recipients for Orion universe only
1.06 ( 10-Jul-2011 )
- initial reflow of the send message window based on Ivar's original code
**************************************************************************************
Credit to Ivar (Artemis) for the original script that I then started hacking at:
- http://pardus.rukh.de/dl/pardus_multi_message.user.js
*****************************************************************************************/
/*
**************************************************************************************
Shared utility methods
**************************************************************************************
*/
function getUniverse() {
var universe = window.location.host.substr(0, window.location.host.indexOf('.'));
universe = universe.substr(0,1).toUpperCase() + universe.substr(1).toLowerCase();
return universe;
}
if (document.URL.search('pardus.at/msgframe.php') > -1) {
/*
**************************************************************************************
Save the current pilot name to assist in de-duping when sending to lists of pilots
**************************************************************************************
*/
GM_setValue('currentPilotName' + getUniverse(), document.getElementById('universe').getAttribute('alt').split(': ')[1]);
} else {
var WIDTH_OF_SETTINGS_PANEL = 300;
var HEIGHT_TO_RESIZE_TOGGLE = 300;
var b_ERROR_WHILST_SENDING_A_MESSAGE = false;
var THROTTLE_DELAY_MS = 100;
/*
**************************************************************************************
Common utility methods
**************************************************************************************
*/
Array.prototype.unique = function() {
var o = {}, i, l = this.length, r = [];
for(i=0; i<l; i+=1) o[this[i]] = this[i];
for(i in o) r.push(o[i]);
return r;
};
String.prototype.strim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
};
/*
**************************************************************************************
Methods to drive the settings panel
**************************************************************************************
*/
function cssForSettingsPanel() {
if (document.getElementById('MultiMessageSettingsPanelCSS')) return;
var CSS = document.createElement('STYLE');
CSS.setAttribute('type','text/css');
CSS.setAttribute('id','MultiMessageSettingsPanelCSS');
// http://www.dailycoding.com/Utils/Converter/ImageToBase64.aspx
var CSS_background = "data:image/gif;base64,R0lGODdhAQACAPAAABQaPAYGISwAAAAAAQACAAACAkQKADs=";
var css = "\n/* Injected css from the Multi Message userscript */ \n\n";
css += '#settingsWrapper { position:absolute;right:18px;top:25px; }' + '\n';
css += '#settingsWrapper { background-image:url(' + CSS_background + ');padding:6px;font-size:11px;border:1px solid #aab;text-align:left; }' + '\n';
css += '#settingsWrapper h3 { background-color:#aab;color:#000;text-align:center;padding:5px 8px;margin:0;font-size:11px; }' + '\n';
css += '#settingsWrapper h4 { margin:5px 0;float:left;clear:left; }' + '\n';
css += '#settingsWrapper .grouptitles { float:left;clear:left; }' + '\n';
css += '#settingsWrapper .radios { float:right; }' + '\n';
css += '#settingsWrapper .checkboxes { float:left;clear:left;margin-bottom:5px; }' + '\n';
css += '#settingsWrapper hr { border:none;border-top:1px solid #aab;height:1px;margin:5px 0;clear:both; }' + '\n';
css += '#settingsWrapper input[type="text"], #settingsWrapper textarea { border:1px solid #aab;border-radius:2px;padding:2px;background-color:#00001C;color:#D0D1D9;font-family:Arial,Verdana;font-size:11px; }' + '\n';
css += '#settingsWrapper input[type="text"] { width:100px; }' + '\n';
css += '#settingsWrapper textarea { width:280px;height:65px;margin:5px 0;float:left;clear:both; }' + '\n';
css += '#settingsWrapper .buttons { text-align:right;margin:10px 0 5px; }' + '\n';
css += '#settingsWrapper .buttons span { margin:0 0 0 10px;border-radius:3px;background-color:green;padding:3px 8px;border:1px solid #AAAABB;cursor:pointer;color:#D0D1D9;font-weight:bold; }' + '\n';
css += '#settingsWrapper .buttons span#cancelAndCloseSettings { background-color:#c11;color:#D0D1D9; }' + '\n';
CSS.innerHTML = css;
document.body.appendChild(CSS);
}
function writeCurrentSettingsToSettingsPanel() {
document.getElementById('settingsBCC_ON').checked = GM_getValue('DefaultBCCState' + universe, '') == 'checked';
document.getElementById('settingsBCC_OFF').checked = !document.getElementById('settingsBCC_ON').checked;
document.getElementById('settingsWarnSelf').checked = GM_getValue('SettingsWarnSelf' + universe, '') == 'true';
document.getElementById('settingsQL1Name').value = GM_getValue('QuickList1LinkName' + universe, '') == '' ? 'List 1' : GM_getValue('QuickList1LinkName' + universe, '');
document.getElementById('settingsQL1_ON').checked = GM_getValue('QuickList1LinkDisplay' + universe, '') == 'true';
document.getElementById('settingsQL1_OFF').checked = !document.getElementById('settingsQL1_ON').checked;
document.getElementById('settingsQL1Names').value = GM_getValue('QuickList1PilotNames' + universe, '') == '' ? 'Pilot 1, Pilot 2, Pilot 3' : GM_getValue('QuickList1PilotNames' + universe, '');
document.getElementById('settingsQL2Name').value = GM_getValue('QuickList2LinkName' + universe, '') == '' ? 'List 2' : GM_getValue('QuickList2LinkName' + universe, '');
document.getElementById('settingsQL2_ON').checked = GM_getValue('QuickList2LinkDisplay' + universe, '') == 'true';
document.getElementById('settingsQL2_OFF').checked = !document.getElementById('settingsQL2_ON').checked;
document.getElementById('settingsQL2Names').value = GM_getValue('QuickList2PilotNames' + universe, '') == '' ? 'Pilot 1, Pilot 2, Pilot 3' : GM_getValue('QuickList2PilotNames' + universe, '');
}
function getSettingsPanelHTML(universe) {
var html = '';
html += '<h3>Configuring Multi-Messenger options for ' + universe + '</h3>';
html += '<hr/>';
html += '<div>By default the BCC checkbox is ';
html += '<input type="radio" name="settingsBCC" id="settingsBCC_ON"> <label for="settingsBCC_ON">ON</label> ';
html += '<input type="radio" name="settingsBCC" id="settingsBCC_OFF"> <label for="settingsBCC_OFF">OFF</label> ';
html += '</div>';
html += '<hr/>';
html += '<div class="checkboxes">';
html += '<input type="checkbox" name="settingsWarnSelf" id="settingsWarnSelf"> <label for="settingsWarnSelf">Show an alert when sending yourself a message</label><br/>';
html += '</div>';
html += '<hr/>';
html += '<h4>Group List 1</h4>';
html += '<div class="grouptitles"><input type="text" id="settingsQL1Name" value=""></div>';
html += '<div class="radios">';
html += '<input type="radio" name="settingsQL1" id="settingsQL1_ON"> <label for="settingsQL1_ON">Show group</label> ';
html += '<input type="radio" name="settingsQL1" id="settingsQL1_OFF"> <label for="settingsQL1_OFF">Hide group</label> ';
html += '</div>';
html += '<textarea id="settingsQL1Names"></textarea>';
html += '<hr/>';
html += '<h4>Group List 2</h4>';
html += '<div class="grouptitles"><input type="text" id="settingsQL2Name" value=""></div>';
html += '<div class="radios">';
html += '<input type="radio" name="settingsQL2" id="settingsQL2_ON"> <label for="settingsQL2_ON">Show group</label> ';
html += '<input type="radio" name="settingsQL2" id="settingsQL2_OFF"> <label for="settingsQL2_OFF">Hide group</label> ';
html += '</div>';
html += '<textarea id="settingsQL2Names"></textarea>';
html += '<hr/>';
html += '<div class="buttons"><span id="saveAndCloseSettings">Save and Close</span> <span id="cancelAndCloseSettings">Cancel</span></div>';
return html;
}
function attachEventsForSettingsPanelButtons() {
if (document.getElementById('saveAndCloseSettings')) {
document.getElementById('saveAndCloseSettings').addEventListener('click', saveAndCloseSettingsPanel, false);
}
if (document.getElementById('cancelAndCloseSettings')) {
document.getElementById('cancelAndCloseSettings').addEventListener('click', saveAndCloseSettingsPanel, false);
}
}
function addSettingsPanelToPageSide() {
cssForSettingsPanel();
var div = document.createElement('div');
div.setAttribute('id','settingsWrapper');
div.innerHTML = getSettingsPanelHTML(getUniverse());
document.getElementById('sendform').parentNode.appendChild(div);
attachEventsForSettingsPanelButtons();
writeCurrentSettingsToSettingsPanel();
window.resizeBy(WIDTH_OF_SETTINGS_PANEL, 0);
}
function saveAndCloseSettingsPanel(e) {
if (e.target.id == 'saveAndCloseSettings') {
var universe = getUniverse();
GM_setValue('DefaultBCCState' + universe, document.getElementById('settingsBCC_ON').checked ? 'checked' : '');
document.getElementById('bcc').checked = document.getElementById('settingsBCC_ON').checked;
GM_setValue('SettingsWarnSelf' + universe, document.getElementById('settingsWarnSelf').checked === true ? 'true' : 'false');
var _QuickList1LinkDisplay = (document.getElementById('settingsQL1_ON').checked) ? 'true' : 'false';
GM_setValue('QuickList1LinkDisplay' + universe, _QuickList1LinkDisplay);
var _QuickList1LinkName = document.getElementById('settingsQL1Name').value;
GM_setValue('QuickList1LinkName' + universe, _QuickList1LinkName);
var _QuickList1PilotNames = document.getElementById('settingsQL1Names').value;
document.getElementById('customlink1').innerHTML = _QuickList1LinkName;
document.getElementById('customlink1').style.display = _QuickList1LinkDisplay == 'true' && _QuickList1LinkName != '' ? 'block' : 'none';
GM_setValue('QuickList1PilotNames' + universe, _QuickList1PilotNames);
var _QuickList2LinkDisplay = (document.getElementById('settingsQL2_ON').checked) ? 'true' : 'false';
GM_setValue('QuickList2LinkDisplay' + universe, _QuickList2LinkDisplay);
var _QuickList2LinkName = document.getElementById('settingsQL2Name').value;
GM_setValue('QuickList2LinkName' + universe, _QuickList2LinkName);
var _QuickList2PilotNames = document.getElementById('settingsQL2Names').value;
document.getElementById('customlink2').innerHTML = _QuickList2LinkName;
document.getElementById('customlink2').style.display = _QuickList2LinkDisplay == 'true' && _QuickList2LinkName != '' ? 'block' : 'none';
GM_setValue('QuickList2PilotNames' + universe, _QuickList2PilotNames);
}
document.getElementById('settingsWrapper').parentNode.removeChild(document.getElementById('settingsWrapper'));
window.resizeBy((0-WIDTH_OF_SETTINGS_PANEL),0);
document.getElementById('mmsettingslink').style.visibility = 'visible';
}
function openSettingsPanel(e) {
e.target.style.visibility = 'hidden';
addSettingsPanelToPageSide();
}
/*
**************************************************************************************
Support the configurable quicklinks
**************************************************************************************
*/
function clickCustomQuickLink(e) {
var universe = getUniverse();
var pilotList = '';
if (e.target.id == 'customlink1') {
pilotList = GM_getValue('QuickList1PilotNames' + universe,'');
} else if (e.target.id == 'customlink2') {
pilotList = GM_getValue('QuickList2PilotNames' + universe,'');
}
if (pilotList == '') {
return;
}
// remove the current pilot from the list if included
var currentPilotName = GM_getValue('currentPilotName' + universe,'').toLowerCase();
var newPilotArray = [];
var arr = pilotList.strim().split(",");
for(var i = 0; i < arr.length; i++) {
arr[i] = arr[i].strim();
if (arr[i].toLowerCase() != currentPilotName) {
newPilotArray.push(arr[i]);
}
}
document.getElementById('recipient2').value = newPilotArray.join(', ');
}
/*
*****************************************************************************************************************************\
Enable and disable form elements triggered by clicking on the send button
*******************************************************************************************************************************
*/
function _toggleOnScreenFormElements(state) {
var sendButton = document.getElementById('sendbutton');
sendButton.disabled = state;
if (state == true) {
sendButton.style.backgroundColor = '#999';
sendButton.setAttribute('value', 'Sending...');
} else {
sendButton.style.backgroundColor = '#00001C';
sendButton.setAttribute('value', 'Send');
}
// var recipientTextarea = document.getElementById('recipient2');
// recipientTextarea.disabled = state;
// var subjectInput = document.getElementById('subject');
// subjectInput.disabled = state;
// var bodyTextarea = document.getElementById('textarea');
// bodyTextarea.disabled = state;
}
function disableOnScreenFormElements() {
_toggleOnScreenFormElements(true);
}
function reenableOnScreenFormElements() {
_toggleOnScreenFormElements(false);
}
/*
*****************************************************************************************************************************\
Handle the clicking of the send button and sending of each message
*******************************************************************************************************************************
*/
function getRecipients() {
// handle the recipients list delimiters being either COMMA, NEWLINE or SEMI-COLON
var arr = newrecp.value.strim().replace(/\n|;/g, ",").split(",");
var cleanedArr = [];
for(var i = 0; i < arr.length; i++) {
if (arr[i].strim() != "") {
cleanedArr.push(arr[i].strim());
}
}
return cleanedArr.unique();
}
function sendMessages(button) {
button.setAttribute('disabled','disabled');
var recipients = getRecipients();
var recipientTextarea = document.getElementById('recipient2');
if (recipientTextarea.value == "" || recipients.length === 0) {
alert("Please enter at least one recipient!");
recipientTextarea.focus();
button.removeAttribute('disabled');
return false;
}
var bodyTextarea = document.getElementById('textarea');
if (bodyTextarea.value == "") {
alert("Please enter a message!");
bodyTextarea.focus();
button.removeAttribute('disabled');
return false;
}
disableOnScreenFormElements();
b_ERROR_WHILST_SENDING_A_MESSAGE = false;
var d = document.getElementById('errormsg');
if (d) {
d.parentNode.removeChild(d);
}
msgcount = recipients.length;
for (let i=0; i<recipients.length; i++) {
if (recipients[i] != '') {
setTimeout(function() {
sendXMLHTTP(recipients[i]);
}, i * THROTTLE_DELAY_MS);
}
}
}
function sendXMLHTTP(to) {
var params = "";
var msg = document.getElementById('textarea').value;
if (!document.getElementById('bcc').checked && getRecipients().length > 1) {
var _quoteIndex = msg.indexOf("\n---------------------------------------------------------------------"); // first occurence of a "quote" as per pardus messaging
if (_quoteIndex > -1 ) { //only adds CCs between text if there is a quoted message. otherwise add at end.
msg = msg.substring(0,_quoteIndex) + "\n\nCC: "+getRecipients().join(", ") + msg.substring(_quoteIndex);
} else {
msg += "\n\nCC: "+getRecipients().join(", ");
}
}
params += "recipient="+encodeURIComponent(to);
params += "&textfield="+encodeURIComponent(document.getElementById('subject').value);
params += "&textarea="+encodeURIComponent(msg);
if (document.getElementById('attach_signature').disabled == false) {
if (document.getElementById('attach_signature').checked) {
params += "&attach_signature="+document.getElementById('attach_signature').value;
}
}
params += "&Send=Send";
var b_WarnSelf = GM_getValue('SettingsWarnSelf' + getUniverse(), '') == 'true';
GM_xmlhttpRequest({
method: "POST",
url: document.location,
data: params,
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Content-Length": params.length
},
onload: function(response) {
var nop = response.responseText.indexOf("This player does not exist!");
var nos = response.responseText.indexOf("Sorry, you cannot send yourself messages");
if (nop > -1 || (nos > -1 && b_WarnSelf)) {
b_ERROR_WHILST_SENDING_A_MESSAGE = true;
reenableOnScreenFormElements();
if (nop > -1) {
var d = document.getElementById('errormsg');
if (d == null) {
d = document.createElement('div');
d.setAttribute('id', 'errormsg');
d.style.color = '#c00';
d.style.fontWeight = 'bold';
var s = document.createElement('span');
d.appendChild(document.createTextNode('The following pilots do not exist: '));
d.appendChild(s);
s.appendChild(document.createTextNode(to));
newrecp.parentNode.appendChild(d);
} else {
d.children[0].appendChild(document.createTextNode(', '+to));
}
} else if (nos > -1 && b_WarnSelf) {
alert('You cannot send a message to yourself');
}
var recipientTextarea = document.getElementById('recipient2');
recipientTextarea.focus();
return;
}
if (--msgcount == 0 && !b_ERROR_WHILST_SENDING_A_MESSAGE) {
var arr = getRecipients();
if (arr.length > 1) {
alert("The message was sent to the following pilots:\n\n"+arr.join("\n"));
}
self.close();
}
}
});
}
/*
**************************************************************************************
Here is where the magic begins...
**************************************************************************************
*/
var universe = getUniverse();
var msgcount = 0;
var recipientCell = document.getElementById('recipient2').parentNode;
var oldrecp = document.getElementById('recipient2');
// make the title look good
var titleCell = document.getElementsByTagName('TABLE')[2].rows[0].cells[0];
titleCell.style.padding = '5px 0';
titleCell.style.fontSize = '11px';
titleCell.setAttribute('colspan', 2);
// remove some functionality we don't want and set the layout to be simple
var checkbutton = document.getElementsByName('checkname')[0];
if (typeof checkbutton != "undefined") {
checkbutton.parentNode.removeChild(checkbutton);
} else {
// remove the view profile link
var viewProfileLink = document.getElementById('recipient2').nextElementSibling;
viewProfileLink.parentNode.removeChild(viewProfileLink);
// grab the race and alliance details
var raceAllianceData = '';
var imgs = recipientCell.parentNode.lastChild.previousSibling.getElementsByTagName('IMG');
if (imgs.length) raceAllianceData = ' (' + imgs[0].alt + ')';
// update the title with the profile link. race and alliance data
titleCell.innerHTML = 'Replying to a message from: <a href="' + viewProfileLink.href + '" style="color:#116;text-decoration:underline;" target="_blank">' + oldrecp.value + raceAllianceData + '</a>';
}
// make the table a little wider to prevent the text areas wrapping and making nasty gaps
document.getElementsByTagName('TABLE')[2].width='490';
// add in some brief instructions
var p = document.createElement('p');
p.style.fontSize = '11px';
p.style.margin = '0 4px 2px 0';
p.style.textAlign = 'left';
p.innerHTML = "Comma separate pilot names and use the BCC checkbox at the bottom to hide the pilot list";
var tables = document.getElementsByTagName('TABLE');
var newRow = tables[2].insertRow(1);
var newCell = newRow.insertCell(0);
newCell.setAttribute('colspan','2');
newCell.appendChild(p);
// set the widths for the table correctly
recipientCell.previousElementSibling.setAttribute('width','65');
// top align the "To:" string
recipientCell.previousElementSibling.getElementsByTagName('B')[0].setAttribute('style', 'margin:4px 0 0;display:block;');
recipientCell.previousElementSibling.setAttribute('valign','top');
// remove the image cell for the pilot
recipientCell.parentNode.removeChild(recipientCell.parentNode.lastChild.previousSibling);
// add in the custom lists
var customLinkHTML = '<div style="font-size:9px;font-weight:bold;color:#3C3;margin-top:3px;width:65px;overflow:hidden;">';
customLinkHTML += '<span id="customlink1" style="cursor:pointer;margin-top:2px;display:' + (GM_getValue('QuickList1LinkDisplay' + universe, '') == 'true' && GM_getValue('QuickList1LinkName' + universe, '') != '' ? 'block' : 'none') + '">' + GM_getValue('QuickList1LinkName' + universe, '') + '</span>';
customLinkHTML += '<span id="customlink2" style="cursor:pointer;margin-top:2px;display:' + (GM_getValue('QuickList2LinkDisplay' + universe, '') == 'true' && GM_getValue('QuickList2LinkName' + universe, '') != '' ? 'block' : 'none') + '">' + GM_getValue('QuickList2LinkName' + universe, '') + '</span>';
customLinkHTML += '</div>';
recipientCell.previousElementSibling.innerHTML += customLinkHTML;
document.getElementById('customlink1').addEventListener('click', clickCustomQuickLink, true);
document.getElementById('customlink2').addEventListener('click', clickCustomQuickLink, true);
// replace the input for a textarea for the recipients
var newrecp = document.createElement('textarea');
newrecp.setAttribute('name', 'recipient');
newrecp.setAttribute('id', 'recipient2');
newrecp.setAttribute('tabindex', 1);
newrecp.style.backgroundColor = '#00001c';
newrecp.style.font = '12px Arial,Verdana';
newrecp.style.color = '#D0D1D9';
newrecp.style.border = '1px solid #aab';
newrecp.style.borderRadius = '3px';
newrecp.style.padding = '2px';
newrecp.style.marginBottom = '2px';
newrecp.style.width = '390px';
newrecp.style.height = '40px';
recipientCell.replaceChild(newrecp, oldrecp);
// include the recipient in the To field if this is a reply message
var recipient = '';
var searchParams = location.search.substr(1).split('&');
for (var loop=0; loop<searchParams.length; loop++) {
if (searchParams[loop].indexOf('to=')>-1) {
recipient = searchParams[loop].substr(3);
}
}
if (recipient=='undefined') recipient = '';
newrecp.value = unescape(recipient);
// style up the subject field
var subject = document.getElementsByName('textfield')[0];
subject.setAttribute('id', 'subject');
subject.style.width = '390px';
subject.style.border = '1px solid #aab';
subject.style.borderRadius = '2px';
subject.style.padding = '2px';
subject.style.marginBottom = '2px';
// top align the "Subject:" string
subject.parentNode.previousElementSibling.getElementsByTagName('B')[0].setAttribute('style', 'margin:4px 0 0;display:block;');
subject.parentNode.previousElementSibling.setAttribute('valign','top');
// style up the message body field
var body = document.getElementsByName('textarea')[0];
body.style.border = '1px solid #aab';
body.style.borderRadius = '2px';
body.style.padding = '2px';
body.style.width = '390px';
body.style.height = '175px';
body.removeAttribute('cols');
body.parentNode.removeAttribute('colspan');
// top align the "Message:" string
body.parentNode.previousElementSibling.getElementsByTagName('B')[0].setAttribute('style', 'margin:4px 0 0;display:block;');
body.parentNode.previousElementSibling.setAttribute('valign','top');
// remove the old resize link
var el = document.getElementById('resizeLink');
el.parentNode.removeChild(el);
// add a replacement resize link to accomodate resizing offscreen for small screens
function resizeBodyTextareaLink(e) {
var resizeValue = HEIGHT_TO_RESIZE_TOGGLE;
var displayText = '';
if (e.target.textContent.indexOf('+') > -1) {
displayText = 'SIZE -';
} else {
resizeValue = 0 - resizeValue;
displayText = 'SIZE +';
}
document.getElementById('resizeLinkNew').innerHTML = displayText;
window.resizeBy(0,resizeValue);
document.getElementById('textarea').style.height = parseInt(document.getElementById('textarea').style.height, 10) + resizeValue + 'px';
}
var resLinkNew = document.createElement('B');
resLinkNew.setAttribute('style','display:block;margin-top:150px;');
resLinkNew.innerHTML = '<font size="1"><a href="javascript://" id="resizeLinkNew">SIZE +</a></font>';
body.parentNode.previousElementSibling.appendChild(resLinkNew);
document.getElementById('resizeLinkNew').addEventListener('click', resizeBodyTextareaLink, false);
// add some space between the send button and the message
document.getElementById('textarea').style.marginBottom = '8px';
// add in the BCC checkbox
var bcc = document.createElement('input');
bcc.setAttribute('type', 'checkbox');
bcc.setAttribute('id', 'bcc');
bcc.checked = GM_getValue('DefaultBCCState' + universe, '');
var atsig = document.getElementById('attach_signature');
atsig.parentNode.insertBefore(bcc, atsig);
atsig.parentNode.insertBefore(document.createTextNode('BCC '), atsig);
// style up a new send button
var button = document.createElement('input');
button.setAttribute('id', 'sendbutton');
button.setAttribute('type', 'button');
button.setAttribute('value', 'Send');
button.style.width = '100px';
button.style.border = '1px solid #aab';
button.style.borderRadius = '3px';
button.style.padding = '2px';
button.style.marginLeft = '10px';
button.style.cursor = 'pointer';
button.style.fontWeight = 'bold';
button.setAttribute('tabindex', 4);
atsig.parentNode.appendChild(button);
atsig.parentNode.style.paddingRight = '4px';
// attach our send button click functionality
button.addEventListener('click', function () { sendMessages(this); }, false);
// remove the old send button
var inp = document.getElementById('Send');
inp.parentNode.parentNode.removeChild(inp.parentNode);
// add a warning on spamming and a link to the rule
var p = document.createElement('p');
p.style.fontSize = '11px';
p.style.margin = '5px 0 0';
p.innerHTML = "Ensure you understand the <a href=\"http://www.pardus.at/index.php?section=rules\" target=\"_blank\">Rule against Spamming</a>.<span style=\"float:right;margin-right:5px;cursor:pointer;\" id=\"mmsettingslink\">Show multi-message settings</span>";
var newRow = tables[2].insertRow();
var newCell = newRow.insertCell(0);
newCell.setAttribute('colspan','2');
newCell.appendChild(p);
// float the form to accomodate the settings panel
document.getElementById('sendform').style.cssFloat = 'left';
document.getElementById('sendform').style.margin = '0 3px';
// attach the method to run when the user clicks on the Show settings link
document.getElementById('mmsettingslink').addEventListener('click', openSettingsPanel, false);
}
// INTENDED TO BE USED WITH PARDUS MULTI MESSAGE
// ==UserScript==
// @name PardusMessaging
// @namespace jirina42@seznam.cz , astraltoremail@gmail.com
// @author jirina, Tsunders
// @description Adds some useful features to the standard IGM messaging in Pardus.
// @version 1.5.2
// @include *://*.pardus.at/messages_private.php*
// @include *://*.pardus.at/messages_alliance.php*
// @include *://*.pardus.at/sendmsg.php*
// @include *://*.pardus.at/options.php*
// @downloadURL https://github.com/Tsunder/pardus-script-fun-pack/raw/master/userscripts/pardus_messaging.user.js
// @updateURL https://github.com/Tsunder/pardus-script-fun-pack/raw/master/userscripts/pardus_messaging.user.js
// @icon http://www.pardus.at/favicon.ico
// 1.5.2 2018 11 28 download migration
// 1.5.1 2018 11 09 update for "span" colours.
// 1.5 2018 10 31 add reply to all button, dependent on "pardus multi message"
// strip out remaining TFA stuff
// RIP terran federation academy forums.
// Pincedragon (orion)
// http://orion.pardus.at/profile.php?id=216482
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
// ////////////////////////////////////////////////////////////////////////
// Imported -- Rhindon's Standard Cookie Code
// -- Stores GreaseMonkey Values instead of actual Cookies
// ////////////////////////////////////////////////////////////////////////
text = document.URL;
if(text.indexOf("orion.pardus.at") >= 0 ){
universe = "orion";
}else if(text.indexOf("artemis.pardus.at") >= 0) {
universe = "artemis";
}else if(text.indexOf("pegasus.pardus.at") >= 0) {
universe = "pegasus";
}
function createCookie(name,value) {
GM_setValue(name,value);
}
function readCookie(name) {
try {
var temp = GM_getValue(name);
if(temp != '~~~DELETED~~~') return temp;
return null;
} catch(err) {
return null;
}
}
function eraseCookie(name) {
createCookie(name,"~~~DELETED~~~");
}
// ////////////////////////////////////////////////////////////////////////
// End imported code
// ////////////////////////////////////////////////////////////////////////
function mysendmsg() {
// Search for the messages
var cbs = document.getElementsByName("checkbox[]");
var player = this.getAttribute("to");
var subject = this.getAttribute("subj");
var from = this.getAttribute("from");
var last = this.getAttribute("last");
var all = this.getAttribute("all");
var index = this.getAttribute("table");
var private = this.getAttribute("private") == "true";
var txt = "";
var body = this.parentNode.parentNode.parentNode;
var msgcelltop = body.getElementsByTagName("TR")[private?2:3];
var msgcell = msgcelltop.getElementsByTagName("TD")[0];
var subjcell = body.getElementsByTagName("TR")[private?1:2].getElementsByTagName("B")[0];
var playercell = body.getElementsByTagName("TR")[0].getElementsByTagName("A")[0];
var sentcell = playercell.parentNode.parentNode.nextSibling.nextSibling;
txt = "\n\n---------------------------------------------------------------------\n";
txt = txt + playercell.previousSibling.nodeValue + playercell.childNodes[0].nodeValue + "\n";
txt = txt + subjcell.childNodes[0].nodeValue + "\n";
txt = txt + "Sent: " + sentcell.childNodes[sentcell.childNodes.length-1].nodeValue + "\n\n";
var skipbr = 0;
var donutCC = false; //tracker for if the element is a part of a quoted message.
for(var i=0; i<msgcell.childNodes.length; i++) {
var element = msgcell.childNodes[i];
if(element.nodeName == "BR") {
if(skipbr == 0)
txt = txt + "\n";
else
skipbr = 0;
}else if(element.nodeName == "HR"){
break;
}else if (element.nodeName == "SPAN"){ //catches the color aspect
txt += "[color=" + element.getAttribute("style").split(":")[1] + "]" + element.childNodes[0].nodeValue + "[/url]";
continue
}else if(element.nodeName == "FONT"){
if(element.getAttribute("color") != "null"){
txt = txt + "<font color=\""+element.getAttribute("color")+"\" size=\""+element.getAttribute("size")+"\">"+element.childNodes[0].nodeValue+"</font>";
}else{
txt = txt + "<font size=\""+element.getAttribute("size")+"\">"+element.childNodes[0].nodeValue+"</font>";
}
continue;
}else if(element.nodeName == "B"){
txt = txt + "<b>"+element.childNodes[0].nodeValue+"</b>";
continue;
}else if(element.nodeName == "U"){
txt = txt + "<u>"+element.childNodes[0].nodeValue+"</u>";
continue;
}else if(element.nodeName == "I"){
txt = txt + "<i>"+element.childNodes[0].nodeValue+"</i>";
continue;
}else if(element.nodeName == "A"){
txt = txt + "[url="+element.getAttribute("href")+"]"+element.childNodes[0].nodeValue+"[/url]";
continue
//not sure how to make this work RIP
}else if(element.nodeName == "IMG"){
//txt = txt + "test spacing ";
txt = txt + element.getAttribute("alt");
continue
}else if(last == "yes" && element.nodeValue == "--------------------------------------------------------------------- "){
break;
}else if(element.nodeValue == "--------------------------------------------------------------------- ") {
donutCC = true; // we are now in a quoted message
txt = txt + element.nodeValue; // adds quote line to message
}else if(all == "yes" && element.nodeValue.indexOf("CC: ") == 0 && !donutCC) {// if replying to all, and there's a CC line, and if this is part of the original message.
var _CCRecipients = element.nodeValue.substring(4).split(", "); //gets an array of recipeints from the CC list (after "CC: " and seperated by ", ")
for (var _nameIndice = 0 ; _nameIndice < _CCRecipients.length; _nameIndice++) { // comparing each recipient to the player, adds player to list if not on
if (_CCRecipients[_nameIndice].toLowerCase().localeCompare(player.toLowerCase()) == 0 ){
break;
}
if (_nameIndice == _CCRecipients.length - 1){
_CCRecipients.push(player)
break;
}
}
player = _CCRecipients.join(", "); // the to field will be populated with the CC list
txt = txt + element.nodeValue; //adds original cclist to quoted message.
}else{
txt = txt + element.nodeValue;
}
}
createCookie("TFA_Reply", txt);
window.open("sendmsg.php?to="+player+"&subj="+subject,"_blank","width=800,height=600,left=100,top=50");
}
function mysendmsg2() {
label = this.getAttribute("label");
infoCookie = GM_getValue(universe+"_preset|"+label).split("|");
if(infoCookie[0] != null){
var player = infoCookie[0];
}else{
var player = this.getAttribute("to");
}
var subject = infoCookie[1];
var last = this.getAttribute("last");
var all = this.getAttribute("all");
var index = this.getAttribute("table");
var private = this.getAttribute("private") == "true";
var txt = infoCookie[2];
window.open("sendmsg.php?to="+player+"&subj="+subject,"_blank","width=800,height=600,left=100,top=50");
}
function addLinksToMessage(messageTable, private, index) {
var body = messageTable.getElementsByTagName("TBODY")[0];
var newcell = document.createElement("TD");
var newrow = document.createElement("TR");
newrow.appendChild(newcell);
var msgcelltop = body.getElementsByTagName("TR")[private?2:3];
var msgcell = msgcelltop.getElementsByTagName("TD")[0];
var subj = body.getElementsByTagName("TR")[private?1:2].getElementsByTagName("B")[0].childNodes[0].nodeValue;
playercell = body.getElementsByTagName("TR")[0];
if(playercell.getElementsByTagName("A").length == 0)
return;
var player = playercell.getElementsByTagName("A")[0].childNodes[0].nodeValue;
subj = subj.substr(9);
var btn = document.createElement("input");
//btn.id = cb.value;
btn.type = "button";
btn.value = "Re:";
btn.addEventListener("click", mysendmsg, false);
btn.setAttribute("to", player);
btn.setAttribute("from", player);
btn.setAttribute("subj", subj);
btn.setAttribute("last", "no");
btn.setAttribute("all", "no");
btn.setAttribute("private", private);
newcell.appendChild(btn);
newcell.appendChild(document.createTextNode(" "));
var btn = document.createElement("input");
//btn.id = cb.value;
btn.type = "button";
btn.value = "Re: last";
btn.addEventListener("click", mysendmsg, false);
btn.setAttribute("to", player);
btn.setAttribute("from", player);
btn.setAttribute("subj", subj);
btn.setAttribute("last", "yes");
btn.setAttribute("all", "no");
btn.setAttribute("private", private);
newcell.appendChild(btn);
newcell.appendChild(document.createTextNode(" "));
var btn = document.createElement("input");
//btn.id = cb.value;
btn.type = "button";
btn.value = "Re: All";
btn.addEventListener("click", mysendmsg, false);
btn.setAttribute("to", player);
btn.setAttribute("from", player);
btn.setAttribute("subj", subj);
btn.setAttribute("last", "no");
btn.setAttribute("all", "yes");
btn.setAttribute("private", private);
newcell.appendChild(btn);
newcell.appendChild(document.createTextNode(" "));
var btn = document.createElement("input");
//btn.id = cb.value;
btn.type = "button";
btn.value = "Re: All: last";
btn.addEventListener("click", mysendmsg, false);
btn.setAttribute("to", player);
btn.setAttribute("from", player);
btn.setAttribute("subj", subj);
btn.setAttribute("last", "yes");
btn.setAttribute("all", "yes");
btn.setAttribute("private", private);
newcell.appendChild(btn);
newcell.appendChild(document.createTextNode(" "));
var btn = document.createElement("input");
//btn.id = cb.value;
btn.type = "button";
btn.value = "Fw:";
btn.addEventListener("click", mysendmsg, false);
btn.setAttribute("to", "");
btn.setAttribute("from", player);
btn.setAttribute("subj", subj);
btn.setAttribute("last", "no");
btn.setAttribute("all", "no");
btn.setAttribute("private", private);
newcell.appendChild(btn);
newcell.appendChild(document.createTextNode(" "));
var btn = document.createElement("input");
//btn.id = cb.value;
btn.type = "button";
btn.value = "Fw: last";
btn.addEventListener("click", mysendmsg, false);
btn.setAttribute("to", "");
btn.setAttribute("from", player);
btn.setAttribute("subj", subj);
btn.setAttribute("last", "yes");
btn.setAttribute("all", "no");
btn.setAttribute("private", private);
newcell.appendChild(btn);
/*presetBtn = new Array();
loadPresetData(player,private,subj,index);
if(presetBtn.length > 0){
newcell.appendChild(document.createTextNode(" "));
for(i=0; i<presetBtn.length; i++){
newcell.appendChild(presetBtn[i]);
newcell.appendChild(document.createTextNode(" "));
}
}
body.appendChild(document.createTextNode(""));*/
body.appendChild(newrow);
}
function loadPresetData(player,private,subj,index){
//unused
if(GM_getValue(universe+"_preset_ids") == null){
GM_setValue(universe+"_preset_ids","");
}
allPresets = loadPresets();
if(allPresets[0] == "") return;
for(i in allPresets){
infoCookie = GM_getValue(universe+"_preset|"+allPresets[i]).split("|");
presetBtn[i] = document.createElement("input");
presetBtn[i].type = "button";
presetBtn[i].value = allPresets[i];
presetBtn[i].addEventListener("click", mysendmsg2, false);
presetBtn[i].setAttribute("last", "no");
presetBtn[i].setAttribute("all", "no");
presetBtn[i].setAttribute("private", private);
presetBtn[i].setAttribute("label", allPresets[i]);
presetBtn[i].setAttribute("to", player);
}
}
function deletePreset(id){
del = confirm("Do you really wish to delete this preset? ("+id+")");
if(!del) return;
var deleteMe = document.getElementById(id);
deleteMe.parentNode.removeChild(deleteMe);
newcookie = "";
divs = document.getElementById("messaging").getElementsByTagName("div");
for(i = 0; i < divs.length; i++){
newcookie += divs[i].id+"|";
}
newcookie = newcookie.slice(0,-1);
GM_setValue(universe+"_preset_ids",newcookie);
if(newcookie.split("|").length == 1){
GM_setValue(universe+"_preset_ids","");
GM_setValue(universe+"_preset|"+id,null);
}
}
function createNewPreset(label,ignore){
//create callback
function addDeleteHandler(target,id){
target.addEventListener("click", function() {deletePreset(id);}, false);
}
to = "";
subj = "";
if(!label || typeof(label) !== "string"){
label = prompt("Enter a label for your button. The label will appear as a link in the options screen. Click that link to edit the preset, which you want add to your messaging interface.");
if(label == null || label == "") return;
label = label.replace(/\|/g,"_");
label = label.replace(/ /g,"_");
alreadyStored = GM_getValue(universe+"_preset_ids").split("|");
for(i in alreadyStored){
if(alreadyStored[i] == label){
alert("Invalid identifier. Please use a unique name!");
return;
}
}
}else{
labeldata = GM_getValue(universe+"_preset|"+label).split("|");
to = labeldata[0];
subj = labeldata[1];
}
newElement = document.createElement("div");
newElement.id = label;
delLink = document.createElement("a");
delLink.innerHTML = "<font color='#FFFFFF'>[DEL]</font>";
//use callback
addDeleteHandler(delLink,newElement.id);
newLink = document.createElement("a");
newLink.target = "_blank";
newLink.href= "sendmsg.php?to=&subj="+subj+"&preset="+label;
newLink.innerHTML = "<font color='#FFFFFF'>[EDIT]</font>";
newElement.appendChild(delLink);
newElement.appendChild(document.createTextNode(" "));
newElement.appendChild(newLink);
newElement.appendChild(document.createTextNode(" "+label));
document.getElementById("messaging").appendChild(newElement);
if(!ignore){
newcookie = label;
GM_setValue(universe+"_preset|"+label,"||");
if(GM_getValue(universe+"_preset_ids") == null || GM_getValue(universe+"_preset_ids") == ""){
GM_setValue(universe+"_preset_ids",newcookie);
}else{
GM_setValue(universe+"_preset_ids",GM_getValue(universe+"_preset_ids")+"|"+newcookie);
}
}
}
function addLinks() {
// Log
//GM_log("addLinks Start");
// Check that we're on the right page
var private;
if(text.indexOf("messages_private.php") >= 0)
private = true;
else if(text.indexOf("messages_alliance.php") >= 0)
private = false;
else
return;
// Search for the messages
var tables;
var min;
var max;
if(private) {
var form1 = document.getElementsByName("form1")[0];
tables = form1.getElementsByTagName("table");
min = 0;
max = tables.length;
} else {
var search = document.getElementsByName("search")[0];
var container = search.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
tables = container.getElementsByTagName("table");
min = 1;
max = tables.length - 2;
}
for(var i = max-1; i >= min; i--) {
parseColorCode(tables[i], private);
addLinksToMessage(tables[i], private, i);
}
// Log
//GM_log("addLinks End");
}
function addReply() {
// Check that we're on the correct page
var letter;
if(text.indexOf("sendmsg.php") < 0) {
return;
}
var reply = readCookie("TFA_Reply");
if(reply == null)
var reply = readCookie("TFA_Reply_preset");
if(reply == null)
return;
var input = document.getElementById("textarea");
input.value = reply;
eraseCookie("TFA_Reply");
eraseCookie("TFA_Reply_preset");
}
function createOptions(){
if(text.indexOf("options.php") < 0) return;
if(GM_getValue(universe+"_preset_ids") == null){
GM_setValue(universe+"_preset_ids","");
}
source = document.getElementsByTagName("form")[0].parentNode.getElementsByTagName("table")[0];
form = source.parentNode;
clone = source.cloneNode(true);
clone.id = "messaging";
form.appendChild(document.createElement("br"));
form.appendChild(document.createElement("br"));
form.appendChild(clone);
custom1 = document.getElementById("messaging");
custom1.getElementsByTagName("th")[0].childNodes[0].nodeValue = "Pardus Messaging";
custom1.getElementsByTagName("td")[0].childNodes[0].nodeValue = "You can set up preset messages here, edit or remove them.";
c1row = custom1.getElementsByTagName("tr")[2];
c1row.removeChild(custom1.getElementsByTagName("td")[1]);
c1btn = document.createElement("input");
c1btn.type = "button";
c1btn.value = "New Preset";
c1btn.addEventListener("click", createNewPreset, false);
c1row.appendChild(c1btn);
savedPresets = new Array();
savedPresets = loadPresets();
if(savedPresets[0].length > 0){
for(i = 0; i < savedPresets.length; i++){
createNewPreset(savedPresets[i],true);
}
}
}
function loadPresets(){
arr = GM_getValue(universe+"_preset_ids").split("|");
return arr;
}
function usePMforCookie(){
if(text.indexOf("preset=") < 0){
return;
}
if(GM_getValue(universe+"_preset_ids") == null){
GM_setValue(universe+"_preset_ids","");
}
label = text.split("preset=")[1];
infoCookie = GM_getValue(universe+"_preset|"+label).split("|");
newRecipient = document.createElement("input");
newRecipient.type = "text";
newRecipient.id = "recipient";
newSubmit = document.createElement("input");
newSubmit.type = "button";
newSubmit.value = "Save preset";
newSubmit.onclick = function(){
newcookie = "";
newcookie += document.getElementById("recipient").value+"|";
newcookie += document.getElementsByName("textfield")[0].value+"|";
newcookie += document.getElementsByName("textarea")[0].value;
if(newcookie.split("|").length == 3){
GM_setValue(universe+"_preset|"+label,newcookie);
}else{
alert("Error! Preset could not be saved!\n\nPlease do not use the '|' sign!");
}
window.close();
};
document.getElementsByTagName("th")[0].innerHTML = "<font color='#FF0000'>Preset mode for label: "+label+"</font>";
document.getElementsByName("recipient")[0].parentNode.appendChild(newRecipient);
deleteElement(document.getElementById("recipient2"));
deleteElement(document.getElementById("attach_signature"));
deleteElement(document.getElementById("resizeLink"));
deleteElement(document.getElementsByTagName("label")[0]);
deleteElement(document.getElementsByTagName("input")[0]);
document.getElementById("Send").parentNode.appendChild(newSubmit);
deleteElement(document.getElementById("Send"));
document.getElementById("recipient").value = infoCookie[0];
document.getElementsByName("textfield")[0].value = infoCookie[1];
document.getElementsByName("textarea")[0].value = infoCookie[2];
}
function deleteElement(element){
var deleteMe = element;
deleteMe.parentNode.removeChild(deleteMe);
}
function addPMshortcuts(){
if(text.indexOf("messages_") < 0) return;
if(GM_getValue(universe+"_quicklinks_groups") == null || GM_getValue(universe+"_quicklinks_pilots") == null){
GM_setValue(universe+"_quicklinks_groups","");
GM_setValue(universe+"_quicklinks_pilots","");
}
function openPopup(url){
newwindow=window.open(url,'name','height=400,width=200');
if(window.focus) {newwindow.focus();}
}
groupArray = loadPresetGroups();
pilotArray = loadPresetPilots();
quicklinks = "<tr><td align=\"left\" style=\"padding:5px;\">";
if(groupArray != ""){
for(i in groupArray){
quicklinks += "<u><b>"+groupArray[i]+"</b></u><br>";
for(j in pilotArray[0]){
if(pilotArray[1][j] == groupArray[i]){
quicklinks += "<a href=\"javascript:newWindow=window.open('http://orion.pardus.at/sendmsg.php?to="+pilotArray[0][j]+"&quicklinks=true','',width=400,height=200);newWindow.focus();newWindow.resizeTo(550,500);newWindow.focus();\"><font color=\""+pilotArray[2][j]+"\">"+pilotArray[0][j]+"</font></a><br>";
}
}
quicklinks += "<br>";
}
}
//show by default, if cookie not set
if(GM_getValue(universe+"_quicklinks_showHide") == "none"){
showHideState = "none";
quicklinks += "<a href=\"javascript:void(0);\" id=\"showHideOptions\">[Show options]</a>";
}else{
showHideState = "block";
quicklinks += "<a href=\"javascript:void(0);\" id=\"showHideOptions\">[Hide options]</a>";
}
quicklinks += "<div id=\"message_quick_advanced\" style=\"display:"+showHideState+"\"><br>";
quicklinks += "<a href=\"javascript:void(0);\" id=\"newGroup\">[Add new group]</a><br>";
quicklinks += "<a href=\"javascript:void(0);\" id=\"newPilot\">[Add new pilot]</a><br>";
quicklinks += "<br>";
quicklinks += "<a href=\"javascript:void(0);\" id=\"sortGroupsLink\">[Sort groups A-Z]</a><br>";
quicklinks += "<a href=\"javascript:void(0);\" id=\"sortPilotsLink\">[Sort pilots A-Z]</a><br>";
quicklinks += "<br>";
quicklinks += "<a href=\"javascript:void(0);\" id=\"deleteGroup\">[Delete group]</a><br>";
quicklinks += "<a href=\"javascript:void(0);\" id=\"deletePilot\">[Delete pilot]</a></div></td></tr>";
tableheaders = document.getElementsByTagName("th");
for(i=0; i<tableheaders.length; i++){
if(tableheaders[i].innerHTML.match("Report")){
targetTable = i;
}
}
tableheaders[targetTable].parentNode.parentNode.parentNode.parentNode.innerHTML += "<table id=\"message_quicklinks\" width=\"135\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" style=\"background:url(http://static.pardus.at/images/bg.gif)\"><tr><th>Quicklinks</th></tr>"+quicklinks+"</table><p> </p>";
sortGroupsLink = document.getElementById("sortGroupsLink");
sortGroupsLink.onclick = function(){
sortAndSave(universe+"_quicklinks_groups");
document.location.reload(true);
};
sortPilotsLink = document.getElementById("sortPilotsLink");
sortPilotsLink.onclick = function(){
sortAndSave(universe+"_quicklinks_pilots");
document.location.reload(true);
};
newGroup = document.getElementById("newGroup");
newGroup.onclick = function(){
addNewGroup();
document.location.reload(true);
};
newPilot = document.getElementById("newPilot");
newPilot.onclick = function(){
addNewPilot();
document.location.reload(true);
};
deletePilot = document.getElementById("deletePilot");
deletePilot.onclick = function(){
deletePilotByName();
document.location.reload(true);
};
deleteGroup = document.getElementById("deleteGroup");
deleteGroup.onclick = function(){
deleteGroupByName();
document.location.reload(true);
};
showHideOptions = document.getElementById("showHideOptions");
showHideOptions.onclick = function(){
if(document.getElementById("message_quick_advanced").style.display != "none"){
document.getElementById("message_quick_advanced").style.display = "none";
GM_setValue(universe+"_quicklinks_showHide","none");
document.getElementById("showHideOptions").innerHTML = "[Show options]";
}else{
document.getElementById("message_quick_advanced").style.display = "block";
GM_setValue(universe+"_quicklinks_showHide","block");
document.getElementById("showHideOptions").innerHTML = "[Hide options]";
}
};
}
function deleteGroupByName(){
delName = prompt("Enter a group you wish to remove");
if(!delName) return;
pilots = new Array();
pilots = loadPresetPilots();
newCookie = "";
for(i in pilots[0]){
if(pilots[1][i] != delName){
newCookie += pilots[0][i]+"~"+pilots[1][i]+"~"+pilots[2][i]+"|";
}
}
newCookie = newCookie.slice(0,-1);
GM_setValue(universe+"_quicklinks_pilots",newCookie);
groups = new Array();
groups = loadPresetGroups();
newGroupCookie = "";
for(i in groups){
if(groups[i] != delName){
newGroupCookie += groups[i]+"|";
}
}
newGroupCookie = newGroupCookie.slice(0,-1);
GM_setValue(universe+"_quicklinks_groups",newGroupCookie);
}
function deletePilotByName(){
delName = prompt("Enter a pilot you wish to remove");
if(!delName) return;
pilots = new Array();
pilots = loadPresetPilots();
newCookie = "";
for(i in pilots[0]){
if(pilots[0][i] != delName){
newCookie += pilots[0][i]+"~"+pilots[1][i]+"~"+pilots[2][i]+"|";
}
}
newCookie = newCookie.slice(0,-1);
GM_setValue(universe+"_quicklinks_pilots",newCookie);
}
function addNewPilot(){
groups = loadPresetGroups();
if(groups == ""){
alert("You have to create at least one group, before you can add a pilot.");
return;
}
newpilotname = prompt("Please enter the pilot you want to save");
newpilotname = newpilotname.replace(/\|/g,"").replace(/~/g,"").trim();
if(!newpilotname) return;
color = prompt("You can enter a color here(If you leave it blank, the link will be white)").replace(/ /g,"");
if(!color) color = "#FFFFFF";
grouptextForPrompt = "";
for(i in groups){
grouptextForPrompt += "\n--> "+groups[i];
}
targetgroup = prompt("Which group do you want to add the pilot \""+newpilotname+"\" to?\nAvailable options are:"+grouptextForPrompt);
targetgroup = targetgroup.replace(/\|/g,"");
if(!inArray(targetgroup,groups) || targetgroup == ""){
alert("Group name invalid. Pilot not saved.");
return;
}
if(GM_getValue(universe+"_quicklinks_pilots") != ""){
GM_setValue(universe+"_quicklinks_pilots",GM_getValue(universe+"_quicklinks_pilots")+"|"+newpilotname+"~"+targetgroup+"~"+color);
}else{
GM_setValue(universe+"_quicklinks_pilots",newpilotname+"~"+targetgroup+"~"+color);
}
}
function inArray(value,arr){
for(i in arr){
if(arr[i] == value) return true;
}
return false;
}
function addNewGroup(){
newgroupname = prompt("Please enter the desired groupname");
newgroupname = newgroupname.replace(/\|/g,"").trim();
if(newgroupname){
if(GM_getValue(universe+"_quicklinks_groups") != ""){
GM_setValue(universe+"_quicklinks_groups",GM_getValue(universe+"_quicklinks_groups")+"|"+newgroupname);
}else{
GM_setValue(universe+"_quicklinks_groups",newgroupname);
}
}
}
function sortAndSave(sourcecookie){
groups = GM_getValue(sourcecookie).split("|").sort(function(a, b){
var x = a.toLowerCase();
var y = b.toLowerCase();
return x < y ? -1 : x > y ? 1 : 0;
});
newCookie = "";
for(i in groups){
newCookie += groups[i]+"|";
}
newCookie = newCookie.slice(0,-1);
GM_setValue(sourcecookie,newCookie);
}
function loadPresetGroups(){
groups = GM_getValue(universe+"_quicklinks_groups").split("|");
return groups;
}
function loadPresetPilots(){
pilotNames = new Array();
pilotGroup = new Array();
pilotColor = new Array();
pilotDataFiles = GM_getValue(universe+"_quicklinks_pilots").split("|");
for(i in pilotDataFiles){
pilotinfo = pilotDataFiles[i].split("~");
pilotNames[i] = pilotinfo[0];
pilotGroup[i] = pilotinfo[1];
pilotColor[i] = pilotinfo[2];
}
pilots = new Array();
pilots[0] = pilotNames;
pilots[1] = pilotGroup;
pilots[2] = pilotColor;
return pilots;
}
function addPresetButtons(){
//only add presetbuttons when opening PMs with quicklinks
//if(text.indexOf("&quicklinks=true") < 0) return;
//add presetbuttons for each PM
if(text.indexOf("sendmsg.php?") < 0) return;
allPresets = loadPresets();
if(allPresets[0] == "") return;
//callback function
function addPresetHandler(target,to,subj,msg){
target.addEventListener("click", function() {setPMToPreset(to,subj,msg);}, false);
}
presetButton = new Array();
for(i in allPresets){
infoCookie = GM_getValue(universe+"_preset|"+allPresets[i]).split("|");
presetButton[i] = document.createElement("input");
presetButton[i].type = "button";
presetButton[i].value = allPresets[i];
addPresetHandler(presetButton[i],infoCookie[0],infoCookie[1],infoCookie[2]);
document.getElementsByTagName("body")[0].appendChild(presetButton[i]);
document.getElementsByTagName("body")[0].appendChild(document.createTextNode(" "));
}
}
function setPMToPreset(to,subj,msg){
if(to != "") document.getElementById("recipient2").value = to;
document.getElementsByName("textfield")[0].value = subj;
document.getElementById("textarea").value = msg+"\n"+document.getElementById("textarea").value;
}
function parseColorCode(messageTable,private){
var msgCell = messageTable.getElementsByTagName("tr")[private?2:3].getElementsByTagName("td")[0];
var skipBR = 0;
var emptyElement = document.createTextNode("");
messageText = msgCell.innerHTML.replace(/&lt;font/gi,'<font').replace(/&lt;\/font&gt;/gi,'</font>');
messageText = messageText.replace(/&lt;u&gt;/gi,'<u>').replace(/&lt;\/u&gt;/gi,'</u>');
messageText = messageText.replace(/&lt;b&gt;/gi,'<b>').replace(/&lt;\/b&gt;/gi,'</b>');
messageText = messageText.replace(/&lt;i&gt;/gi,'<i>').replace(/&lt;\/i&gt;/gi,'</i>');
messageText = messageText.replace(/&gt;/gi,'>').replace(/&quot;/gi,'"');
msgCell.innerHTML = messageText;
}
addLinks();
addReply();
createOptions();
usePMforCookie();
addPMshortcuts();
addPresetButtons();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment