This is in HTML with JavaScript and probably only works in Mozilla.

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
  <head>
    <title>J. M. Inc. mediator bookmarklets</title>
<script>

// escape quotes and backslashses for inclusion in JavaScript "-delimited 
// strings
function qesc(str) {
  return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"')
}

function twodigithex(num) {
  return (Math.floor(num / 16).toString(16) + 
          (num % 16).toString(16)).toUpperCase()
}

// escape special URL characters with %
// problems with #, ^, % still?
function uesc(str) {
  return str.replace(/[ %&?#]/g, 
                     function(achar) { return '%' + twodigithex(achar.charCodeAt(0)) })
}

// The J. M. Inc. mediator doen't cope with slashes in the Malkovich
// word, even escaped.  If you're lucky, it chops off everything after
// the first slash; if you're unlucky, it just gives you an error
// message.  So we remove slashes from the input string as it's typed.

// It handles # marks even worse.

function noslash(str) {
  return str.replace(/[\/#]/g, '')
}

function fix() {
  var input = document.forms.wordform.word
  var a = document.getElementById("changeablelink")
  input.value = noslash(input.value)
  // Mozilla sometimes uses second line of JavaScript URL as default 
  // bookmark title, and doesn't run it, but sometimes it just screws up.
  // I haven't found another way to set the default bookmark title for a 
  // bookmarklet.
  a.setAttribute('href', 
                 'javascript:window.location = "http://web.lfw.org/jminc/' + 
qesc(uesc(uesc(input.value))) + '/" + window.location')
  a.setAttribute("title", "Add this link to your bookmarks; it converts web pages to a 
" + input.value + " Inc. version.")
  a.firstChild.data = input.value + " Inc."
}

function init() {
  fix()  // there might be something already in the box
  // dunno how portable the following is, but it works in Mozilla 1.0
  document.forms.wordform.word.addEventListener("keypress", fix, true)
}

</script>
  </head>

  <body onload="init()">
    <h1>J. M. Inc. mediator bookmarklets</h1>

<p>Note: these are tested in Mozilla 1.0; at least the second one
probably won't work in Netscape 4.x or older, and I have no idea about
other browsers.</p>

<p>A bookmarklet is a little scrap of JavaScript intended to be put in
your web-browser bookmarks file; when you click on it, it executes,
with permission to do whatever it wants with the current page.  Here's
one that runs the current web page through the J. M. Inc. mediator: <a
href="javascript:window.location = 'http://web.lfw.org/jminc/' +
window.location">J. M. Inc.</a></p>

<form name="wordform">And here's a bookmarklet generator; it generates
bookmarklets to your specification, running web pages through the
J. M. Inc. mediator with the specified replacement text.  I find "<a
href="javascript:document.wordform.word.value='asshole';fix()">asshole</a>"
and <a href="javascript:document.wordform.word.value=' ';fix()">a
single space</a> to be amusing.

<input name="word" onchange="fix()" value="Sitaker" 
/><a id="changeablelink" href="#">If this message persists, either your 
browser doesn't support JavaScript or this page is broken for you.</a></form>

<p>Note that, as of this writing (2002-08-01), the underlying mediator
software doesn't do a very good job with words containing '"' (the
double-quote character), '/' (the slash character), or "#" (the hash
character).</p>

<p>Of course, the <a href="javascript:window.location = 'http://crit.org/' + 
window.location;
Crit this page">CritLink</a> bookmarklet is far more useful.</p>

  </body>
</html>



-- 
<[EMAIL PROTECTED]>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
According to my medieval text in the seventh century a finalizer raised a
dead object named Gorth who infected every computer in Cappidocia ending
Roman rule in the region.  -- Charles Fiterman on [EMAIL PROTECTED]

Reply via email to