Greasy Fork is available in English.

BTS2 - FC-Research Table Parser

Parses defined items in a table and retrieve data from them in array

  1. // ==UserScript==
  2. // @name BTS2 - FC-Research Table Parser
  3. // @namespace BTS2, amazon, fcresearch, parser
  4. // @version 0.1
  5. // @description Parses defined items in a table and retrieve data from them in array
  6. // @author AA from BTS2
  7. // @match file:///*/LPN*.htm
  8. // @include http://fcresearch-eu.aka.amazon.com/*/results?*
  9. // @include https://fcresearch-eu.aka.amazon.com/*/results?*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. function getColumn(table_id, col){
  17. var tab = document.getElementById(table_id);
  18. var header_nodes = document.getElementById(table_id+'_wrapper').querySelectorAll("th");
  19. var header_length = header_nodes.length / 2;
  20. var header_arr = new Array(header_length);
  21. while(header_length--){
  22. header_arr[header_length] = header_nodes[header_length]; // convert NodeList to an Array (half-sized) of Nodes
  23. }
  24.  
  25. var n = tab.rows.length;
  26. var i, tr, td, items_arr = [];
  27.  
  28. if (col < 0) return null;
  29.  
  30. for (i = 0; i < n; i++) {
  31. tr = tab.rows[i];
  32. if (tr.cells.length > col){
  33. items_arr.push(tab.rows[i].cells[col].textContent);
  34. }
  35. }
  36. return delDups(items_arr);
  37. }
  38.  
  39. function delDups(array){
  40. var seen = [];
  41. array.splice(0, 1); // deletes the first empty item in array
  42. return array.filter(function(item){
  43. return seen.hasOwnProperty(item) ? false : (seen[item] = true); // returns only the unique items
  44. });
  45. }
  46.  
  47. function addParserIcon(){
  48. var elm = document.getElementById('inventory-lpn');
  49. var icon = '<span id="parserIcon" class="ui-icon ui-icon-circle-check" style="margin-left:45px;margin-top:-23px"></span>';
  50. elm.insertAdjacentHTML('beforeend', icon);
  51. elm.addEventListener('click', function(){
  52. var data = [];
  53. data = getColumn('table-inventory', 4);
  54. downloadFile(data, 'LPN_list.txt', 'text/plain');
  55. });
  56. }
  57.  
  58. function downloadFile(data, name, type, stringify = false){
  59. if (stringify) data = JSON.stringify(data);
  60. var a = document.createElement('a');
  61. var file = new Blob([data], {type: type});
  62. a.href = URL.createObjectURL(file);
  63. a.download = name;
  64. a.click();
  65. }
  66.  
  67. function ready(fn) {
  68. if (document.attachEvent ? document.readyState === 'complete' : document.readyState !== 'loading'){
  69. fn();
  70. } else {
  71. document.addEventListener('DOMContentLoaded', fn);
  72. }
  73. }
  74. // ----------------------------------------------------------
  75. ready(function(){
  76. addParserIcon();
  77. });
  78.  
  79. })();