kalpdev.1 / KeyLight 3

// ==UserScript==
// @name          KeyLight 3
// @namespace     kalpsdj
// @author        Shjaisw
// @license       MIT
// @updateURL     https://openuserjs.org/meta/kalpdev.1/KeyLight_3.meta.js
// @downloadURL   https://openuserjs.org/install/kalpdev.1/KeyLight_3.user.js
// @run-at        document-end
// @version       4.0
// @description   Highlights Chemical words
// @include       https://*
// @exclude       https://*google*
// @exclude       https://argus.aka.amazon.com/*
// @exclude       https://issues.amazon.com/*
// @grant         GM_registerMenuCommand
// @grant         GM_setValue
// @grant         GM_getValue
// ==/UserScript==


 // Do not make any changes/delete any script,line no 13. We are not responsible for any changes in script. Do not allow script to run on argus.  


(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 = "voltage,input,output,mah,AIR HORN, COMPRESSED HORN, AIRHORN, BLOW HORN, SAFETY CAN, AIR DUSTER, SPRAY DUSTER, COMPRESSED AIR SPRAY CLEANER, DUSTER, CANNED AIR CLEANER, FOG HORN, FREEZE SPRAY, ELECTRONICS FREEZE SPRAY, SIGNAL HORN, SURVIVAL HORN,cold,pressed,charging case,light up ,water,based,CR2016,18650,AAA,voltage,input,output,mah,charg,water,based,AAA,non-rechargeable,Packed with,contained in,magnetized,spillable,NON-SPILLABLE,Non spillable,Digital,power bank,pull force,magnet,magnets,AGM,watts,volts,watt,watt hours,watt hour,watt-hours,watt-hour,volt,nimh,nicd,220V,LR44,AG13,NI-MH,Ni-cd,alkaline,LR06,LR03,cr2032,cr2023,rechargeable,charge,charge time,Lipo,polymer,Li-polymer,Li-on,builtin,lithium,lithium_ion,Lithium ion,li-ion,Lithium_metal,Lithium metal,Lithium batteries,Lithium metal batteries,lithium metal battery,lithium-ion batteries,Lithium ion batteries,lithium-ion battery,lithium ion battery,lithium polymer battery,Lithium Battery Packaging,LITHIUM ION BATTERIES CONTAINED IN EQUIPMENT,LITHIUM ION BATTERIES PACKED WITH EQUIPMENT"
    var highlightStyle = GM_getValue('highlightStyle');
    if (!highlightStyle) highlightStyle = "color: #000; font-weight: bold; background-color: #ff8e8e;"

    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);
})();