Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Project Description.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled</title>
<script src="libraries/p5.js" type="text/javascript"></script>

<script src="libraries/p5.dom.js" type="text/javascript"></script>
<script src="libraries/p5.sound.js" type="text/javascript"></script>

<script src="sketch.js" type="text/javascript"></script>

<style> body {padding: 0; margin: 0;} canvas {vertical-align: top;} </style>
</head>
<body>
<h1>Nathan's ScratchXs</h1>
<p>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</p>
<h3>Nathan's new project</h3>
<p>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.</p>
</body>
</html>
97 changes: 75 additions & 22 deletions Time.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
})({});
})({});