|
1 | 1 | // ==UserScript==
|
2 | 2 | // @name GitHub Static Time
|
3 |
| -// @version 1.0.10 |
| 3 | +// @version 1.1.0 |
4 | 4 | // @description A userscript that replaces relative times with a static time formatted as you like it
|
5 | 5 | // @license MIT
|
6 | 6 | // @author Rob Garrison
|
|
26 | 26 | let busy = false;
|
27 | 27 | let timeFormat = GM_getValue("ghst-format", "LLL");
|
28 | 28 | let locale = GM_getValue("ghst-locale", "en");
|
| 29 | + let useUTC = GM_getValue("ghst-utc", "false"); |
29 | 30 |
|
30 | 31 | // list copied from
|
31 | 32 | // https://github.com/moment/momentjs.com/blob/master/data/locale.js
|
|
195 | 196 | return;
|
196 | 197 | }
|
197 | 198 | el = els[indx];
|
198 |
| - time = el.getAttribute("datetime") || ""; |
199 |
| - if (el && time) { |
| 199 | + time = moment(el.getAttribute("datetime") || ""); |
| 200 | + if (el && time.isValid()) { |
| 201 | + if (useUTC === "true") { |
| 202 | + time = time.utc(); |
| 203 | + } |
200 | 204 | if (tempFormat) {
|
201 |
| - formatted = moment(time).format(tempFormat); |
| 205 | + formatted = time.format(tempFormat); |
202 | 206 | el.textContent = formatted;
|
203 | 207 | el.title = formatted;
|
204 | 208 | } else {
|
205 |
| - formatted = moment(time).format(timeFormat); |
| 209 | + formatted = time.format(timeFormat); |
206 | 210 | node = block.cloneNode(true);
|
207 | 211 | node.setAttribute("datetime", time);
|
208 | 212 | node.textContent = formatted;
|
|
237 | 241 | #ghst-settings-inner { position:fixed; left:50%; top:50%; width:25rem;
|
238 | 242 | transform:translate(-50%,-50%); box-shadow:0 .5rem 1rem #111;
|
239 | 243 | color:#c0c0c0 }
|
240 |
| - #ghst-settings-inner .boxed-group-inner { height: 205px; } |
| 244 | + #ghst-settings-inner .boxed-group-inner { height: 255px; } |
241 | 245 | #ghst-footer { clear:both; border-top:1px solid rgba(68, 68, 68, .3);
|
242 | 246 | padding-top:5px; }
|
243 | 247 | `);
|
|
262 | 266 | <br>
|
263 | 267 | </dd>
|
264 | 268 | </dl>
|
| 269 | + <dl class="form-group flattened"> |
| 270 | + <dt> |
| 271 | + <label for="ghst-utc">Show UTC time (use "z" in format below)</label> |
| 272 | + </dt> |
| 273 | + <dd> |
| 274 | + <div class="form-checkbox"> |
| 275 | + <input id="ghst-utc" type="checkbox" class="float-right"> |
| 276 | + </div> |
| 277 | + <br> |
| 278 | + </dd> |
| 279 | + </dl> |
265 | 280 | <dl class="form-group flattened">
|
266 | 281 | <dt>
|
267 | 282 | <label for="ghst-format">
|
268 |
| - <p>Set <a href="https://momentjs.com/docs/#/displaying/format/"> |
| 283 | + Set <a href="https://momentjs.com/docs/#/displaying/format/" target="_blank"> |
269 | 284 | MomentJS
|
270 | 285 | </a> format (e.g. "MMMM Do YYYY, h:mm A"):
|
271 |
| - </p> |
272 | 286 | </label>
|
273 | 287 | </dt>
|
274 | 288 | <dd>
|
|
282 | 296 | </div>
|
283 | 297 | </div>`;
|
284 | 298 | $("body").appendChild(div);
|
| 299 | + $("#ghst-utc").checked = useUTC === "true"; |
285 | 300 | on($("#ghst-settings"), "click", closePanel);
|
286 | 301 | on($("body"), "keyup", event => {
|
287 | 302 | if (
|
|
297 | 312 | });
|
298 | 313 | on($("#ghst-settings-inner"), "click", event => {
|
299 | 314 | event.stopPropagation();
|
300 |
| - event.preventDefault(); |
| 315 | + // event.preventDefault(); |
301 | 316 | });
|
302 | 317 | on($("#ghst-save"), "click", () => {
|
303 | 318 | closePanel();
|
304 | 319 | update("save");
|
305 | 320 | });
|
306 | 321 | on($("#ghst-locale"), "change", update);
|
| 322 | + on($("#ghst-utc"), "change", update); |
307 | 323 | on($("#ghst-format"), "change", update);
|
308 | 324 | on($("#ghst-cancel"), "click", closePanel);
|
309 | 325 | }
|
|
319 | 335 | if (mode === "revert") {
|
320 | 336 | $("#ghst-locale").value = locale;
|
321 | 337 | $("#ghst-format").value = timeFormat;
|
| 338 | + $("#ghst-utc").checked = useUTC === "true"; |
322 | 339 | }
|
323 | 340 | let loc = $("#ghst-locale").value || "en";
|
324 | 341 | let time = $("#ghst-format").value || "LLL";
|
| 342 | + let utc = $("#ghst-utc").checked ? "true" : "false"; |
325 | 343 | if (mode === "save") {
|
326 | 344 | timeFormat = time;
|
327 | 345 | locale = loc;
|
| 346 | + useUTC = utc; |
328 | 347 | GM_setValue("ghst-format", timeFormat);
|
329 | 348 | GM_setValue("ghst-locale", locale);
|
| 349 | + GM_setValue("ghst-utc", useUTC); |
330 | 350 | }
|
331 | 351 | moment.locale(loc);
|
332 | 352 | staticTime(time);
|
|
0 commit comments