Advertisement
ns26

Untitled

Aug 22nd, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //// COMMENT FOR EDO: THIS SCRIPT IS PRE-CHANGE
  2. //// MAIN SCRIPT ~~~
  3. /// SET TAGS
  4. function highlightElem(elem, color, background, border) {
  5.     if (elem) {
  6.         elem.style.color = color;
  7.         elem.style.background = background;
  8.         elem.style.border = border;
  9.     }
  10. }
  11. /// INSPECT IFRAMES
  12. function highlightItems(ids, color, background, border) {
  13.     for (let v = 0; v < ids.length; v++) {
  14.         var mainElements = document.querySelectorAll(`[value="${ids[v]}"]`);
  15.         for (let i = 0; i < mainElements.length; i++) {
  16.             highlightElem(mainElements[i], color, background, border);
  17.             if (mainElements[i].value === "4804") {
  18.                 // SPECIFIC VALUE IS FOUND. NOW IT NEEDS TO GRAB ANOTHER ID LIST FROM CHROME.STORAGE AND HIGHLIGHT ID'S WITH A
  19.                 // BORDER PROPERTY
  20.                 console.log("4804 catched");
  21.                 chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
  22.                     console.log("sent msg bc 4804");
  23.                 });
  24.             }
  25.         }
  26.         var iframes = document.querySelectorAll('iframe');
  27.         for (let i = 0; i < iframes.length; i++) {
  28.             try {
  29.                 var content = iframes[i].contentDocument || iframes[i].contentWindow.document;
  30.                 var elems = content.querySelectorAll(`[value="${ids[v]}"]`);
  31.                 for (let j = 0; j < elems.length; j++) {
  32.                     highlightElem(elems[j], color, background, border);
  33.                     if (elems[j].value === "1234") {
  34.                         // SPECIFIC VALUE IS FOUND. NOW IT NEEDS TO GRAB ANOTHER ID LIST FROM CHROME.STORAGE AND HIGHLIGHT ID'S WITH A
  35.                         // BORDER PROPERTY
  36.                         console.log("4804 catched2");
  37.                         chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
  38.                             console.log("sent msg bc 1234");
  39.                         });
  40.                     }
  41.                 }
  42.             } catch (ex) {
  43.                 console.log('Caught Error', ex);
  44.                 continue;
  45.             }
  46.         }
  47.     }
  48. }
  49.  
  50. function highlightAll(lists) {
  51.     for (let i = 0; i < lists.length; i++) {
  52.         highlightItems(lists[i].ids, lists[i].color, lists[i].background, lists[i].border);
  53.     }
  54. }
  55.  
  56. itemList = [
  57.     {
  58.         index: 0,
  59.         description: 'TEST1',
  60.         ids: ['000-ABC12-00009',
  61.         '000-ABC12-00011',
  62.         '000-ABC12-00012',
  63.         '000-ABC12-00013'],
  64.         color: 'white',
  65.         background: 'orange',
  66.         border: 'medium solid #0c182b'
  67.     },
  68.     {
  69.         index: 1,
  70.         description: 'TEST2',
  71.         ids: ['000-ABC12-00014',
  72.         '000-ABC12-00015',
  73.         '000-ABC12-00016',
  74.         '000-ABC12-00017'],
  75.         color: 'white',
  76.         background: 'orange',
  77.         border: 'medium solid #0c182b'
  78.     },
  79.     {
  80.         index: 2,
  81.         description: 'TEST3',
  82.         ids: ['000-ABC12-00018',
  83.         '000-ABC12-00019',
  84.         '000-ABC12-00020',
  85.         '000-ABC12-00021'],
  86.         color: 'white',
  87.         background: 'orange',
  88.         border: 'medium solid #0c182b'
  89.     },
  90.     {
  91.         index: 3,
  92.         description: 'TEST4',
  93.         ids: ['000-ABC12-00021',
  94.         '000-ABC12-00022',
  95.         '000-ABC12-00023',
  96.         '000-ABC12-00024'],
  97.         color: 'white',
  98.         background: 'orange',
  99.         border: 'medium solid #0c182b'
  100.     },
  101.     {
  102.         index: 4,
  103.         description: 'TEST5',
  104.         ids: ['000-ABC12-00025',
  105.         '000-ABC12-00026',
  106.         '000-ABC12-00027',
  107.         '000-ABC12-00028'],
  108.         color: 'white',
  109.         background: 'orange',
  110.         border: 'medium solid #0c182b'
  111.     },
  112.     {
  113.         index: 5,
  114.         description: 'TEST6',
  115.         ids: ['000-ABC12-00025',
  116.         '000-ABC12-00026',
  117.         '000-ABC12-00027',
  118.         '000-ABC12-00028'],
  119.         color: 'white',
  120.         background: 'orange',
  121.         border: 'medium solid #0c182b'
  122.     },
  123.     {
  124.         index: 6,
  125.         description: 'TEST7',
  126.         ids: ['000-ABC12-00025',
  127.         '000-ABC12-00026',
  128.         '000-ABC12-00027',
  129.         '000-ABC12-00028'],
  130.         color: 'white',
  131.         background: 'orange',
  132.         border: 'medium solid #0c182b'
  133.     },
  134.     {
  135.         index: 7,
  136.         description: 'TEST8',
  137.         ids: ['000-ABC12-00025',
  138.         '000-ABC12-00026',
  139.         '000-ABC12-00027',
  140.         '000-ABC12-00028'],
  141.         color: 'white',
  142.         background: 'orange',
  143.         border: 'medium solid #0c182b'
  144.     },
  145.     {
  146.         index: 8,
  147.         description: 'TEST9',
  148.         ids: ['000-ABC12-00025',
  149.         '000-ABC12-00026',
  150.         '000-ABC12-00027',
  151.         '000-ABC12-00028'],
  152.         color: 'white',
  153.         background: 'orange',
  154.         border: 'medium solid #0c182b'
  155.     },
  156.     {
  157.         index: 9,
  158.         description: 'TEST10',
  159.         ids: ['000-ABC12-00025',
  160.         '000-ABC12-00026',
  161.         '000-ABC12-00027',
  162.         '000-ABC12-00028'],
  163.         color: 'white',
  164.         background: 'orange',
  165.         border: 'medium solid #0c182b'
  166.     },
  167. ];
  168.  
  169. /// GET SAVED COLORS
  170. chrome.storage.sync.get(["cpicker1","cpicker2","cpicker3","cpicker4","cpicker5","cpicker6","cpicker7","cpicker8","cpicker9","cpicker10",
  171.     "idList1","idList2","idList3","idList4","idList5","idList6","idList7","idList8","idList9","idList10"],
  172.     function(data) {
  173.         var border = [data.bpicker1, data.bpicker2, data.bpicker3];
  174.         var colors = [data.cpicker1, data.cpicker2, data.cpicker3, data.cpicker4, data.cpicker5, data.cpicker6, data.cpicker7, data.cpicker8, data.cpicker9, data.cpicker10];
  175.         var ids = [(data.idList1).split('\n'), (data.idList2).split('\n'), (data.idList3).split('\n'), (data.idList4).split('\n'), (data.idList5).split('\n'),
  176.         (data.idList6).split('\n'),(data.idList7).split('\n'),(data.idList8).split('\n'),(data.idList9).split('\n'),(data.idList10).split('\n')];
  177.     itemList.forEach(function(item, index) {
  178.       item.background = colors[index];
  179.             item.ids = ids[index];
  180.     });
  181.     // Retrieve all iFrames and attach a function to the iframe load event
  182.     // which parses the iframe content for values
  183.     var frames = document.querySelectorAll('iframe');
  184.     for (let i = 0; i < frames.length; i++) {
  185.         try {
  186.             frames[i].addEventListener('load', function() {
  187.                 highlightAll(itemList);
  188.             });
  189.         } catch (ex) {
  190.             console.log('Error Processing IFrame', ex);
  191.             continue;
  192.         }
  193.     }
  194.     //Run highlight all on main window area of webpage that is not an iframe.
  195.     try {
  196.         highlightAll(itemList);
  197.     } catch (ex) {
  198.         console.log('Error Processing Main Window', ex);
  199.     }
  200. });
  201. //// ~~ END MAIN SCRIPT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement