kalpdev.1 / ParaShoot for Paragon 1

// ==UserScript==
// @name        ParaShoot for Paragon 1
// @namespace     kalpsdj
// @author        Shjaisw
// @license       MIT
// @version     1.1
// @copyright 2020, kalpdev.1
// @updateURL https://openuserjs.org/meta/kalpdev.1/ParaShoot_for_Paragon_1.meta.js
// @downloadURL https://openuserjs.org/install/kalpdev.1/ParaShoot_for_Paragon_1.user.js
// @description Tool used for paragon process
// @include     https://image-assist.amazon.com/vision/*
// @include     https://csi.amazon.com/*
// @include https://browse-query-editor-na.aka.amazon.com/?browseNodeFilter=category-node-live-on-website&catalogAttributes=gl_product_group_type*
// @grant         GM_registerMenuCommand
// @grant         GM_setValue
// @grant         GM_getValue
// ==/UserScript==

function getURLASIN() {
//get the ASIN from the URL
  var m;
  m = document.location.href.match(/(?:.+\/)?dp\/([^/?]+)/);
  if (m) return m[1];
  m = document.location.href.match(/gp\/product\/([^/?]+)/);
  if (m) return m[1];
  m = document.location.href.match(/ASIN\/([^/?]+)/);
  if (m) return m[1];
}

function getDPASIN() {

  var n;
  n = document.getElementById('ASIN').value;
  if (n) return n;
  n = document.getElementByName('ASIN').value;
  if (n) return n;
}

function shjaisw(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

shjaisw (
	'h3#feedback { display: none; }'
	+
	'.vertical-space-150 { display: none; }'
    +
    '#fixed-header { display: none; }'
    +
    '#filter { display: none; }'
     +
    'li.info { display: none; }'
     +
    'div#filtermessage.warning { display: none; }'
    +
    'h2#heading { display: none; }'
    +
    'div.a-box-inner { width: 100%; display: inline-block; background: #FFFDE7; }'
    +
    '.CSIForm { background-color: #ffe9bf; }'
     +
    'div#advancedoptionsmessage { display: none; }'
     +
    'div#buttonsdiv { display: none; }'
    +
    '.glyphicon--small { display: none; }'
    +
    'table[id="productdata"] tbody tr.odd td { background-color: #FFFDE7; }'
    +
    'browse-common-toolbar { display: none; }'
    +
    '.asin-list .asin-list__cell--checkbox { display: none; vertical-align: middle; }'
    +
    'table { background-color: #FFECB3; }'
    +
    '.panel-warning { display: none; }'
    +
    '.asin-display-control { display: none; }'
    +
    '.asin-list .asin-list__cell { padding: 2px 8px; }'
    +
    '.asin-discovery-form .panel-heading.imsv3-header { color: #fff; display: none; background-color: darkolivegreen; border-color: #2e6da4; cursor: pointer; }'
    +
    '.asin-discovery-form .panel-collapse { display: none; }'
    +
    '.asin-discovery-form { display: none; }'
    +
    'table[id="productdata"] thead tr .header { background-repeat: no-repeat; background-position: center right; cursor: pointer; background: #56c5d3; }'
    +
    'div#filterboxplaceholder { background: beige; text-align: center; font-size: x-large; }'
);

(function() {
  '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');
        val = val.replace(pat1, sep).replace(pat2, '');
      }
      val = val.replace(/\s{2,}/g, ' ').trim();
      GM_setValue(varName, val);
      if(!document.body.querySelector(".THmoa")) THmoa_doHighlight(document.body);
      else location.reload();
    });
  }


  var THmoa_MutOb = (window.MutationObserver) ? window.MutationObserver : window.WebKitMutationObserver;
  if (THmoa_MutOb){
    var THmoa_chgMon = new THmoa_MutOb(function(mutationSet){
      mutationSet.forEach(function(mutation){
        for (var i=0; i<mutation.addedNodes.length; i++){
          if (mutation.addedNodes[i].nodeType == 1){
            THmoa_doHighlight(mutation.addedNodes[i]);
          }
        }
      });
    });

    var opts = {childList: true, subtree: true};
    THmoa_chgMon.observe(document.body, opts);
  }



  function THmoa_doHighlight(el){
    var keywords = GM_getValue('keywords');
    if(!keywords) keywords = "gl_product_group_type,product_type,item_classification,product_site_launch_date,item_name,part_number,model_number,bullet_point,product_description,cpsia_cautionary_statement,safety_warning	brand,safety_warning,brand,manufacturer,eu_toys_safety_directive_age_warning,eu_toys_safety_directive_warning,eu_toys_safety_directive_language,_minimum_age,value:,play,play value,kids,all ages,fun,toy,toys,playschool"
    var highlightStyle = GM_getValue('highlightStyle');
    if (!highlightStyle) highlightStyle = "color: #000; font-weight: bold; background-color: #52def261;"

    var rQuantifiers = /[-\/\\^$*+?.()|[\]{}]/g;
    keywords = keywords.replace(rQuantifiers, '\\$&').split(',').join('|');
    var pat = new RegExp('(' + keywords + ')', '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 != "THmoa" && node.parentNode.className != "THmoa"){
          var sp = span.cloneNode(true);
          sp.innerHTML = node.nodeValue.replace(pat, '<span style="' + highlightStyle + '" class="THmoa">$1</span>');
          node.parentNode.replaceChild(sp, node);
        }
      }
    }
  }

  THmoa_doHighlight(document.body);
})();