Skip to content

Instantly share code, notes, and snippets.

Created November 10, 2016 23:07
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/00fc9c64065ef26e27c0584c5416636b to your computer and use it in GitHub Desktop.
Save anonymous/00fc9c64065ef26e27c0584c5416636b to your computer and use it in GitHub Desktop.
(You) counter
// ==UserScript==
// @name you counter
// @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
// ==/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);
console.log(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);
}
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; \
} \
" );
setInterval (render,30000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment