Skip to content

Instantly share code, notes, and snippets.

@appleneko2001
Forked from sam0737/clock.html
Last active September 4, 2022 18:40
Show Gist options
  • Select an option

  • Save appleneko2001/88c4ab9f0b2235e8f97b2ee5da9d4e85 to your computer and use it in GitHub Desktop.

Select an option

Save appleneko2001/88c4ab9f0b2235e8f97b2ee5da9d4e85 to your computer and use it in GitHub Desktop.
個人修改版Clock with Browser source for OBS Studio
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body translate="no" >
<div id="output"></div>
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment-with-locales.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.33/moment-timezone-with-data.min.js'></script>
<script>
// https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
var urlParams;
(function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
urlParams = {};
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();
// Set moment.js locale to zh-tw
moment.locale('zh-tw');
var output = document.getElementById("output");
if (urlParams["style"]) output.setAttribute("style", urlParams["style"]);
if (urlParams["bodyStyle"]) document.body.setAttribute("style", urlParams["bodyStyle"]);
var c;
setInterval(
c = function() {
output.innerText = moment().tz("Asia/Taipei").format(urlParams["format"] || '');
}, 1000);
c();
</script>
</body>
</html>
@appleneko2001
Copy link
Author

appleneko2001 commented May 22, 2021

This is clock for OBS Studio use. It uses moment.js and moment-timezone.js library for handles clock formats, timezones and etc.

Warning: moment.js in this gist file are using zh-tw locale.

Usage

In OBS Studio, you have to add an browser source to your scene, and copy next url to URL field
https://gistcdn.githack.com/appleneko2001/88c4ab9f0b2235e8f97b2ee5da9d4e85/raw/0313439048780b10a776df1304d6014903e7dfd6/clock.html

Format of moment.js can be determined in moment.js -> Format Dates.

For example, you want a clock looks like that:

2021 五月 22, 7:37:41 晚上

your url should be looks like this:
https://gistcdn.githack.com/appleneko2001/88c4ab9f0b2235e8f97b2ee5da9d4e85/raw/0313439048780b10a776df1304d6014903e7dfd6/clock.html?format=YYYY MMMM DD, h:mm:ss a

Credit of original gist: https://gist.github.com/sam0737/a0ee8ca253fc5c84b2aa2ac018f7b8ad
Credit of idea: Youtube@IT9GameLog

Referenced resource: Raw Githack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment