Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    30
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Thumbs up I've coded strong javascript search engine

    Well, this is only beginning and kinda beta, but this is just awesome!
    This is 100% secured, but yet unfinished.
    This is huuuuuge!
    I've created temporal apache server on my computer to show how it works:
    http://80.222.127.106/downloads.php

    Every script needed is located at source code of downloads.php

    eg.
    Code:
    <script>
    
    function alpha(e) {
    
    var k;
    
    document.all ? k = e.keyCode : k = e.which;
    
    if (e.keyCode == 13)
    
    {
    
    search();
    
    }
    
    else
    
    {
    
    return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k > 47 && k < 58))
    
    }
    
    }
    
    function search()
    
    {
    
    var srchs1 = document.getElementById('search').value.toUpperCase();
    
    var srchsspace = srchs1.replace(/ /gi, ". .");
    
    var srchs2 = srchsspace.replace(/A/gi,".A.");
    
    var srchs3 = srchs2.replace(/B/gi,".B.");
    
    var srchs4 = srchs3.replace(/C/gi,".C.");
    
    var srchs5 = srchs4.replace(/D/gi,".D.");
    
    var srchs6 = srchs5.replace(/E/gi,".E.");
    
    var srchs7 = srchs6.replace(/F/gi,".F.");
    
    var srchs8 = srchs7.replace(/G/gi,".G.");
    
    var srchs9 = srchs8.replace(/H/gi,".H.");
    
    var srchs10 = srchs9.replace(/I/gi,".I.");
    
    var srchs11 = srchs10.replace(/J/gi,".J.");
    
    var srchs12 = srchs11.replace(/K/gi,".K.");
    
    var srchs13 = srchs12.replace(/L/gi,".L.");
    
    var srchs14 = srchs13.replace(/M/gi,".M.");
    
    var srchs15 = srchs14.replace(/N/gi,".N.");
    
    var srchs16 = srchs15.replace(/O/gi,".O.");
    
    var srchs17 = srchs16.replace(/P/gi,".P.");
    
    var srchs18 = srchs17.replace(/Q/gi,".Q.");
    
    var srchs19 = srchs18.replace(/R/gi,".R.");
    
    var srchs20 = srchs19.replace(/S/gi,".S.");
    
    var srchs21 = srchs20.replace(/T/gi,".T.");
    
    var srchs22 = srchs21.replace(/U/gi,".U.");
    
    var srchs23 = srchs22.replace(/V/gi,".V.");
    
    var srchs24 = srchs23.replace(/W/gi,".W.");
    
    var srchs25 = srchs24.replace(/X/gi,".X.");
    
    var srchs26 = srchs25.replace(/Y/gi,".Y.");
    
    var srchs27 = srchs26.replace(/0/gi,".0.");
    
    var srchs28 = srchs27.replace(/1/gi,".1.");
    
    var srchs29 = srchs28.replace(/2/gi,".2.");
    
    var srchs30 = srchs29.replace(/3/gi,".3.");
    
    var srchs31 = srchs30.replace(/4/gi,".4.");
    
    var srchs32 = srchs31.replace(/5/gi,".5.");
    
    var srchs33 = srchs32.replace(/6/gi,".6.");
    
    var srchs34 = srchs33.replace(/7/gi,".7.");
    
    var srchs35 = srchs34.replace(/8/gi,".8.");
    
    var srchs36 = srchs35.replace(/9/gi,".9.");
    
    var srchs = srchs36.replace(/Z/gi,".Z.");
    
    var srch = document.getElementById('lmao').innerHTML; 
    
    var matchPos = srch.search(srchs);
    
    if((!srchs) || (srchs == ".W..R..I..T..E.. ..K..E..Y..W..O..R..D..S...."))
    
    {
    
    return;
    
    }
    
    else if(matchPos != -1)
    
    {
    
    var cursor = "'pointer'";
    
    var location = "'downloads.php'";
    
    var match = document.getElementById('lmao').innerHTML.replace(srchs, '<b id="result" onclick="window.scroll(0,0)" onmouseover="this.style.cursor=' + cursor + '">' + srchs.fontcolor("Red") + '</b>');
    
    document.getElementById('lmao').innerHTML=match;
    
    document.getElementById('lolz').innerHTML='<IMG SRC="images/backbutton.gif" onclick="window.location=' + location + '" onmouseover="this.style.cursor=' + cursor + '"><br><br><br>';
    
    setTimeout("tests()", 1);
    
    }
    
    else
    
    {
    
    alert("Nothing found, please, try again");
    
    }
    
    }
    
    function tests()
    
    {
    
    var posit = document.getElementById('result');
    
    var posit1 = posit.offsetTop - 200;
    
    window.scroll(0,posit1);
    
    }
    
    </script>
    Code:
    <div id="lolz"><input type="text" style="text-align: center" name="search" id="search" value="Write keywords..." onFocus="value=''" onkeypress="return alpha(event)">
    
    <br><br>
    
    <img src="http://img200.imageshack.us/img200/2181/searchbutton.gif" onmouseover="this.style.cursor='pointer'" onclick="search()">
    
    <br><br>
    
    </div>
    div to search from:
    Code:
    <div id="lmao">
    .H..E..L..L..O.!
    </div>
    It says .H..E..L..L..O.! but when you search for "hello" or "h" or "he" or "hel" or "hell" or "hello" or "ello" etc, it will find well.

  • #2
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Optimized Code

    Should really do some code formatting, makes your code easier to read and dissect for others. I'm sure there is more to do, but this should be a great foundation to start from.
    Code:
    <html>
    <head>
    <script>
    function alpha(e)
    {
     var k;
     document.all ? k = e.keyCode : k = e.which;
     if (e.keyCode == 13)
     {
      search();
     }
     else
     {
      return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k > 47 && k < 58));
     }
    }
    
    function search()
    {
     var srchs1 = document.getElementById('search').value.toUpperCase();
     var srchsspace = srchs1.replace(/ /gi, ". .");
     var srchs2 = srchsspace.replace(/A/gi,".A.");
     var srchs3 = srchs2.replace(/B/gi,".B.");
     var srchs4 = srchs3.replace(/C/gi,".C.");
     var srchs5 = srchs4.replace(/D/gi,".D.");
     var srchs6 = srchs5.replace(/E/gi,".E.");
     var srchs7 = srchs6.replace(/F/gi,".F.");
     var srchs8 = srchs7.replace(/G/gi,".G.");
     var srchs9 = srchs8.replace(/H/gi,".H.");
     var srchs10 = srchs9.replace(/I/gi,".I.");
     var srchs11 = srchs10.replace(/J/gi,".J.");
     var srchs12 = srchs11.replace(/K/gi,".K.");
     var srchs13 = srchs12.replace(/L/gi,".L.");
     var srchs14 = srchs13.replace(/M/gi,".M.");
     var srchs15 = srchs14.replace(/N/gi,".N.");
     var srchs16 = srchs15.replace(/O/gi,".O.");
     var srchs17 = srchs16.replace(/P/gi,".P.");
     var srchs18 = srchs17.replace(/Q/gi,".Q.");
     var srchs19 = srchs18.replace(/R/gi,".R.");
     var srchs20 = srchs19.replace(/S/gi,".S.");
     var srchs21 = srchs20.replace(/T/gi,".T.");
     var srchs22 = srchs21.replace(/U/gi,".U.");
     var srchs23 = srchs22.replace(/V/gi,".V.");
     var srchs24 = srchs23.replace(/W/gi,".W.");
     var srchs25 = srchs24.replace(/X/gi,".X.");
     var srchs26 = srchs25.replace(/Y/gi,".Y.");
     var srchs27 = srchs26.replace(/0/gi,".0.");
     var srchs28 = srchs27.replace(/1/gi,".1.");
     var srchs29 = srchs28.replace(/2/gi,".2.");
     var srchs30 = srchs29.replace(/3/gi,".3.");
     var srchs31 = srchs30.replace(/4/gi,".4.");
     var srchs32 = srchs31.replace(/5/gi,".5.");
     var srchs33 = srchs32.replace(/6/gi,".6.");
     var srchs34 = srchs33.replace(/7/gi,".7.");
     var srchs35 = srchs34.replace(/8/gi,".8.");
     var srchs36 = srchs35.replace(/9/gi,".9.");
     var srchs = srchs36.replace(/Z/gi,".Z.");
     var srch = document.getElementById('lmao').innerHTML; 
     var matchPos = srch.search(srchs);
     if((!srchs) || (srchs == ".W..R..I..T..E.. ..K..E..Y..W..O..R..D..S...."))
     {
      return;
     }
     else if(matchPos != -1)
     {
      var cursor = "'pointer'";
      var location = "'downloads.php'";
      var match = document.getElementById('lmao').innerHTML.replace(srchs, '<b id="result" onclick="window.scroll(0,0)" onmouseover="this.style.cursor=' + cursor + '">' + srchs.fontcolor("Red") + '</b>');
      document.getElementById('lmao').innerHTML=match;
      document.getElementById('lolz').innerHTML='<IMG SRC="images/backbutton.gif" onclick="window.location=' + location + '" onmouseover="this.style.cursor=' + cursor + '"><br><br><br>';
      setTimeout("tests()", 1);
     }
     else
     {
      alert("Nothing found, please, try again");
     }
    }
    
    function tests()
    {
     var posit = document.getElementById('result');
     var posit1 = posit.offsetTop - 200;
     window.scroll(0,posit1);
    }
    </script>
    </head>
    <body>
    <div id="lolz">
     <input type="text" style="text-align: center" name="search" id="search" value="Write keywords..." onFocus="value=''" onkeypress="return alpha(event)" />
     <br /><br />
     <img src="http://img200.imageshack.us/img200/2181/searchbutton.gif" onmouseover="this.style.cursor='pointer'" onclick="search()" />
     <br /><br />
    </div>
    
    <div id="lmao">
     .H..E..L..L..O.!
    </div>
    </body>
    </html>

  • #3
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Why not do this for the search function, saves you time in saying var all the time.
    Code:
    function search() {
      var srchs = document.getElementById('search').value.toUpperCase()
                  .replace(/ /gi,". .").replace(/A/gi,".A.").replace(/B/gi,".B.")
                  .replace(/C/gi,".C.").replace(/D/gi,".D.").replace(/E/gi,".E.")
                  .replace(/F/gi,".F.").replace(/G/gi,".G.").replace(/H/gi,".H.")
                  .replace(/I/gi,".I.").replace(/J/gi,".J.").replace(/K/gi,".K.")
                  .replace(/L/gi,".L.").replace(/M/gi,".M.").replace(/N/gi,".N.")
                  .replace(/O/gi,".O.").replace(/P/gi,".P.").replace(/Q/gi,".Q.")
                  .replace(/R/gi,".R.").replace(/S/gi,".S.").replace(/T/gi,".T.")
                  .replace(/U/gi,".U.").replace(/V/gi,".V.").replace(/W/gi,".W.")
                  .replace(/X/gi,".X.").replace(/Y/gi,".Y.").replace(/Z/gi,".Z.")
                  .replace(/0/gi,".0.").replace(/1/gi,".1.").replace(/2/gi,".2.")
                  .replace(/3/gi,".3.").replace(/4/gi,".4.").replace(/5/gi,".5.")
                  .replace(/6/gi,".6.").replace(/7/gi,".7.").replace(/8/gi,".8.")
                  .replace(/9/gi,".9."),
          srch = document.getElementById('lmao').innerHTML,
          matchPos = srch.search(srchs);
      if((!srchs) || (srchs == ".W..R..I..T..E.. ..K..E..Y..W..O..R..D..S...."))  {
        return;
      } else if(matchPos != -1) {
        var cursor   = "'pointer'",
            location = "'downloads.php'";
            match    = document.getElementById('lmao').innerHTML.replace(srchs, '<b id="result" onclick="window.scroll(0,0)" onmouseover="this.style.cursor=' + cursor + '">' + srchs.fontcolor("Red") + '</b>');
        document.getElementById('lmao').innerHTML=match;
        document.getElementById('lolz').innerHTML='<IMG SRC="images/backbutton.gif" onclick="window.location=' + location + '" onmouseover="this.style.cursor=' + cursor + '"><br><br><br>';
        setTimeout("tests()", 1);
      } else {
        alert("Nothing found, please, try again");
      }
    }
    Last edited by DJCMBear; 12-24-2010 at 06:07 AM.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •