ArcGIS Server Fields to GIS-L

copies field names in a format to paste into the GIS-L spreadsheet

  1. // ==UserScript==
  2. // @name ArcGIS Server Fields to GIS-L
  3. // @namespace https://fxzfun.com/
  4. // @version 0.2
  5. // @description copies field names in a format to paste into the GIS-L spreadsheet
  6. // @author FXZFun
  7. // @match *://*/*rest/services*/*Server/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=waze.com
  9. // @grant none
  10. // @license GNU GPLv3
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. var fieldsHeading = [...document.querySelectorAll("b")].filter(_ => _.innerText == "Fields:")[0];
  17.  
  18. for (var field of fieldsHeading.nextElementSibling.children) {
  19. field.innerHTML = `<label id="${field.innerText.split("(")[0]}"><input type="checkbox" />${field.innerHTML}</label>`;
  20. }
  21.  
  22. fieldsHeading.outerHTML += "<button id='copyBtn' onclick='copyFields()'>Copy Selected Fields</button>";
  23.  
  24. window.copyFields = function() {
  25. var fields = [...document.querySelectorAll("input")].filter(_ => _.checked).map(_ => _.parentElement.id.trim()).join(", ");
  26. copyTextToClipboard(location.href + " " + fields);
  27. }
  28.  
  29. // from https://stackoverflow.com/a/30810322
  30. function fallbackCopyTextToClipboard(text) {
  31. var textArea = document.createElement("textarea");
  32. textArea.value = text;
  33.  
  34. // Avoid scrolling to bottom
  35. textArea.style.top = "0";
  36. textArea.style.left = "0";
  37. textArea.style.position = "fixed";
  38.  
  39. document.body.appendChild(textArea);
  40. textArea.focus();
  41. textArea.select();
  42.  
  43. try {
  44. var successful = document.execCommand('copy');
  45. var msg = successful ? 'successful' : 'unsuccessful';
  46. if (msg) document.getElementById("copyBtn").innerText = "Copied";
  47. } catch (err) {
  48. document.getElementById("copyBtn").innerText = "Error copying";
  49. console.error('Fallback: Oops, unable to copy', err);
  50. }
  51.  
  52. document.body.removeChild(textArea);
  53. }
  54.  
  55. function copyTextToClipboard(text) {
  56. if (!navigator.clipboard) {
  57. fallbackCopyTextToClipboard(text);
  58. return;
  59. }
  60. navigator.clipboard.writeText(text).then(function() {
  61. document.getElementById("copyBtn").innerText = "Copied";
  62. }, function(err) {
  63. document.getElementById("copyBtn").innerText = "Error copying";
  64. console.error('Fallback: Oops, unable to copy', err);
  65. });
  66. }
  67. })();