Last active
June 27, 2017 22:11
-
-
Save prendradjaja/a19b45653973ac6fe71d4125325eb2d3 to your computer and use it in GitHub Desktop.
Timestamp for Workflowy tags (bookmarklet)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Minifier fork (with ES6 support): | |
| // https://jadengore.github.io/bookmarkleter/ | |
| // My usual minifier (no ES6 support): http://chriszarate.github.io/bookmarkleter/ | |
| // GitHub issue: https://github.com/chriszarate/bookmarkleter/issues/7 | |
| function main() { | |
| prompt('Press Ctrl-C to copy', '#' + getTimeStamp()); | |
| } | |
| function getTimeStamp() { | |
| var date = new Date(); | |
| var hoursRaw = date.getHours(); | |
| var [hours, ampm] = datelib.twelveHours(hoursRaw); | |
| var minutes = datelib.twoDigits(date.getMinutes()); | |
| return ('ts:v1_' | |
| + hours + ':' + minutes | |
| + ampm); | |
| } | |
| var datelib = { // homespun stuff | |
| _version: '0.1.0', | |
| twelveHours: function twelveHours(hoursRaw) { | |
| var ampm = (hoursRaw < 12 ? | |
| 'am' : 'pm'); | |
| var hours; | |
| if (hoursRaw === 0) { | |
| hours = 12; | |
| } else if (hoursRaw <= 12) { | |
| hours = hoursRaw; | |
| } else { | |
| hours = hoursRaw - 12; | |
| } | |
| hours = datelib.twoDigits(hours); | |
| return [hours, ampm]; | |
| }, | |
| twoDigits: function twoDigits(hours) { | |
| return (hours < 10 ? | |
| '0' + hours : '' + hours); | |
| } | |
| }; | |
| main(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:%22use%20strict%22;function%20main(){prompt(%22Press%20Ctrl-C%20to%20copy%22,%22%23%22+getTimeStamp())}function%20getTimeStamp(){var%20t=new%20Date,r=t.getHours(),e=datelib.twelveHours(r),n=_slicedToArray(e,2),i=n[0],o=n[1],a=datelib.twoDigits(t.getMinutes());return%22ts:v1_%22+i+%22:%22+a+o}var%20_slicedToArray=function(){function%20t(t,r){var%20e=[],n=!0,i=!1,o=void%200;try{for(var%20a,u=t[Symbol.iterator]();!(n=(a=u.next()).done)%26%26(e.push(a.value),!r||e.length!==r);n=!0);}catch(t){i=!0,o=t}finally{try{!n%26%26u.return%26%26u.return()}finally{if(i)throw%20o}}return%20e}return%20function(r,e){if(Array.isArray(r))return%20r;if(Symbol.iterator%20in%20Object(r))return%20t(r,e);throw%20new%20TypeError(%22Invalid%20attempt%20to%20destructure%20non-iterable%20instance%22)}}(),datelib={_version:%220.1.0%22,twelveHours:function(t){var%20r,e=t%3C12%3F%22am%22:%22pm%22;return%20r=0===t%3F12:t%3C=12%3Ft:t-12,r=datelib.twoDigits(r),[r,e]},twoDigits:function(t){return%20t%3C10%3F%220%22+t:%22%22+t}};main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment