Skip to content

Instantly share code, notes, and snippets.

@BarakChamo
Last active November 16, 2017 22:43
Show Gist options
  • Save BarakChamo/eeb200586bb54e50bccbb4fba3142794 to your computer and use it in GitHub Desktop.
Save BarakChamo/eeb200586bb54e50bccbb4fba3142794 to your computer and use it in GitHub Desktop.
Camera Capture Thingy
a = window;
TIME_SWITCH_TIME = 4000;
DOWNLOAD_TIME = 2000;
function captureImage(time) {
document.createElement("img");
var c = document.createElement("canvas"),
d = c.getContext("2d"),
e,
f,
g,
h;
c.width = 960;
c.height = 540;
f = "none" === jQuery(jQuery(".video-window video")[0]).parent().css("display") ? jQuery(jQuery(".video-window video")[1]) : jQuery(jQuery(".video-window video")[0]);
var l = jQuery(".video-window").position();
g = l.left;
h = l.top;
if (960 < a.innerWidth && screenfull.isFullscreen) {
d.drawImage(f[0], 0, 0, c.width, c.height)
} else
960 > a.innerWidth && screenfull.isFullscreen ? d.drawImage(f[0], 0, 0, 960, 540) : d.drawImage(f[0], g, h, f.width(), f.height());
this._currentImageURL = c.toDataURL("image/png", .92)
console.log(c);
this._currentImageURL && downloadImage(this._currentImageURL, time)
};
function downloadImage(image, time) {
console.log("DOWNLOAD", time);
var downloadLink = document.createElement("a");
downloadLink.href = image;
downloadLink.download = window.location.pathname.slice(1, -1) + "-" + time + ".png";
document.body.appendChild(downloadLink);
downloadLink.click();
console.log("downloading " + time)
document.body.removeChild(downloadLink);
}
function goOverClips() {
var clips = Array.from(document.getElementsByClassName('clip'));
clips.forEach((clip, i) => {
setTimeout(() => {
var clipTime = clip.getAttribute("data-time");
clip.click();
console.log("Switch video to " + clipTime)
setTimeout(() => {
console.log("capturing " + clipTime)
captureImage(clipTime);
}, DOWNLOAD_TIME);
}, i * TIME_SWITCH_TIME)
})
}
earthcam.Share.prototype.shareImageReady = downloadImage
// Switch mode to archive
window.earthcam.BlackBar.prototype.switchMode("archive");
setTimeout(() => goOverClips(), 2000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment