-1

its my first posting so be gentile.

I'm looking to get a Greasemonkey script coded to take certain snippets of data, in this case the Agent ID and Ticket Number and export them to Excel.

I've hacked together something which basically plops the details into outlook to email it onwards to someone but Im just looking to 'correlate' on a webpage, however right now I have limited resources in the office and no access to create a MySQL DB internally (though this should be done for me soon) and likely make things much easier :)

This is the code I have from the existing script which also outputs the results to a page that doesn't exist anymore (I get the feeling the previous guy was thinking the same as I was)

// ==UserScript==
// @name           Easy Feedback
// @namespace      http://blah
// @description    Easy feedback buttons
// @include        https://blah.example.com/custdetails-new.html*
// @include        https://blah.example.com/ticket_show.html*
// ==/UserScript==

// Inject jQuery into the host
function addJQuery(callback) {
var script = document.createElement("script");
script.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js");
script.addEventListener('load', function() {
    var script = document.createElement("script");
    script.textContent = "(" + callback.toString() + ")();";
    document.body.appendChild(script);
}, false);
document.body.appendChild(script);
}

// Burst out of its stomach
function main() {
// Get the current URL
var sAgent = "";
var sTicket = "";

// Get current ticket (if possible)
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

for (var i = 0; i < hashes.length; i++) {
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
}

if (vars["ticket_id"]) {
    sTicket = vars["ticket_id"];
}

// Add feedback buttons
$("td:contains('Company staff')")
.not(":contains('Raised:')")
.not(":contains('by:')")
.each(function() {
    var tmpTicket = "";

    if (sTicket == "") {
        var tmp = $(this).closest(":contains('Ticket:')").children(0).children(0).children(0).children(0).children(0).children(0).text();
        var matched = tmp.match(/Ticket:[\s]+(.)+/);
        tmpTicket = matched[0].substr(8);
    } else {
        tmpTicket = sTicket;
    }

    tmp = ($(this).text()).match(/.+\(/);
    sAgent = tmp[0].substr(0, tmp[0].length - 1);

    $(this).append('<br /><br /><a href="mailto:mail@example.com?subject=Feedback on ' + sAgent + ' (' + tmpTicket + ')&amp;body=Agent: ' + sAgent + '%0ATicket: ' + tmpTicket + '%0A%0A%0ADetails:">Feedback</a>').children(0).click(function() {
        $(this).parent().parent().fadeOut(200);

         Record the click for Monitoring
        var tmpId = Math.floor(Math.random()*100);
        $('<iframe name="feedback' + tmpId + '" id="feedback' + tmpId + '" src="WEBSITE/Feedback/record.html?ticket=' + tmpTicket + '&agent=' + sAgent + '" style="display:none;" />').load(function() {
            $(this).remove();
        }).appendTo('body');

        $(this).parent().parent().fadeIn(200);
    });;
});
}

// Plant that seed
addJQuery(main);

So... yeah any advice would be greatly appreciated.

I will throw my hands up and admit I haven't coded for a while but what I have done while here is fix broken code to make things work so my coding is the more 'hack and slash' with no specialization... :/

I get the feeling that he pointed this to a DB somewhere and then displayed the results on the html page though I cant be sure as this was created long before my time with the company

Dan
  • 25
  • 6

1 Answers1

0

This code is logging the operation within the iframe bit, making a GET request to a remote service:

WEBSITE/Feedback/record.html?ticket=' + tmpTicket + '&agent=' + sAgent + '

Possibly there is (or should be) some server side service in that URL that catches the request and logs it. If your problem is that this service is no longer available, I would explore two possible solutions:

  1. Create your own logging service that saves the data, this is necessary if you log from different browsers. PHP allows you to create such a service very easily, this is all the code you need to append the request parameters into a CSV file on the server:

    <?php
    $fp = fopen('log.csv', 'a');
    fwrite($fp, $_REQUEST['ticket'] . ',' . $_REQUEST['agent']);
    fclose($fp);
    ?>
    
  2. Keep data locally in JavaScript and export it using HTML5 download, see response to Export javascript data to CSV file without server interaction

Community
  • 1
  • 1
EmirCalabuch
  • 4,756
  • 1
  • 25
  • 20
  • Thank you, I decided to go with option 1, and im waiting on some space to be freed up on a server (handily wont take much) on the flip side the office also found a way to use this for a further monitoring system they are looking to implement company wide.... 2 birds 1 poorly executed script and all that. – Dan Apr 14 '15 at 14:27