ytkns/public/assets/shared.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-06-10 16:03:13 +00:00
var _paq = window._paq || [];
_paq.push(['disableCookies']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
_paq.push(['enableHeartBeatTimer']);
(function() {
_paq.push(['setTrackerUrl', '//uiharu.railgun.sh/mtm']);
_paq.push(['setSiteId', 'zlwmGOjMBk5J']);
var g = document.createElement('script');
g.type = 'text/javascript'; g.async = true;
g.defer = true; g.src = '//uiharu.railgun.sh/mtm.js';
document.head.appendChild(g);
})();
function synchroniseBackgroundWithAudio(bgi, target) {
var cnt = document.getElementById(target || 'BackgroundImage') || document.getElementById('container'),
bga = document.getElementById('BackgroundAudio'),
rdy = false,
bgs = [];
if(!cnt)
return;
var computed = getComputedStyle(cnt);
if(computed.backgroundImage && target !== 'ForegroundImage')
bgs = computed.backgroundImage.split(',');
if(!bga) {
bgs.splice(0, 0, 'url(' + bgi + ')');
cnt.style.backgroundImage = bgs.join(',');
return;
}
var onReady = function(url) {
bgs.splice(0, 0, 'url(' + url + ')');
cnt.style.backgroundImage = bgs.join(',');
bga.play();
};
bga.addEventListener('canplay', function() {
rdy = true;
});
bga.pause();
bga.currentTime = 0;
var xhr = new XMLHttpRequest;
xhr.responseType = 'blob';
xhr.onreadystatechange = function() {
if(xhr.readyState !== 4)
return;
bgi = URL.createObjectURL(xhr.response);
if(rdy)
onReady(bgi);
else
bga.addEventListener('canplay', function() {
onReady(bgi);
});
};
xhr.open('GET', bgi);
xhr.send();
}