Mycroft Project Submission Utility

http://mycroftproject.com/submitos.html

HTML

<form><table border="1">
  <tbody><tr>
    <td colspan="2"><input name="setgoogle" value="Prefill for Google" onclick="fillgoogle()" type="button">
    <input name="setbing" value="Prefill for Bing" onclick="fillbing();" type="button"></td></tr>
  <tr>
    <td colspan="2"><input name="showhelp" id="showhelp" onclick="togglehelp();" type="checkbox" checked="checked"><label for="showhelp">Show full instructions?</label><br>
    There is detailed documentation at <a href="http://www.opensearch.org/" target="_blank">OpenSearch.org</a> and with
    reference to Firefox at the <a href="http://developer.mozilla.org/en/docs/Creating_OpenSearch_plugins_for_Firefox" target="_blank">
    Mozilla Developer Center</a>.</td></tr>
  <tr>
    <td><label for="name">Plugin Name:</label></td><td><input name="name" id="name" value="Bing" size="40" maxlength="50" onchange="disablesubmit()" type="text">
    <div class="helpinfo" style="">This is the name of the plugin displayed on Mycroft and also the name that will be displayed in the searchbox of the
    browser. Please standardise where appropriate and omit 'search' and 'plugin' unless part of the brand.</div></td></tr>
  <tr>
    <td><label for="desc">Plugin Description:</label></td><td><input name="desc" id="desc" value="Bing" size="40" maxlength="128" onchange="disablesubmit()" type="text">
    <div class="helpinfo" style="">This is currently underused but is part of the spec. Please include a brief description of the search performed.</div></td></tr>
  <tr>
    <td><label for="engurl">Search URL:</label></td><td><input name="url" id="engurl" value="https://www.bing.com/search?q={searchTerms}&amp;go=&amp;form=QBLH" size="40" onchange="disablesubmit()" type="text">
      <input name="method" id="method_get" value="get" checked="" onchange="posttoggle()" type="radio">
      <label for="method_get">GET</label>
      <input name="method" id="method_post" value="post" onchange="posttoggle()" type="radio">
      <label...

JavaScript

// Workflow functions:
function escapeHTML(string)
{
  string=string.replace(/&(?!amp;)/g,"&amp;");
  string=string.replace(/[<]/g,"&lt;");
  string=string.replace(/>/g,"&gt;");
  return string
}
function escapeHTML2(string)
{
  string=escapeHTML(string);
  string=string.replace(/"/g,"%22");
  return string
}
function ValidateForm() {
  returnval = true;

  var reqfields = ["icontype","author","name","desc","engurl","searchform"];
  if (document.getElementById("incemail").checked) {
    reqfields[reqfields.length] = "email";
  }
  if (document.getElementById("iconsrc_copy").checked) {
    reqfields[reqfields.length] = "iconcppid";
  } else {
    reqfields[reqfields.length] = "iconfile";
  }

  for ( var i in reqfields ) {
    if (document.getElementById(reqfields[i]).value.length < 1) {
      document.getElementById(reqfields[i]).style.backgroundColor="#FFBFBF";
      returnval = false;
    } else {
      document.getElementById(reqfields[i]).style.backgroundColor="";
    }
  }

  if (returnval) {
    if ( !( (document.getElementById("method_get").checked && /{searchTerms}/.test(document.getElementById("engurl").value) )
        || (document.getElementById("method_post").checked && /{searchTerms}/.test(document.getElementById("params").value) ) ) ) {
      returnval = false;
      alert("No {searchTerms} parameter found. (Case sensitive)");
    }
  } else {
    alert("Please complete required fields and generate again.");
  }

  return returnval;
}
function buildplugin() {
  if ( ValidateForm() ) {
  var D = new Date().toUTCString();
  var author = document.getElementById("author").value;
  var email = document.getElementById("email").value;
  if (document.getElementById("incemail").checked) {
    var contact = '  <Contact>' + escapeHTML(email) + '<\/Contact>\n';
  } else {
    var contact = '';
  }
  var name = document.getElementById("name").value;
  var desc = document.getElementById("desc").value;
  var url = document.getElementById("engurl").value;
  if...