title: Javascript for conditional URL append or redirect based on window.location.href
body: <p>I am trying to make a bookmarklet that when clicked will check the URL of the current tab/window to see if it contains 'char1' and/or 'char2' (a given character). If both chars are present it redirects to another URL, for the other two it will append the current URL respectively.</p>
  
  <p>I believe there must be a more elegant way of stating this than the following (which has so far worked perfectly for me) but I don't have great knowledge of Javascript. My (unwieldy &amp; repetitive) working code (apologies):</p>
  
  <pre><code>if (window.location.href.indexOf('char1') != -1 &amp;&amp;
      window.location.href.indexOf('char2') != -1)
  {
      window.location="https://website.com/";
  }
  else if (window.location.href.indexOf('char1') != -1)
  {
      window.location.assign(window.location.href += 'append1');
  }
  else if (window.location.href.indexOf('char2') != -1)
  {
      window.location.assign(window.location.href += 'append2');
  }
  </code></pre>
  
  <p>Does exactly what I need it to but, well... not very graceful to say the least.</p>
  
  <p>Is there a simpler way to do this, perhaps with vars or a pseudo-object? Or better code?</p>