diff --git a/Project Description.html b/Project Description.html new file mode 100755 index 0000000..fc2f77d --- /dev/null +++ b/Project Description.html @@ -0,0 +1,23 @@ + + + + + Untitled + + + + + + + + + + +

Nathan's ScratchXs

+

To access the code of Nathan's first go here: http://nathanfi.github.io/ScratchX1/Time.js + To use the extension in ScratchX, go here: scratchx.org/?url=http://nathanfi.github.io/ScratchX1/Time.js

+

Nathan's new project

+

The project is as follows: The use will click on a location on a world map, and then the extension will display "Hello" in that location's official language. + In order to complete this project, Nathan will provide a world map sprite, and use the Google Translate API as well as the log equations required to display "Hello" in the local language of the location of the mouse.

+ + diff --git a/Time.js b/Time.js index a7d878d..a552d6d 100644 --- a/Time.js +++ b/Time.js @@ -10,33 +10,86 @@ msg: 'Ready' }; }; - ext._getDay = function() { - var today = new Date() - return today.getDay() - } - ext._getHours = function() { - var today = new Date() - return today.getHours() - } - ext._getMinutes = function() { - var today = new Date() - return today.getMinutes() - } - ext._getSeconds = function() { - var today = new Date() - return today.getSeconds() - } + + ext.time = function(timeMenu) { + var today = new Date(); + if (timeMenu == 'Day of Week') { + var day = today.getDay(); + if (day === 0 || day === 7) { + return 'Sunday'; + } else if (day == 1) { + return 'Monday'; + } else if (day == 2) { + return 'Tuesday'; + } else if (day == 3) { + return 'Wednesday'; + } else if (day == 4) { + return 'Thursday'; + } else if (day == 5) { + return 'Friday'; + } else if (day == 6) { + return 'Saturday'; + } + } else if (timeMenu == 'Minute') { + return today.getMinutes(); + } else if (timeMenu == 'Second') { + return today.getSeconds(); + } else if (timeMenu == 'Hour') { + var hours = today.getHours(); + if (hours <= 12 && hours > 0) { + return hours; + } else if (hours === 0) { + return 12; + } else if (hours > 12) { + return hours - 12; + } + } else if (timeMenu == 'Hour 24 Clock') { + return today.getHours(); + } else if (timeMenu == 'Date') { + return today.getDate(); + } else if (timeMenu == 'Month') { + return today.getMonth(); + } else if (timeMenu == 'Year') { + return today.getFullYear(); + } + }; + + ext.displayTime = function(displayMenu) { + var today = new Date(); + var hours = today.getHours(); + if (hours === 0) { + hours = 12; + } else if (hours > 12) { + hours = hours - 12; + } + var month = today.getMonth() + 1; + if (displayMenu == 'Hours:Minutes') { + return hours + ":" + today.getMinutes(); + } else if (displayMenu == 'Hours:Minutes:Seconds') { + return hours + ":" + today.getMinutes() + ":" + today.getSeconds(); + } else if (displayMenu == 'Month/Date/Year') { + return month + "/" + today.getDate() + "/" + today.getFullYear(); + } else if (displayMenu == 'Date/Month/Year') { + return today.getDate() + "/" + month + "/" + today.getFullYear(); + } else if (displayMenu == 'Month/Date') { + return month + "/" + today.getDate(); + } else if (displayMenu == 'Date/Month') { + return today.getDate() + "/" + month; + } + }; // Block and block menu descriptions var descriptor = { blocks: [ - ['r', 'Days', 'getDay'] - ['r', 'Hours', 'getHours'] - ['r', 'Minutes', 'getMinutes'] - ['r', 'Seconds', 'getSeconds'] - ] + ['r', 'Display %m.displayMenu', 'displayTime', 'Hours:Minutes'], + ['r', 'Current %m.timeMenu', 'time', 'Day of Week'] + ], + menus: { + timeMenu: ['Day of Week', 'Hour', 'Hour 24 Clock', 'Minute', 'Second', 'Date', 'Month', 'Year'], + displayMenu: ['Hours:Minutes', 'Hours:Minutes:Seconds', 'Month/Date', 'Date/Month', 'Month/Date/Year', 'Date/Month/Year'] + } }; // Register the extension ScratchExtensions.register('Time', descriptor, ext); -})({}); \ No newline at end of file +})({});