Created
June 29, 2013 07:47
-
-
Save lgoldstien/5890269 to your computer and use it in GitHub Desktop.
A greasemonkey script that is causing me problems
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 Give Me Tickets | |
// @description All the stock responses and stuff you could possibly need to get working on tickets | |
// @author Lawrence Goldstien ( lgoldstien@*******.co.uk ) | |
// @namespace | |
// @include | |
// @grant none | |
// ==/UserScript== | |
console.log("Gimme Tickets: Starting to load the script"); | |
// Ticket text boxes | |
var gt_ticket_text = document.getElementsByName('ticket_comment_text')[0]; | |
var gt_text_text = document.getElementsByName('sms_ticket_comment_text')[0]; | |
var gt_signoff_text = document.getElementsByName('body')[0]; | |
// Ticket information | |
if ( document.URL.indexOf("ticket_create") == -1 ){ | |
var gt_ticket_number = document.getElementsByName('ticket_id')[0].value; | |
} else { | |
var gt_ticket_number = ''; | |
console.log("We have no ticket number as we are creating a ticket.") | |
} | |
//Get customer username | |
function getUsername() { | |
var allTD = document.getElementsByTagName("td"); | |
return allTD[6].innerHTML.replace(/^\s*|\s*$/g,''); | |
} | |
//Get realm | |
function getRealm() { | |
var allTD = document.getElementsByTagName("td"); | |
return allTD[18].innerHTML.replace(/^\s*|\s*$/g,''); | |
} | |
// Load username | |
var gt_username = getUsername(); | |
// Load realm | |
var gt_realm = getRealm(); | |
// DO NOT EDIT ABOVE THIS LINE!!! // | |
/************************************************************************************** | |
This section contains some help on how to add your own stock responses | |
All the stock response buttons are contained in an array called gt_all_the_stocks and can be added to as you want | |
var gt_all_the_stocks = [ | |
[ // Each new array element in the root is a row in the page | |
// Each item in this array is a button to be added with all the information needed. | |
["Button Title", "Text to be added to the main ticket", "Something for the SMS", "Add to the signoff at the bottom.", "A console message if you need it!", "Quick Cause", ], | |
] | |
]; | |
You can include the following user information in your stock response: | |
Customer Username: " + gt_username + " | |
Account Realm: " + gt_realm + " | |
Ticket Number (if set): " + gt_ticket_number + " | |
If you find something goes wrong then please try the following steps: | |
1. Uncomment the console.log(gt_all_the_stocks); line after the array to see if it all prints out. | |
2. Make sure that the strings that make up the array have " around them, not ' | |
3. Make sure any symbols like ', " or ` have a backslash before, like this: "Lawrence\'s" | |
**************************************************************************************/ | |
var gt_all_the_stocks = [ | |
[ // Greetings | |
["Thank you, touch", "Thank you for getting in touch,\n\n", "", "", "Added thank you", "C5434",], | |
["Time on phone", "Thank you for getting in touch,\n\n", "", "", "Added thank you", "C5434",], | |
["Thank you, touch", "Thank you for getting in touch,\n\n", "", "", "Added thank you", "C5434",], | |
["Thank you, touch", "Thank you for getting in touch,\n\n", "", "", "Added thank you", "C5434",], | |
["Thank you, touch", "Thank you for getting in touch,\n\n", "", "", "Added thank you", "C5434",], | |
], | |
[ // BB Faults stuff | |
["SFI Required", "some stock text stuff with some symbols \'", "Something for the text area", "Add something to the bottom of the signoff page\!", "A console message if you need it!", "C463", ], | |
] | |
]; | |
// Uncomment below to debug the set up you are using | |
// console.log(gt_all_the_stocks); | |
// ------ DO NOT EDIT BELOW THIS LINE ------ // | |
// Ticket functions | |
//Set ticket cause | |
function setCause(quickId) { | |
document.getElementsByName('quick_id')[0].value = quickId; | |
} | |
//Add to signoff | |
function setSignoff(text) { | |
document.getElementsByName('body')[0].value = document.getElementsByName('body')[0].value + text; | |
} | |
//Set response | |
function setResponse(newText) { | |
document.getElementsByName('ticket_comment_text')[0].value = newText; | |
} | |
//Set SMS | |
function setSMS(newText) { | |
document.getElementsByName('sms_ticket_comment_text')[0].value = newText; | |
} | |
//Send to customer | |
function toCustomer() { | |
document.getElementsByName('target_user')[0][1].selected = true; | |
} | |
// Make a div | |
function createDiv(idString) { | |
var newDiv = document.createElement('div'); | |
newDiv.id = idString; | |
newDiv.style.marginTop = '5px'; | |
newDiv.style.marginBottom = '5px'; | |
newDiv.style.paddingTop = '5px'; | |
return newDiv; | |
} | |
//Surround selected text | |
function surround(pre, post) { | |
var textarea = document.getElementsByName('ticket_comment_text')[0]; | |
var len = textarea.value.length; | |
var start = textarea.selectionStart; | |
var end = textarea.selectionEnd; | |
var sel = textarea.value.substring(start, end); | |
var replace = pre + sel + post; | |
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len); | |
textarea.selectionStart = start; | |
textarea.selectionEnd = start + replace.length; | |
} | |
//Create a button | |
function addButton(container, text, onclickFunc) { | |
// Create a new button | |
var buttonnode= document.createElement('input'); | |
// Set some generic attributes | |
buttonnode.setAttribute('type','button'); | |
buttonnode.setAttribute('name',text); | |
buttonnode.setAttribute('value',text); | |
buttonnode.setAttribute('class', 'gt_buttons'); | |
// Attach the event | |
container.appendChild(buttonnode) | |
buttonnode.addEventListener("click", onclickFunc, true); | |
// Return it | |
return buttonnode; | |
} | |
function addHr(container) { | |
var hr = document.createElement("hr"); | |
container.appendChild(hr); | |
return hr; | |
} | |
// Build the menu for the ticket | |
// Make the one above the ticket box | |
console.log("Building the button container"); | |
var div_above = createDiv('above_ticket'); | |
div_above.style.display = 'block'; | |
var make_div_above = document.createElement('div'); | |
// Put some Pool control in there | |
console.log(gt_all_the_stocks); | |
// The button adding script goes here and will iterate through the gt_all_the_stocks array to get the tickets | |
for (var i1 = 0; i1 < gt_all_the_stocks.length; i1++) { | |
console.log("Setting up row #" + i1 + " " + typeof i1); | |
row = i1; | |
for (var i2 = 0; i2 < gt_all_the_stocks[i1].length; i2++) { | |
/* Set up the variables for the button | |
var title = gt_all_the_stocks[i1][i2][0]; | |
var main_text = gt_all_the_stocks[i1][i2][1]; | |
var sms_text = gt_all_the_stocks[i1][i2][2]; | |
var signoff_text = gt_all_the_stocks[i1][i2][3]; | |
var console_message = gt_all_the_stocks[i1][i2][4]; | |
var quick_cause = gt_all_the_stocks[i1][i2][5]; | |
*/ | |
button = i2; | |
addButton(make_div_above, gt_all_the_stocks[row][button][0], function(){ | |
if ( gt_all_the_stocks[row][button][1].length != 0 ){ | |
surround("", gt_all_the_stocks[row][button][1]); | |
} | |
if ( gt_all_the_stocks[row][button][2].length != 0 ){ | |
setSMS(gt_all_the_stocks[row][button][2]); | |
} | |
if ( gt_all_the_stocks[row][button][3].length != 0 ){ | |
setSignoff(gt_all_the_stocks[row][button][3]); | |
} | |
if ( gt_all_the_stocks[row][button][4].length != 0 ){ | |
console.log("Stock Tickets: " + gt_all_the_stocks[row][button][4]); | |
} | |
if ( gt_all_the_stocks[row][button][5].length != 0 ){ | |
setCause(gt_all_the_stocks[row][button][5]); | |
} | |
}); | |
// alert(gt_all_the_stocks[i1][i2]); | |
} | |
addHr(make_div_above); | |
// alert(gt_all_the_stocks[i]); | |
} | |
// The standard HTML based stuff goes here | |
addButton(make_div_above, '<b>', function() { | |
surround('<b>', '</b>'); | |
}); | |
addButton(make_div_above, '<img>', function() { | |
img = prompt("Give me the image URL",""); | |
surround('<img src="' + img + '"><div style="clear: both"></div>', ''); | |
}); | |
addButton(make_div_above, '<a href>', function() { | |
url = prompt("Give me the URL",""); | |
surround('<a href="' + url + '">','</a>'); | |
}); | |
addButton(make_div_above, '<i>', function() { | |
surround('<i>', '</i>'); | |
}); | |
addButton(make_div_above, '<u>', function() { | |
surround('<u>', '</u>'); | |
}); | |
addButton(make_div_above, 'Red', function() { | |
surround('<font color="red">', '</font>'); | |
}); | |
addButton(make_div_above, 'Green', function() { | |
surround('<font color="green">', '</font>'); | |
}); | |
addButton(make_div_above, 'Orange', function() { | |
surround('<font color="orange">', '</font>'); | |
}); | |
addButton(make_div_above, 'Help?', function() { | |
surround('<font color="orange">', '</font>'); | |
}); | |
// Put the buttons on top of the ticket text | |
make_div_above.appendChild(div_above); | |
gt_ticket_text.parentNode.insertBefore(make_div_above, gt_ticket_text); | |
// Let the world know you are loaded | |
console.log("The gimme tickets script is loaded."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment