From 2736c225c0c7e0b442fac00635c8e18560668649 Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Tue, 10 Jan 2017 08:51:15 -0600 Subject: [PATCH] move ImportJson to lib, separate out RefreshData --- gs/{type => lib}/ImportJson.gs | 47 ---------------------------------- gs/type/RefreshData.gs | 40 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 47 deletions(-) rename gs/{type => lib}/ImportJson.gs (92%) create mode 100644 gs/type/RefreshData.gs diff --git a/gs/type/ImportJson.gs b/gs/lib/ImportJson.gs similarity index 92% rename from gs/type/ImportJson.gs rename to gs/lib/ImportJson.gs index f47b09579..abbd3aba7 100644 --- a/gs/type/ImportJson.gs +++ b/gs/lib/ImportJson.gs @@ -1,50 +1,3 @@ -/*====================================================================================================================================* - run ImportJSON on-demand from Sheets menu - ====================================================================================================================================*/ - -var typeSheet = { - "FilterLists Global": "GlobalData", - "FilterLists Regional": "RegionalData", - "FilterLists Forked": "ForkedData", - "FilterLists Combo": "ComboData", - "FilterLists Stale": "StaleData" -}; - -var typeGitHubUrl = { - "FilterLists Global": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/global.json", - "FilterLists Regional": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/regional.json", - "FilterLists Forked": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/forked.json", - "FilterLists Combo": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/combo.json", - "FilterLists Stale": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/stale.json" -}; - -function onOpen() { - var ss = SpreadsheetApp.getActiveSpreadsheet(), - options = [{ - name: "Refresh Data", - functionName: "refreshJson" - }, ]; - ss.addMenu("Refresh Data", options); -} - -function refreshJson() { - var ss = SpreadsheetApp.getActiveSpreadsheet(); - var sheet = ss.getSheetByName(typeSheet[ss.getName()]); - var data = ImportJSON(typeGitHubUrl[ss.getName()], "", "noTruncate,rawHeaders,noInherit"); - for (i = 0; i < data.length; i++) { - for (j = 0; j < data[0].length; j++) { - if (data[i][j] == null) { - data[i][j] = ""; - } - } - } - sheet.clearContents(); - var range = sheet.getRange(1, 1, data.length, data[0].length); - range.setValues(data) -} - - - // forked from https://github.com/fastfedora/google-docs /*====================================================================================================================================* ImportJSON by Trevor Lohrbeer (@FastFedora) diff --git a/gs/type/RefreshData.gs b/gs/type/RefreshData.gs new file mode 100644 index 000000000..c05402e55 --- /dev/null +++ b/gs/type/RefreshData.gs @@ -0,0 +1,40 @@ +var typeSheet = { + "FilterLists Global": "GlobalData", + "FilterLists Regional": "RegionalData", + "FilterLists Forked": "ForkedData", + "FilterLists Combo": "ComboData", + "FilterLists Stale": "StaleData" +}; + +var typeGitHubUrl = { + "FilterLists Global": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/global.json", + "FilterLists Regional": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/regional.json", + "FilterLists Forked": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/forked.json", + "FilterLists Combo": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/combo.json", + "FilterLists Stale": "https://raw.githubusercontent.com/collinbarrett/FilterLists/master/json-data/stale.json" +}; + +function onOpen() { + var ss = SpreadsheetApp.getActiveSpreadsheet(), + options = [{ + name: "Refresh Data", + functionName: "refreshJson" + }, ]; + ss.addMenu("Refresh Data", options); +} + +function refreshJson() { + var ss = SpreadsheetApp.getActiveSpreadsheet(); + var sheet = ss.getSheetByName(typeSheet[ss.getName()]); + var data = ImportJSON(typeGitHubUrl[ss.getName()], "", "noTruncate,rawHeaders,noInherit"); + for (i = 0; i < data.length; i++) { + for (j = 0; j < data[0].length; j++) { + if (data[i][j] == null) { + data[i][j] = ""; + } + } + } + sheet.clearContents(); + var range = sheet.getRange(1, 1, data.length, data[0].length); + range.setValues(data) +} \ No newline at end of file