Skip to content

Instantly share code, notes, and snippets.

@rahatarmanahmed
Created July 5, 2015 16:58
Show Gist options
  • Save rahatarmanahmed/6a226e67495b1432585e to your computer and use it in GitHub Desktop.
Save rahatarmanahmed/6a226e67495b1432585e to your computer and use it in GitHub Desktop.
Darths & Droids EZ reader
// 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