Skip to content

Instantly share code, notes, and snippets.

@krmanik
Last active December 22, 2020 20:05
Show Gist options
  • Save krmanik/57a7df4f140d3cf3c9b5dd4788bca6ce to your computer and use it in GitHub Desktop.
Save krmanik/57a7df4f140d3cf3c9b5dd4788bca6ce to your computer and use it in GitHub Desktop.
Adding version popup in Anki Deck description
<style>
.popup {
position: relative;
display: inline-block;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s;
}
.btn {
height:25px;
width:45px;
padding:2px;
background-color: #e53935;
border: none;
border-radius: 3px;
color: white;
outline:none;
}
.btn:hover {
background-color: #f44336;
}
</style>
<script>
var deckVersion = "1.2"; // version come with deck
var xhttp = new XMLHttpRequest();
var obj;
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
obj = JSON.parse(this.responseText);
//console.log(obj);
if (obj['version'] > deckVersion) { // comparing deck version with version inside json
console.log('update available');
var popup = document.getElementById("versionPopup");
popup.classList.toggle("show");
}
}
};
xhttp.open("GET", "https://cdn.jsdelivr.net/gh/infinyte7/Write-Kanji@master/Versions/version.json", true); // version file on GitHub
xhttp.send();
</script>
<center>
<a class="popup" href="https://github.com/infinyte7/Write-Kanji/releases"><span class="popuptext" id="versionPopup">Update Available <button class="btn">update</button></span></a>
</center>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment