Skip to content

Instantly share code, notes, and snippets.

@chuckha
Created January 26, 2019 20:25
Show Gist options
  • Save chuckha/c4b959c9cc87bf75dc874999498627ab to your computer and use it in GitHub Desktop.
Save chuckha/c4b959c9cc87bf75dc874999498627ab to your computer and use it in GitHub Desktop.
auto advance instagram on a timer
// ==UserScript==
// @name InstaAutoAdvance
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically advance instagram photos on a timer
// @author You
// @match https://www.instagram.com/*
// @grant none
// ==/UserScript==
// Type 'niko' to start the script and 'okin' to stop it.
(function() {
"use strict";
var startKeyword = "niko";
var endKeyword = reverse(startKeyword);
var codes = {};
for (var i=0; i < 26; i++) {
codes[String.fromCharCode(97+i)] = 97+i;
}
var minutes = 10;
var interval = 1000 * 60 * minutes;
var matched = 0;
var id = 0;
document.addEventListener("keypress", function(input) {
// If the id of the interval is set then it should probably stop
if (id != 0) {
if (input.keyCode === codes[endKeyword[matched]]) {
matched++;
} else {
matched = 0;
}
if (matched == startKeyword.length) {
clearInterval(id);
id = 0;
matched = 0;
}
} else {
if (input.keyCode === codes[startKeyword[matched]]) {
matched++;
} else {
matched = 0;
}
if (matched == startKeyword.length) {
id = setInterval(function(){
document.getElementsByClassName("coreSpriteRightPaginationArrow")[0].click();
}, interval);
matched = 0;
}
}
});
})();
function reverse(s){
return s.split("").reverse().join("");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment