Skip to content

Instantly share code, notes, and snippets.

Created November 14, 2016 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/c5bcd0e5e31c610dd39f73ff8cbcc52d to your computer and use it in GitHub Desktop.
Save anonymous/c5bcd0e5e31c610dd39f73ff8cbcc52d to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name You Count
// @namespace ben
// @include https://boards.4chan.org/*
// @include http://boards.4chan.org/*
// @version 1
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// @require http://code.jquery.com/jquery-1.9.1.js
// @require http://code.jquery.com/ui/1.10.3/jquery-ui.js
// author: ben
// ==/UserScript==
/*jshint multistr: true */
adder = null;
remover = null;
allTimeYou = GM_getValue("totalYou",null);
function count(){
num = $('.you').length;
console.log('counting');
console.log(num);
return num
}
function write(input){
if (adder != null){
if (adder != 0){
storage();
}
}
}
function difference(){
var here = count();
if (adder != null){
remover = (here - adder)
adder = (here - adder) + adder;
console.log('new value ' + adder);
}
else{
adder = here
console.log('starting adder');
}
}
function render(){
difference();
write(adder);
document.getElementById("gmYouCounter").innerHTML="(You) Count: " + allTimeYou;
}
function storage(){
var store = GM_getValue("youHashTable",null);
if (store == null){
store = {};
store[window.location.href] = adder
}
else{
if (store[window.location.href] != 0){
store[window.location.href] = store[window.location.href] + remover}
else{
store[window.location.href] = adder
}
}
GM_setValue('youHashTable',store);
console.log(store)
var total = 0
for (var property in store){
total += store[property];
}
allTimeYou = total
GM_setValue('totalYou',allTimeYou);
document.getElementById("gmYouCounter").innerHTML="(You) Count: " + allTimeYou;
}
var newHTML = document.createElement ('div');
newHTML.innerHTML = ' \
<div id="gmYouCounter"> \
<p>"Total You Count:" </p> \
</div> \
';
document.body.appendChild (newHTML);
document.getElementById("gmYouCounter").innerHTML="(You) Count: " + allTimeYou;
GM_addStyle ( " \
#gmYouCounter { \
position: fixed; \
background-color: #1b1b1b; \
color: #cccaca; \
top: 5px; \
right: 5px; \
font-size: 16px; \
} \
" );
$(document).load(setInterval(render,15000));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment