Created
November 5, 2023 13:44
-
-
Save btmcsweeney/50ba7a687f6b8c2ccb2acc61d8c0714f to your computer and use it in GitHub Desktop.
Userscript to display Buyee Yahoo! Auction pages in the user's local timezone
This file contains 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
// ==UserScript== | |
// @name Buyee Yahoo Auction Timezone Converter | |
// @namespace http://tampermonkey.net/ | |
// @version 0.2 | |
// @description Convert Yahoo! Auction timestamps on Buyee to local timezone | |
// @author Brian McSweeney | |
// @match https://buyee.jp/item/yahoo/auction/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=buyee.jp | |
// @grant none | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js | |
// @require https://momentjs.com/downloads/moment.min.js | |
// @require https://momentjs.com/downloads/moment-timezone-with-data.min.js | |
// ==/UserScript== | |
/* global $ */ | |
/* global moment */ | |
(function() { | |
'use strict'; | |
var timeElements = $("ul#itemDetail_data > li:contains('(JST)')") | |
// moment.js conversion testing | |
// moment.tz('1 Oct 2023 23:20:19', 'D MMM YYYY HH:mm:ss', 'Asia/Tokyo').tz(moment.tz.guess()).format('D MMM YYYY HH:mm:ss') | |
// Get user timezone | |
const zone = moment.tz.guess() | |
// Output format - https://momentjs.com/docs/#/displaying/format/ | |
const timeFormat = 'ddd, MMM Do - h:mm:ss A' | |
// Regex to find the time string in the innerhtml | |
const timeRegex = /\d\d? [A-Z][a-z]{2} \d{4} \d\d?:\d\d:\d\d/g | |
// Update the displayed time and zone | |
for (var i in timeElements.toArray()) { | |
var timeString = timeElements[i].innerHTML.match(timeRegex)[0] | |
var abbrString = moment.tz(timeString, 'D MMM YYYY HH:mm:ss', 'Asia/Tokyo').tz(zone).format('(z)') | |
timeElements[i].innerHTML = timeElements[i].innerHTML.replace('(JST)', abbrString) | |
var localTimeString = moment.tz(timeString, 'D MMM YYYY HH:mm:ss', 'Asia/Tokyo').tz(zone).format(timeFormat) | |
timeElements[i].innerHTML = timeElements[i].innerHTML.replace(timeString, localTimeString) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment