Changing words stealthily

Below we demonstrate some Javascript code which uses the jQuery library to change certain words in a passage of text. It could be used in a practical joke.

The intention was to achieve stealth by dividing the change into a series of small modifications; but whether the idea works is open to question.

The replacements to make are hardcoded, as is the rate at which modifications are made; but it would be easy to expose these parameters in the user interface.

The software has been tested on the following platforms:

  • Firefox 4.0 on Debian 6.0
  • Chromium 10.0.648.204 from Debian Unstable
  • Internet Explorer 8 on Microsoft Windows 7

It works perfectly in Internet Explorer, tolerably well in Firefox, though with a few little bugs, and buggily in Chromium. I am fairly confident that the bugs are in the browsers, and not in the software presented here.

To rerun the application, you'll need to reload the current page.

The passage below is the first paragraph of Macaulay's History of England. In the unlikely event that you want to use the code, you can consider it to be in the public domain.

Highlight words

I purpose to write the history of England from the accession of King James the Second down to a time which is within the memory of men still living. I shall recount the errors which, in a few months, alienated a loyal gentry and priesthood from the House of Stuart. I shall trace the course of that revolution which terminated the long struggle between our sovereigns and their parliaments, and bound up together the rights of the people and the title of the reigning dynasty. I shall relate how the new settlement was, during many troubled years, successfully defended against foreign and domestic enemies; how, under that settlement, the authority of law and the security of property were found to be compatible with a liberty of discussion and of individual action never before known; how, from the auspicious union of order and freedom, sprang a prosperity of which the annals of human affairs had furnished no example; how our country, from a state of ignominious vassalage, rapidly rose to the place of umpire among European powers; how her opulence and her martial glory grew together; how, by wise and resolute good faith, was gradually established a public credit fruitful of marvels which to the statesmen of any former age would have seemed incredible; how a gigantic commerce gave birth to a maritime power, compared with which every other maritime power, ancient or modern, sinks into insignificance; how Scotland, after ages of enmity, was at length united to England, not merely by legal bonds, but by indissoluble ties of interest and affection; how, in America, the British colonies rapidly became far mightier and wealthier than the realms which Cortes and Pizarro had added to the dominions of Charles the Fifth; how in Asia, British adventurers founded an empire not less splendid and more durable than that of Alexander.