Forum Moderators: open

Message Too Old, No Replies

Replacing Text in Online Software

         

SuzyUK

8:24 am on Jun 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



think this is where this should go..

Would like to use a SaaS application, but it's got the USD $ symbol hardcoded

The only actual instant problem for now is the $ sign that's displayed on the Customer receipt, as I'm sure the staff could work with seeing the dollar sign on the GUI, after the figures are pulled to another application for accounting or invoicing the issue then becomes moot

I found a Mozilla Add-on that will replace text but the add-on only partially works because some aspects of unfinished transactions are AJAX produced (I think?), i.e. if you go through the whole sale and do not allow it to print the receipt but instead save and then recall the receipt for printing it works you get the £ sign on the recalled document, but if you complete the sale normally you get the dollar.

Have contacted the company behind the software and it is in the works to localise the software but am looking for that temporary something I can use now until that time comes..

It's not the end of the world as I can get that £ receipt, but it would be nice if it could be automated without the extra step, so I wondered if there is any way of doing/capturing this clientside even with the Ajax..

am prepared to install Greasemonkey or even try to build a custom add-on if it's possible, does this sound even remotely possible?

Fotiman

9:14 pm on Jun 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That does sound possible using Greasemonkey. The trick would probably be determining what events to listen for. Alternatively, you could write a script that executes every x ms (in other words, it's constantly checking for a $), but even that could miss some values if the interval was not small enough.

Once the AJAX code executes, is there a particular element that gets added to the DOM (something with a unique ID for example)?

Fotiman

10:50 pm on Jun 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Here's a quick Greasemonkey script that might do what you need. Replace the domains, tokens, etc. with your own values. I tested this in Chrome, but should work in Firefox w/ Greasemonkey too. Watch for URL replacement by the forums.


// ==UserScript==
// @name Replace Dollar
// @description Replaces the USD symbol with GBP symbol
// @include http://www.w3schools.com/*
// ==/UserScript==
//Name: Replace Dollar
//Version: 0.1
//Author: Peter Foti
//Last update : 2010-06-26
//Note, my test page was
//http://www.w3schools.com/ajax/ajax_example.asp
//which has some AJAX that can pull in data
var NODE_SELECTORS = '#myDiv', // Replace with your own selector
POLL_INTERVAL = 1000, // This will run every 1 second
TOKEN = 'technique', // Replace with '$'
REPLACE_WITH = '£'; // This is what it will get replaced with
function each(list, callback) {
Array.prototype.forEach.call(list, callback);
};
function filter(list, callback) {
return Array.prototype.filter.call(list, callback);
};
(function () {
setTimeout(arguments.callee, POLL_INTERVAL);
var targetNodes = document.querySelectorAll(NODE_SELECTORS);
if (! targetNodes.length) {
return;
}
each(targetNodes, function(n){
var h = n.innerHTML;
h = h.replace(TOKEN,REPLACE_WITH);
n.innerHTML = h;
});
})();

SuzyUK

8:13 am on Jun 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Fotiman, I'll give that a try today thanks,

>>(something with a unique ID for example)?

not unique as far as I can see, the $ symbols, in question do appear in table cells with ID's, I could collect every instance of them for an array?, Though sometimes it's an input box.. but like I said not too worried about the inputs just the actual subtotal, totals and tax amounts should do..

thanks for taking the time to provide some code, will see how I get on and let you know :)

SuzyUK

11:48 am on Jun 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Foti, it's working great (once I upgraded my test area to 3.5 ;)) - and on the last page (receipt) the receipt is wrapped in it's own unique ID

so my selector list this:
var NODE_SELECTORS = 'div.do_print table td, table.register_sale_totals td, table.payment_lists button',

the first being the main receipt, the other just a couple I tried out to see if would help the GUI.. is this the right way the set up the variable or am I using my CSS too literally, should I make the selectors less specific?


however.. on one of the pages there are 2 x search functions (customer & Product) and those inputs will no longer focus I can't see that the selectors are affecting these search buttons, so what would be?

I've discovered the application itself uses the dojo script library if that's any help

and the affected search boxes source look like this:

<input tabindex="1" size="20" maxlength="255" id="add_search_item_text" name="add_search_item_text" onkeypress="if (onEnterKey(event,function () { example.register.addItemSearch(dojo.byId('add_search_item_text')); })) return false;" value="" autocomplete="off" title="Add Item Search" type="text">

I can get it to focus if I hold my mousekey down but the scripts 1sec refresh seems to unfocus it?

SuzyUK

3:29 pm on Jun 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



cancel the above question Fotiman,

it's works great as is, Thank YOU!

(the "do_print" div wasn't as unique as I thought :o)

I can actually do a lot more that just the receipt with this too.. so many thanks for your help :)

Fotiman

3:47 pm on Jun 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh good! Glad you got it working! I should point out that this particular script is a bit of a brute. That is, it's rewriting the innerHTML of certain nodes, so if you have event listeners, that could cause problems depending on how those listeners are assigned. But it sounds like it's working for your case, so that's good. :) Happy to help.