Greasy Fork is available in English.

Place Browser Table Export

Exports WME Place Browser's table output to CSV and download to local disk

  1. // ==UserScript==
  2. // @name Place Browser Table Export
  3. // @namespace http://junyianl.net/
  4. // @version 2019.10.05.01
  5. // @description Exports WME Place Browser's table output to CSV and download to local disk
  6. // @author junyianl
  7. // @match https://w-tools.org/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. /*
  12. Changelogs:
  13. 2019.10.05.01
  14. - Enhancement: Change pipe separator for validation rules to newline
  15. 2019.10.04.04
  16. - Bugfix: Change separator for headers.
  17. 2019.10.04.03
  18. - Bugfix: Separators were not changed.
  19. 2019.10.04.02
  20. - Changed PL column to actual permalink.
  21. - Using tab separator instead of comma, for easier copy-and-pasting into Google spreadsheet.
  22. */
  23.  
  24. (function() {
  25. 'use strict';
  26.  
  27. // Your code here...
  28.  
  29. const validations = [
  30. "Missing Name", // High
  31. "Area not Point", // Medium
  32. "Point not Area",
  33. "Incorrect Primary Category",
  34. "Missing Street",
  35. "Invalid HN",
  36. "Not Updated Since Created", // Low
  37. "IGN Editor",
  38. "Phone Number Format",
  39. "Area Very Small",
  40. "Lower Case Name",
  41. "Lock Level (Completeness)", // Info
  42. "Parent Category",
  43. "Missing Google Place Link",
  44. "Last Edit By Automated Process", // Undocumented
  45. "Missing Google Place Link (6 Month Timer Active)",
  46. "Possible Nearby Duplicate"
  47. ];
  48.  
  49. const tableSeparator = "\t";
  50.  
  51. function downloadCSV(csv, filename) {
  52. var csvFile;
  53. var downloadLink;
  54.  
  55. // CSV file
  56. csvFile = new Blob([csv], {type: "text/csv"});
  57.  
  58. // Download link
  59. downloadLink = document.createElement("a");
  60.  
  61. // File name
  62. downloadLink.download = filename;
  63.  
  64. // Create a link to the file
  65. downloadLink.href = window.URL.createObjectURL(csvFile);
  66.  
  67. // Hide download link
  68. // downloadLink.style.display = "none";
  69.  
  70. // Add the link to DOM
  71. document.body.appendChild(downloadLink);
  72.  
  73. // Click download link
  74. downloadLink.click();
  75. }
  76.  
  77. function exportTableToCSV(filename) {
  78. var csv = [];
  79. var table = document.querySelectorAll("table.tablesorter");
  80.  
  81. // Populate column headers
  82. var row = [], cols = table[0].querySelectorAll("th");
  83. for (var i = 0; i < cols.length; i++) {
  84. row.push('"' + cols[i].innerText + '"');
  85. }
  86. csv.push(row.join(tableSeparator));
  87.  
  88. // Populate places
  89. var places = table[0].querySelectorAll("[class*=validate]");
  90. for (var j = 0; j < places.length; j++) {
  91. var placerow = [], placecol = places[j].querySelectorAll("td");
  92. for (var k = 0; k < placecol.length; k++) {
  93. switch (k) {
  94. case 0:
  95. var pl = placecol[k].querySelector("a");
  96. placerow.push('"' + pl.href + '"');
  97. break;
  98. case 2:
  99. var issue = [], issues = placecol[k].querySelectorAll("li");
  100. for (var l = 0; l < issues.length; l++) {
  101. issue.push(issues[l].innerText);
  102. }
  103. placerow.push('"' + issue.join("\n") + '"');
  104. break;
  105. default:
  106. placerow.push('"' + placecol[k].innerText.trim() + '"');
  107. }
  108. }
  109. csv.push(placerow.join(tableSeparator));
  110. }
  111.  
  112. // Download CSV file
  113. downloadCSV(csv.join("\r\n"), filename);
  114. }
  115.  
  116. var group = document.querySelector('[id=MainContent_ddlAreaGroup]').selectedOptions[0].value;
  117. var area = document.querySelector('[id=MainContent_DropDownList1]').selectedOptions[0].innerText;
  118. var date = new Date();
  119. exportTableToCSV(group + '_' + area + '_' + date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate() + '.csv');
  120.  
  121. })();