-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.js
1 lines (1 loc) · 1.44 KB
/
Code.js
1
var CalendarId=getCalendarId();function PanelCallback(e){var t=getTweets(),a=new Date(e.start_time),r=new Date(e.end_time),n=Math.floor(e.interval_value),l=null;"S-E"===e.selector&&(l=Math.abs(r-a)/t.length,n=Math.floor(l/6e4)),CalendarPush(t,a,n)}function CalendarPush(e,t,a){for(var r=CalendarApp.getCalendarById(CalendarId),n=0;n<e.length;++n){var l=IntervalTimeStamp(t,60*a*1e3,n+1),d=r.createEvent(e[n],l,l);Logger.log(d.getId())}SpreadsheetApp.getUi().alert("Done!")}function getCalendarId(){return SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Calendar ID").getRange("A1").getValue()}function getTweets(){return SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Tweets").getRange(1,1,100,1).getValues().filter(function(e){if(""!==e[0])return e[0]})}function QC(e){var t=e.length<=180?"GOOD":"TOO LONG";return 0<e.length?t:"EMPTY"}function IntervalTimeStamp(e,t,a){var r=t*a,n=new Date(e.getTime()+r),l=["January","February","March","April","May","June","July","August","September","October","November","December"][n.getUTCMonth()],d=n.getUTCDate(),g=n.getUTCFullYear(),i=n.getUTCHours(),u=n.getUTCMinutes(),o=n.getUTCSeconds();return new Date(l+" "+d+", "+g+" "+(i+":"+u+":"+o+" UTC"))}function onOpen(){SpreadsheetApp.getUi().createMenu("Batch Tweets").addItem("Send to Calendar","showSideBar").addToUi()}function showSideBar(){var e=HtmlService.createHtmlOutputFromFile("side-panel.html").setTitle("Send to Calendar");SpreadsheetApp.getUi().showSidebar(e)}