Created
July 5, 2015 16:58
-
-
Save rahatarmanahmed/6a226e67495b1432585e to your computer and use it in GitHub Desktop.
Darths & Droids EZ reader
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
// Makes it so clicking on the current comic loads the next one. Also updates the URL so you can go back and forward. | |
var e = document.querySelector('body > div.center > p:nth-child(2) > img'); | |
e.addEventListener('click', function() { | |
var next = function(n) { var s = '0000' + (++n); return s.substr(s.length - 4); }; | |
window.history.pushState({n: this.src.match(/\d{4}/)[0].replace(/\d{4}/, next)}, 'idk', window.location.href.replace(/\d{4}/, next)); | |
this.src = this.src.replace(/\d{4}/, next); | |
}); | |
window.onpopstate = function(ev) { | |
e.src = e.src.replace(/\d{4}/, ev.state.n); | |
console.log(ev); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment