amberstudent / Simply Stay Availibility

// ==UserScript==
// @name         Simply Stay Availibility
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://ohmyroom.space/rest/init/rooms/1
// @grant        none
// @license      MIT
// ==/UserScript==

function includejQuery(callback) {
    if(window.jQuery)
    {
        // jQuery is already loaded, set up an asynchronous call
        // to the callback if any
        if (callback)
        {
            setTimeout(function() {
                callback(jQuery);
            }, 0);
        }
    }
    else
    {
        // jQuery not loaded, load it and when it loads call
        // noConflict and the callback (if any).
        var script = document.createElement('script');
        script.onload = function() {
            jQuery.noConflict();
            if (callback) {
                window.$ = jQuery;
                callback(jQuery);
            }
        };
        script.src = "http://code.jquery.com/jquery-2.1.1.min.js";
        document.getElementsByTagName('head')[0].appendChild(script);
    }
}


(function() {
    includejQuery(()=>{
      const html = `
       <div class="container" style="width: 100%; padding: 20px; background-color: white; position: fixed; top: 0">
         <span class="label" >Date in format 2018-05-31 </span><input class="input"/>
          <button> Go</button>
       </div>
       
      `;



        let string = $('body').html();
        const oldString = string;
        let newString = '';


      $('body').append(html);
      $('.container button').on('click',()=>{
                   string = oldString;
        const date = $('.input').val();
        console.log(date);
          for(var i = 0 ; i < string.length - 4; ++i){
              newString += string[i];
           if( string[i] == '2' && string[i+1] == '0' && string [i+2] == '1' && string [i+3] == '8'){
             let wordStartIndex = i;
               let word = string.substr(wordStartIndex, 10);

               let attachTag = false;

               const dateArray = date.split("-");
               const day = parseInt(dateArray[2]);
               const month = parseInt(dateArray[1]);

               const searchedDay = parseInt(word[8]+word[9]);
               const searchedMonth = parseInt(word[5] + word[6]);

               if(searchedMonth >= month){
                  if(searchedDay >= day){
                    attachTag = true;
                  }

               }

               if(attachTag){
                   newString += `<span class="tag" style="width:1000px; height: 20px; border: 5px solid red; display: inline-block; position: absolute; left: 0; margin-top:-7px; background-color: rgba(255,0,0,.1);"></span>`;
                console.log(string,wordStartIndex );
               }
           }

        }
                  $('body').html(newString);


      });










    });

})();