kalpdev.1 / AVS - Attribute Verification Script

// ==UserScript==
// @name     AVS - Attribute Verification Script
// @author   @stthorve @shjaisw
// @version     1.6
// @run-at   document-body
// @match    https://argus.aka.amazon.com/*
// @include  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
// @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://unpkg.com/sweetalert/dist/sweetalert.min.js
// @license MIT
// @updateURL https://openuserjs.org/meta/kalpdev.1/AVS_-_Attribute_Verification_Script.meta.js
// @downloadURL https://openuserjs.org/install/kalpdev.1/AVS_-_Attribute_Verification_Script.user.js
// @grant    GM_addStyle
// @match    http://pnq-412gv7q.ant.amazon.com:8087/*
// @grant    GM_xmlhttpRequest
// @grant    GM_registerMenuCommand
// @grant    GM_setValue
// @grant    GM_getValue
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/

(function() { // Highlight Connecting words Realated product details
  'use strict';

  if (window.self !== window.top) { return; }


  function setUserPref(varName, defaultVal, menuText, promtText, sep){
    GM_registerMenuCommand(menuText, function() {
      var val = prompt(promtText, GM_getValue(varName, defaultVal));
      if (val === null)  { return; }

      if (sep && val){
        var pat1 = new RegExp('\\s*' + sep + '+\\s*', 'g');
        var pat2 = new RegExp('(?:^' + sep + '+|' + sep + '+$)', 'g'); // trim starting & trailing separator
        val = val.replace(pat1, sep).replace(pat2, '');
      }
      val = val.replace(/\s{2,}/g, ' ').trim();
      GM_setValue(varName, val);

      if(!document.body.querySelector(".THmo")) THmo_doHighlight(document.body);
      else location.reload();
    });
  }


  var THmo_MutOb = (window.MutationObserver) ? window.MutationObserver : window.WebKitMutationObserver;
  if (THmo_MutOb){
    var THmo_chgMon = new THmo_MutOb(function(mutationSet){
      mutationSet.forEach(function(mutation){
        for (var i=0; i<mutation.addedNodes.length; i++){
          if (mutation.addedNodes[i].nodeType == 1){
            THmo_doHighlight(mutation.addedNodes[i]);
          }
        }
      });
    });
    // attach chgMon to document.body
    var optss = {childList: true, subtree: true};
    THmo_chgMon.observe(document.body, optss);
  }



  function THmo_doHighlight(el){
    var sdj = GM_getValue('sdj');
    if(!sdj)  sdj="lithium_ion,cr2,lithium_metal,cr123,lithium_polymer"
    var sdjc = GM_getValue('sdjc');
    if (!sdjc) sdjc = "color: #000; font-weight: bold; background-color: #fc585b;"

    var rQuantifiers = /[-\/\\^$*+?.()|[\]{}]/g;
    sdj = sdj.replace(rQuantifiers, '\\$&').split(',').join('|');
    var pat = new RegExp('(' + sdj + ')', 'gi');
    var span = document.createElement('span');

    var snapElements = document.evaluate(
        './/text()[normalize-space() != "" ' +
        'and not(ancestor::style) ' +
        'and not(ancestor::script) ' +
        'and not(ancestor::textarea) ' +
        'and not(ancestor::code) ' +
        'and not(ancestor::pre)]',
        el, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

    if (!snapElements.snapshotItem(0)) { return; }

    for (var i = 0, len = snapElements.snapshotLength; i < len; i++) {
      var node = snapElements.snapshotItem(i);

      if (pat.test(node.nodeValue)) {

        if (node.className != "THmo" && node.parentNode.className != "THmo"){

          var sp = span.cloneNode(true);
          sp.innerHTML = node.nodeValue.replace(pat, '<span style="' + sdjc + '" class="THmo">$1</span>');
          node.parentNode.replaceChild(sp, node);
        }
      }
    }
  }

  // first run
  THmo_doHighlight(document.body);
})();



function addCustomSearchResult (jNode) {
    //$(".submit-product-card-classification").hide ();

    $('.submit-product-card-classification').click(function(){
        //$('md-tab-item[aria-label="Extended battery attributes from the catalog"]').trigger('click');

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

	function add_description(){
        //alert("Hey");
        //console.log("Heyyyyyyy");
        $('md-tab-item[aria-label="Extended battery attributes from the catalog"]').trigger('click');

       setTimeout(function(){ var n = attribute(); console.log("Str is : " + n); var keyword = "American"; if(n.includes("lithium_polymer")==true || n.includes("lithium_ion") || n.includes("lithium_metal")==true || n.includes("lithium_manganese_dioxide") || n.includes("lithium")==true || n.includes("cr2") || n.includes("cr123a")==true || n.includes("cr123") || n.includes("LiMnO2")==true || n.includes("batteries_packed_with_equipment") || n.includes("batteries_contained_in_equipment")==true || n.includes("batteries_only")) { alert('Please Check Battery Attributes'); } }, 1000);
         function attribute(){
             var active_data7= $('.ng-scope').text();
             //console.log("Battery string is : " + active_data7);
             return (active_data7);
           }

        ////var active_data = $('.ng-isolate-scope').text();
        //console.log("Active string is : " + active_data);

        ////var batt = $('.md-dg-theme').text();
        ////console.log("Bat Attri is : " + batt);
	}
//alert("Hey");
//console.log("Heyyyyyyy");



    });
}


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