Last active
August 29, 2015 13:56
-
-
Save csinchok/9254216 to your computer and use it in GitHub Desktop.
Just a hack that goes into the teaser field on a video
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
<script type="text/javascript"> | |
var primaryId = "1960"; | |
var alternateIds = ["1647", "1648", "1649", "1642", "1637", "1629"]; | |
function chooseVideo(){ | |
var watched = localStorage.getItem("mj_video_variants"); | |
if (watched === null) { | |
watched = []; | |
} else { | |
watched = watched.split(","); | |
} | |
// If the primary video has been seen, or on 20% of new plays, show an alternate. | |
if (watched.indexOf(primaryId) !== -1 || Math.random() < 0.20) { | |
var unWatched = []; | |
for (var index in alternateIds) { | |
if (watched.indexOf(alternateIds[index]) === -1) { | |
unWatched.push(alternateIds[index]); | |
} | |
} | |
if (unWatched.length === 0) { | |
watched = alternateIds; | |
watched.push(primaryId); | |
unWatched = watched; | |
} | |
var randomIndex = Math.floor(Math.random() * unWatched.length); | |
videoId = unWatched[randomIndex]; | |
var srcHTML = '<source src="http://v.theonion.com/onionmedia/videos/videometa/' + videoId + '/zen_mp4.mp4" type="video/mp4"><source src="http://v.theonion.com/onionmedia/videos/videometa/' + videoId + '/zen_webm.webm" type="video/webm">'; | |
var videoEl = document.getElementById(primaryId); | |
videoEl.innerHTML = srcHTML; | |
watched.push(videoId); | |
} else { | |
watched = [primaryId]; | |
} | |
localStorage.setItem("mj_video_variants", watched.join(",")); | |
} | |
if (typeof videoId === 'undefined') { | |
var videoId = null; | |
chooseVideo(); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Couple notes, I might be wrong: