Raw Source
kalpdev.1 / sideline_reduction_App_V4_MC_Team

// ==UserScript==
// @name         sideline_reduction_App_V4_MC_Team
// @version      7.6
// @author       @shjaisw
// @description  Gives the reason box for sidelining asin and Auto sideline for already raised in Qbuzz / EAR
// @updateURL https://openuserjs.org/meta/kalpdev.1/sideline_reduction_App_V4_MC_Team.meta.js
// @downloadURL https://openuserjs.org/install/kalpdev.1/sideline_reduction_App_V4_MC_Team.user.js
// @license MIT
// @match        https://argus.aka.amazon.com/*
// @require  http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require  https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant    GM_addStyle
// @namespace     kalpsdj
// @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
// ==/UserScript==

GM_addStyle(`


.lookup-custom-height {
    z-index:10000000;
}


`);



function addCustomSearchResult (jNode) {

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

      var asinElement = document.querySelector('div#workItemContainer');
      var asin = asinElement ? asinElement.innerText.trim() : '';
     const sidelineButton = document.querySelector('#dtSearch > div.sideline-asin-container > sideline-work-item > button')

    $('.sideline-asin-container').click(function(){


	setTimeout(function(){ add_description();   }, 100);

	function add_description(){

    var toastMixin = Swal.mixin({
    toast: true,
    icon: 'success',
    title: 'General Title',
    animation: false,
    position: 'top-left',
    showConfirmButton: false,
    customClass: 'lookup-custom-height',
    timer: 2000,
    timerProgressBar: true,
    didOpen: (toast) => {
      toast.addEventListener('mouseenter', Swal.stopTimer)
      toast.addEventListener('mouseleave', Swal.resumeTimer)
    }
  });
       Swal.fire({
  icon: 'question', title: 'What was the reason of this Sideline?',
    backdrop: `
    rgba(5,59,37,0.19)
    left top
    no-repeat
  `,
  showCancelButton: true, focusConfirm: false, allowOutsideClick: false, allowEscapeKey: false,
  html: `<select name="Reason" id="reason" style="font-size:large;" >  placeholder="Reason" <option value="MC-Qbuzz">Qbuzz</option> <option value="MC-EAR">EAR</option><option value="MC-Already Qbuzz">Already Qbuzz</option> <option value="MC-Already EAR">Already EAR</option> <option value="MC-UTC case">UTC Case</option> <option value="MC-Other">Other</option> </select>
  <p type="password" id="password" display="none" placeholder="asinnumber">
  <p type="reason" id="reason" display="none" placeholder="Reason">`,
  confirmButtonText: 'Submit Reason&nbsp;<i class="fa fa-arrow-right"></i>',
  showCancelButton: false,
  focusConfirm: false,
  footer: `For any bug/suggestion contact @shjaisw`,
  preConfirm: () => {
    const reason = Swal.getPopup().querySelector('#reason').value;



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



               // alert(response.responseText);

            }
        });
        return { login: username, password: asin , reason: reason}
  }


}).then((result) => {

  toastMixin.fire(`
  *Reason Submited*
    User-Id: ${result.value.login}
    Reason: ${result.value.reason}
     ${result.value.password}
  `.trim())




})



	}


    });
}


var url= window.location.href;
var isArgusDG = /^https:\/\/argus.aka.amazon.com\/#!\/dg(.*)/i.test(url);

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!");
}