Created
April 19, 2017 07:02
-
-
Save KingCprey/6857896aef8c0313edc9c19d5c54e46a to your computer and use it in GitHub Desktop.
Tampermonkey script
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
// ==UserScript== | |
// @name Reddit Upvote Bot | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match https://*.reddit.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const status_str="botstatus"; | |
const user_str="botuser"; | |
const post_str="botpost"; | |
const url_login="https://www.reddit.com/login"; | |
const status_login=1; | |
const status_find_post=2; | |
const status_upvote=3; | |
const status_stop=4; | |
function loggedIn(callback){ | |
var xhttp=new XMLHttpRequest(); | |
xhttp.addEventListener("load",function(){ | |
callback(xhttp.responseURL==="https://www.reddit.com/"); | |
}); | |
xhttp.open("GET","https://www.reddit.com/login"); | |
xhttp.send(); | |
} | |
function logout(){ | |
$(".logout.hover").submit(); | |
} | |
function login(user,pass){ | |
console.log("Logging in as "+user); | |
$("#user_login").val(user); | |
$("#passwd_login").val(pass); | |
$("#login-form > div > button").click(); | |
console.log("Submitted login form"); | |
} | |
function getUser(){return $(".user>a").text();} | |
var users={ | |
}; | |
var userkeys=Object.keys(users); | |
var posts_to_upvote=[ | |
"https://www.reddit.com/r/blog/comments/66455r/looking_back_at_rplace/?ref=share&ref_source=link" | |
]; | |
function getItem(name,defvalue){ | |
var val=localStorage.getItem(name); | |
if(val===null){return defvalue; | |
}else{return val;} | |
} | |
function hasItem(name){return localStorage.getItem(name)!==null;} | |
function setItem(name,value){localStorage.setItem(name,value); } | |
function redirect(url){window.location=url;} | |
console.log("Status = "+getItem(status_str)); | |
switch(parseInt(getItem(status_str,"-1"))){ | |
case status_login: | |
console.log("Need logging in"); | |
if(window.location!==url_login){ | |
console.log("Not on login page, redirecting"); | |
redirect(url_login); | |
} | |
var user=getItem(user_str); | |
if(user===null){ | |
alert("Reddit bot user set to null, stopping"); | |
setItem(status_str,status_stop); | |
break; | |
}else{ | |
var password=users[user]; | |
login(user,password); | |
setItem(status_str,status_stop); | |
} | |
break; | |
case status_find_post: | |
console.log("LOGGED IN AND FINDING POSTS"); | |
loggedIn((is_logged)=>{ | |
console.log("Is logged in = "+is_logged); | |
if(is_logged){ | |
} | |
}); | |
break; | |
case status_upvote: | |
break; | |
case status_stop: | |
break; | |
default: | |
console.log("Starting reddit upvote bot"); | |
if(userkeys.length>0){ | |
setItem(user_str,userkeys[0]); | |
setItem(status_str,status_login); | |
location.reload(); | |
}else{ | |
setItem(status_str,status_stop); | |
alert("No users specified, cannot continue upvote bot"); | |
} | |
break; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment