Raw Source
kalpdev.1 / Sideline Check

// ==UserScript==
// @name         Sideline Check
// @version      1.0
// @author       @shjaisw
// @description  It will scrap the hard sideline asin and remove from start of the inflow.It will remove unwanted sidelines from the Associate.
// @updateURL https://openuserjs.org/meta/kalpdev.1/Auto_Smart_Allocation.meta.js
// @downloadURL https://openuserjs.org/install/kalpdev.1/Auto_Smart_Allocation.user.js
// @license MIT
// @match        https://argus.aka.amazon.com/*
//@require https://cdn.jsdelivr.net/npm/sweetalert2@10
// @resource    buttonCSS https://raw.githubusercontent.com/necolas/css3-github-buttons/master/gh-buttons.css
// @resource    bootstrapCSS https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
// @updateURL https://openuserjs.org/meta/kalpdev.1/Battery_Word_Counter.meta.js
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.es6.min.js
// @require      https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/jquery.mark.es6.min.js
// @require      https://cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js
// @require      https://gist.github.com/raw/2625891/waitForKeyElements.js
//@require https://cdn.jsdelivr.net/npm/sweetalert2@10
// @grant    GM_xmlhttpRequest
// @grant         GM_registerMenuCommand
// @grant         GM_setValue
// @grant         GM_getValue
// @grant       GM_addStyle
// @grant        GM_addStyle
// @grant       GM_xmlhttpRequest
// @grant       GM_getResourceText
// @grant       GM_getResourceURL
// @grant        GM_addStyle
// ==/UserScript==

GM_addStyle(`
.new-sideline-button {
  background-color: #00796b;
  border: none;
  color: white;
  padding: 2px 2px;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 12px;
  position: absolute;
  right: 15px;
}




.modal {
  display: none; /* Hidden by default */
  position: fixed; /* Stay in place */
  z-index: 1000000000000000; /* Sit on top */
  padding-top: 15%; /* Location of the box */
  left: 0;
  top: 0;
  width: 100%; /* Full width */
  height: 100%; /* Full height */
  overflow: auto; /* Enable scroll if needed */
  background-color: rgb(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

/* Modal Content */
.modal-content {
  position: relative;
  z-index: 1000000000000000;
  background-color: #fefefe;
  margin: auto;
  padding: 0;
  border: 1px solid #888;
  width: 35%;
  box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
  -webkit-animation-name: animatetop;
  -webkit-animation-duration: 0.4s;
  animation-name: animatetop;
  animation-duration: 0.4s
}

/* Add Animation */
@-webkit-keyframes animatetop {
  from {top:-300px; opacity:0}
  to {top:0; opacity:1}
}

@keyframes animatetop {
  from {top:-300px; opacity:0}
  to {top:0; opacity:1}
}

/* The Close Button */
.close {
  color: white;
  display:none;
  float: right;
  font-size: 28px;
  font-weight: bold;
}

.close:hover,
.close:focus {
  color: #000;
  display:none;
  text-decoration: none;
  cursor: pointer;
}

.modal-header {
  padding: 2px 16px;
  background-color: #00796b;
  color: white;

}

.title {
  text-align: center;
  font-size: 2.5rem
}

.modal-body {
  padding: 2px 16px;
  text-align: center;
}

.modal-footer {
  padding: 2px 16px;
  background-color: #ffffff;
  text-align: center;
}





.radio {
  display: inline-flex;
  overflow: hidden;
  border-radius: 5px;
  box-shadow: 0 0 5px rgb(0,0,0.25);
}
.radio__input {
  display: none;
}

.radio__label {
  padding: 8px 14px;
  font-size: 14px;
  font-family: sans-serif;
  color: #ffffff;
  background: #009578;
  cursor: pointer;
  transition: background 0.1s;
}

.radio__label:not(:last-of-type) {
  border-right: 1px solid #006B56;
}

.radio__input:checked + .radio__label {
  background: #03fcc2;
  color:#0d0d0d;
  font-weight: bold;
}

.hideDefault {
  display: none;
}

select{font-size:medium;
 background: rgb(128 203 196 / 78%);;
 }

.myButtons {
  color: #009578;
  border: 2px solid #009578;
  margin: 10px;
  background: #FFFFFF;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 10px;
  transition-duration: 0.5s;
  box-shadow: 0 0 5px rgb(0,0,0.10);
  font-weight: bold;

}

.myButtons:hover {
  background-color: #009578;
  color: white;
  font-weight: bold;
  box-shadow: 0 12px 16px 0 rgba(0,0,0,0.24), 0 17px 50px 0 rgba(0,0,0,0.19);

}


`);


(function () {
  ('use strict')
  const argusSessionStorage = window.sessionStorage // start Chrome session storage
  var startTime = 0
  var endTime = 0


 'use strict';


  //****************************************** */
  // check if page is loaded and clear the sessionstyorage
  window.onbeforeunload = function () {
    sessionStorage.setItem("origin", window.location.href);
//sidelinePopup()

  }
  //Then in the onload event:

  window.onload = function () {
    if (window.location.href == sessionStorage.getItem("origin")) {
     sessionStorage.clear();


    }
  }
  //****************************************** */

  function checkIfAsinInQbuzz() {
      var usernameElement = document.querySelector('.spoof-user-badge-pic');
      var username = usernameElement ? usernameElement.alt : null;

      var asinElement = document.querySelector('span.ng-binding');
    var asin = asinElement ? asinElement.innerText.trim() : '';


   // const asin = document.querySelector('#workItemContainer > span') // get the ASIN location
    if (!asin) {
      // if no ASIN location is found


    } else if (argusSessionStorage.getItem('PreviousASIN') === asin.innerText) {

       // IF ASIN location found, check Chrome session storage for the ASIN and compare with current ASIN. IF the same, exit and go to the end of the if statment --> then repeat the function again after 1 second

    } else {
     
      // if the ASIN in storage is not the same as the current ASIN (The ASIN has changed --> Excute the whole code once)

   GM_xmlhttpRequest({
            method: "POST",
            url: "http://pnq-412gv7q.ant.amazon.com:8087/sdj/save_entry",
                                                data: "username="+username+"&asin="+asin,
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            onload: function(response) {

 const sidelineButton = document.querySelector('#dtSearch > div.sideline-asin-container > sideline-work-item > button') // get the sideline button

  alert(response.responseText);

  if (response.responseText === "qbuzz") {
    // Perform actions for Condition 1
     sidelineButton.click();
        const finalconfirm = setInterval(function () {
                    const slButton = document.querySelector("body > div.sweet-alert.showSweetAlert.visible > div.sa-button-container > div > button")
                   if (slButton) {
                       slButton.click();
                      clearInterval(finalconfirm);
                      // document.location.reload(true);
                 }
                }, 500);
    // Add your desired commands here
  } else if (response.responseText === "Condition 2") {
    // Perform actions for Condition 2
    console.log("Condition 2 is met.");
    // Add your desired commands here
  } else {
    // Perform actions for other conditions
    console.log("fresh asin");
    // fresh asin
  }

 // console.log(response.responseText);


            //  alert(response.responseText);

            }
        });


      console.log('Checking Qbuzz')
      argusSessionStorage.clear() // clear the current storage
      const ASIN = asin.innerText.toString() // get the ASIN inner text in variable
      argusSessionStorage.setItem('PreviousASIN', ASIN) // write the new ASIN to the storage

   
   //////////////////////////////////////////////////////////////////
       var toastMixin = Swal.mixin({
    toast: true,
    icon: 'Info',
    background: '#e0f2f1',
    title: 'General Title',
    animation: true,
    position: 'bottom',
    showConfirmButton: false,
    timer: 6500,
    timerProgressBar: true,
    didOpen: (toast) => {
      toast.addEventListener('mouseenter', Swal.stopTimer)
      toast.addEventListener('mouseleave', Swal.resumeTimer)
    }
  });
/////////////////////////////////////////////////////////////////////////////////////




      //fetch('https://tareq.corp.amazon.com:5050', options) // send the request to the server with json
      fetch('https://tareq.corp.amazon.com/qbuzz-db', options)
        .then(response => response.json()) // wait for the response promise and then parse the retruned response to JSON
        .then(data => {
          const sidelineButton = document.querySelector('#dtSearch > div.sideline-asin-container > sideline-work-item > button')
          if (data.ASIN == ASIN) {
              ////////////////////////

            /////////////////////////

sidelineButton.click()

               const finalconfirm = setInterval(function () {
                    const slButton = document.querySelector("body > div.sweet-alert.showSweetAlert.visible > div.sa-button-container > div > button")
                   if (slButton) {
                       slButton.click();
                      clearInterval(finalconfirm);
                      // document.location.reload(true);
                 }
                }, 500);

          }
else { 

}
        })

        .catch(function (error) {

          toastMixin.fire("Connection to database failed due to network/Cisco,Please re-open Argus . If ASIN is loaded in Manually continue the work.");
          console.log(error);

          return
        });
    }
    window.setTimeout(checkIfAsinInQbuzz, 1000) // run the above funtion every 2.5 second (and start the main loop)
  }

  checkIfAsinInQbuzz() // run the function  // this is the first to run //! EBANLE LATER


  //*********************************************************************************************************************************************************/
  //*********************************************************************************************************************************************************/
  //*********************************************************************************************************************************************************/





  function sidelinePopup() {

    const sidelineButton = document.querySelector('#dtSearch > div.sideline-asin-container > sideline-work-item > button') // get the sideline button

  if (!sidelineButton) {// if no button found
    } else {

      const popupWindow = document.createElement('div');
         
   sidelineButton.onclick = function () {
        document.querySelector("#slform").reset();

        modal.style.display = "block";

      }

      const popupDiv = `
        <div id="myModal" class="modal">
          <div class="modal-content">

            <div class="modal-header">
            <span class="close">&times;</span>
            <h2 class="title">Please Select Valid Reason & Comment to Sideline this ASIN</h2>
            </div>

            <div class="modal-body">
                <form id="slform">
                    <div class="radio">



                        <input class="radio__input" type="radio" value="Qbuzz" name="sideline_reason" id="myRadio1" >
                        <label class="radio__label" for="myRadio1">Qbuzz</label>
                        </input>

                        <input class="radio__input" type="radio" value="Already in Tool" name="sideline_reason" id="myRadio2">
                        <label class="radio__label" for="myRadio2">Already in Qbuzz/EAR</label>
                        </input>

                        <input class="radio__input" type="radio" value="qbuzz" name="sideline_reason" id="myRadio3">
                        <label class="radio__label" for="myRadio3">EAR</label>
                        </input>

                        <input class="radio__input" type="radio" value="Technical Issue" name="sideline_reason" id="myRadio4">
                        <label class="radio__label" for="myRadio4">Technical Issue</label>
                        </input>

                         <input class="radio__input" type="radio" value="Other" name="sideline_reason" id="myRadio5" >
                        <label class="radio__label" for="myRadio5">Other</label>
                        </input>


                    </div>

                    <div id="freetext" class="" style="display:none" >
                        <textarea type="text" name="sideline_reason_other" required id="sideline_reason_other" maxlength="250" cols="50" rows="5" placeholder="Note-Comments are Mandatory (Please Select Main Reason Above)"></textarea>
                    </div>

                     <div id="earreasontabs" class="" style="display:none">
                        <select  name="earreasontab" ><option value="FL ASIN">FL ASIN</option> <option value="sme">sme</option>  <option value="Do Not Classify">Do Not Classify</option> <option value="Seller Communicaion">Seller Communication</option> </select>
                    </div>


                    <div class="modal-footer">
                        <button class = "myButtons" id="cancelButton" type="button">Refresh</button>
                        <button class = "myButtons" id="submitButton" type="submit">Submit</button>
                    </div>
                  </form>
            </div>
          </div>
        </div>
          `

      popupWindow.innerHTML = popupDiv
      document.body.appendChild(popupWindow);

      // Get the modal
      const modal = document.getElementById("myModal");

      // Get the <span> element that closes the modal
      const span = document.getElementsByClassName("close")[0];

      // When the user clicks the button, open the modal
     //  sidelineButton.onclick = function () {
      //  modal.style.display = "block";
     // }


      //#######################################################################################################
      //########################################Radio butoons control##########################################
      function hideFreeText() {
        document.getElementById('freetext').style.display = 'none';
        document.getElementById("sideline_reason_other").required = false //false
           document.getElementById('earreasontabs').style.display = 'none';
      }

      function showFreeText() {
        document.getElementById('freetext').style.display = 'block';
        document.getElementById("sideline_reason_other").required = true ;
           document.getElementById('earreasontabs').style.display = 'none';
      }

         function earReason() {
        document.getElementById('freetext').style.display = 'none';
        document.getElementById('earreasontabs').style.display = 'block';
        document.getElementById("sideline_reason_other").required = false ;

      }

      const radio1 = document.getElementById('myRadio1');
      radio1.addEventListener("click", showFreeText, false);


      const radio2 = document.getElementById('myRadio2');
      radio2.addEventListener("click", showFreeText, false);

      const radio3 = document.getElementById('myRadio3');
      radio3.addEventListener("click", earReason, false);

      const radio4 = document.getElementById('myRadio4');
      radio4.addEventListener("click", showFreeText, false);

      const radio5 = document.getElementById('myRadio5');
      radio5.addEventListener("click", showFreeText, false);

      //#######################################################################################################
      //##########################################Submit & cancel buttons control##############################


      function handleSubmit(event) {
        console.log('Writing to Maria DB')
        event.preventDefault();
        const dataToSubmit = new Object();
        const formData = new FormData(this);
        dataToSubmit.currentASIN = document.querySelector('#workItemContainer > span').innerText
        dataToSubmit.userID = document.querySelector("#argus-spoof > div > img").getAttribute("alt")
        dataToSubmit.sidelineReason = formData.get('sideline_reason');

       if (dataToSubmit.sidelineReason == "qbuzz") {
                  dataToSubmit.sidelineReasonOther = formData.get('earreasontab')
                }

                else dataToSubmit.sidelineReasonOther = formData.get('sideline_reason_other');

        endTime = performance.now()

        dataToSubmit.timeSpentBeforeSidelining = ((endTime - startTime) / 1000).toFixed(1);


     if (dataToSubmit.sidelineReason != null) {
                  sendSidlineDataToServer(dataToSubmit)
                }
                else return
          document.getElementById("slform").required = true;
        document.querySelector("#slform").reset();
        modal.style.display = "none";
       popupWindow.remove();


               const finalconfirm = setInterval(function () {
                    const slButton = document.querySelector("body > div.sweet-alert.showSweetAlert.visible > div.sa-button-container > div > button")
                   if (slButton) {
                       slButton.click();
                      clearInterval(finalconfirm);
                      // document.location.reload(true);
                 }
                }, 100);


        return
      }



      // function to write the data to mariadb
      function sendSidlineDataToServer(data) {
        const options = {
          headers: {
            // create the post request header with the data we want to post
            'Content-Type': 'application/json'
          },
          method: 'POST',
          body: JSON.stringify(data)

        }

        //fetch('https://tareq.corp.amazon.com:5050', options) // send the request to the server with json
        fetch('https://tareq.corp.amazon.com/maria-db', options)
          .then(response => response.end()) // wait for the response promise and then parse the retruned response to JSON

          .catch(function (error) {

            console.log("error sending sideline data to database");
            console.log(error);
            return
          });
      }


      const form = document.querySelector("#slform");
      document.getElementById("slform").required = true;// select the form
      form.addEventListener('submit', handleSubmit);


      cancelBtn = document.getElementById('cancelButton');
      cancelBtn.onclick = function () {
       
        
      }

      // #######################################################################################################
      //##########################################closing model##############################


      // When the user clicks on <span> (x), close the modal
      span.onclick = function () {
        
        document.querySelector("#slform").reset();
      }

      // When the user clicks anywhere outside of the modal, close it
      window.onclick = function (event) {
        if (event.target == modal) {
          
         

        }
      }

      return

    }

    window.setTimeout(sidelinePopup, 1000)
  }


})()

if (isArgusDG){
    console.log("This is an Argus DG Page!");
              waitForKeyElements (".submit-product-card-classification", addCustomSearchResult);
}else{
    console.log("This is not an Argus DG Page!");
}