// ==UserScript==
// @name /Animus/ Customizer
// @namespace erin
// @description Customize your post through the /Animus/ store
// @include *8ch.net/animus/*
// @version 0.5
// @grant none
// ==/UserScript==
(function(){
var d, db, h, namespace, $, $$, version;
d = document;
db = document.body;
h = document.getElementsByTagName('head')[0];
namespace = "animusCustom";
version = 0.5;
if(window.location.href.indexOf('8ch.net') > 0){
var $siteDomain = '8ch.net';
}else{
var $siteDomain = '8chan.co';
}
$ = function(s, p){
if(!p || p == null){
p = db;
}
return p.querySelector(s);
};
$$ = function(s, p){
if(!p || p == null){
p = db;
}
return p.querySelectorAll(s);
};
$.getVal = function(k, v){
if(typeof(Storage) !=="undefined"){
if(v == null){
if(localStorage.getItem(namespace + "." + k) != null){
return localStorage.getItem(namespace + "." + k);
}else{
return 'undefined';
}
}else{
if(localStorage.getItem(namespace + "." + k) != null){
return localStorage.getItem(namespace + "." + k);
}else{
return v;
}
}
}else{
return 'storage unavailable';
}
};
$.setVal = function(k, v){
if(typeof(Storage) !=="undefined"){
if(v == null){
return 'undefined';
}else{
return localStorage.setItem(namespace + "." + k, v);
}
}else{
return 'storage unavailable';
}
};
$.delVal = function(k){
return localStorage.removeItem(namespace + "." + k);
};
$.elm = function(t, a, s){
var e = d.createElement(t);
if(a){
for (key in a){
e.setAttribute(key, a[key]);
}
}
if(s){
s.appendChild(e);
}
return e;
};
$.each = function(a, c, e){
for(var i = 0; i < a.length; i++){
c(a[i], i);
if(i == (a.length)-1){
if(e && e != null){
return e(a[i], i);
}else{
return a;
}
}
}
};
$.JSON = function(s){
if(typeof s == 'string'){
return JSON.parse(s);
}else{
return JSON.stringify(s);
}
};
$.time = function(t, c, l){
if(c == false){
return clearInterval(t);
}else{
if(l == true){
return setInterval(function(){
c();
},t);
}else{
return setTimeout(function(){
c();
},t);
}
}
};
$.att = function(s, a, v) {
if (!v || v == null || v == false) {
if (v == false) {
return s.removeAttribute(a);
} else {
return s.getAttribute(a);
}
} else {
s.setAttribute(a, v);
return s;
}
};
$.event = function(t, i, s){
if (i == null) {
i = {};
}
if (s == null) {
s = d;
}
return s.dispatchEvent(new CustomEvent(t, i));
};
$.after = function(e, s){
s.parentNode.insertBefore(e, s.nextSibling);
return e;
};
$.before = function(e, s){
s.parentNode.insertBefore(e, s);
return e;
};
var pageLength = $$('.post').length;
var trackUpdater = function(t, n){
var updater = $('#update_secs');
if(updater.innerHTML != 'Updating...'){
if(t == true && $$('.post').length > pageLength){
var e = {};
e.detail = {};
e.detail['count'] = (parseFloat($$('.post').length) - parseFloat(pageLength));
$.event('threadUpdate', e, d);
pageLength = $$('.post').length;
}
if(parseFloat(updater.innerHTML) > 15){
return $.time(3000, function(){ trackUpdater(false, 0); }, false);
}else if(parseFloat(updater.innerHTML) < 3){
return $.time(200, function(){ trackUpdater(false, 0); }, false);
}else{
return $.time(500, function(){ trackUpdater(false, 0); }, false);
}
}else{
return $.time(100, function(){ trackUpdater(true, $$('.post').length); }, false);
}
}
$.time(5000, function(){ trackUpdater(false, 0); }, false);
var $index = $.JSON($.getVal('list', '[]'));
var $getList = function(){
var xhr = new XMLHttpRequest();
xhr.open("GET", window.location.protocol + '//erin.wtf/postassets.php');
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
$index = $.JSON(xhr.responseText);
$.setVal('list', xhr.responseText);
}
}
xhr.send();
}
$getList();
$.time((1000*60*3), function(){
$getList();
}, true);
var $applyItems = function(){
$.each($$('.reply'), function(xe, xi){
if($('.trip', xe)){
var $trip = $('.trip', xe).innerHTML;
if($index[$trip]){
if($index[$trip]['background']){
xe.style.backgroundImage = 'url("' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['background'] + '")';
xe.style.backgroundRepeat = 'repeat';
$('.name', xe).style.textShadow = '1px 0 0 #FFF, -1px 0 0 #FFF, 0 1px 0 #FFF, 0 -1px 0 #FFF, 1px 1px #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF';
$('.trip', xe).style.textShadow = '1px 0 0 #FFF, -1px 0 0 #FFF, 0 1px 0 #FFF, 0 -1px 0 #FFF, 1px 1px #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF';
if($('.subject', xe)){
$('.trip', xe).style.textShadow = '1px 0 0 #FFF, -1px 0 0 #FFF, 0 1px 0 #FFF, 0 -1px 0 #FFF, 1px 1px #FFF, -1px -1px 0 #FFF, 1px -1px 0 #FFF, -1px 1px 0 #FFF';
}
if($index[$trip]['background'] != 'eeveetrans.png'){
xe.style.color = 'black';
}
}
if($index[$trip]['nameicon']){
if(!$('.name-icon-mod', xe)){
var $icon = {};
$icon['class'] = 'name-icon-mod';
$icon = $.elm('span', $icon);
$icon.innerHTML = '<img style="height:16px;margin-bottom:-3px;" src="' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['nameicon'] + '"> ';
$.before($icon, $('.name', xe));
}
}
if($index[$trip]['signature']){
$('.body', xe).style.backgroundImage = 'url("' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['signature'] + '")';
$('.body', xe).style.backgroundRepeat = 'no-repeat';
$('.body', xe).style.backgroundPosition = 'right bottom';
$('.body', xe).style.paddingBottom = '25px';
}
if($index[$trip]['imageborder']){
if($('.post-image', xe)){
$('.post-image', xe).style.border = "13px solid transparent";
$('.post-image', xe).style.borderImage = 'url("' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['imageborder'] + '") 13 repeat';
}
}
if($index[$trip]['tripcode']){
$('.trip', xe).title = $trip;
$('.trip', xe).innerHTML = $index[$trip]['tripcode'];
}
}
}
});
}
$applyItems();
$.time(1300, function(){ $applyItems(); }, false);
d.addEventListener('8chan-Z.NewPosts', function(){ $applyItems(); $.time(2000, function(){ $applyItems(); }, false); }, false);
d.addEventListener('threadUpdate', function(){ $applyItems(); $.time(2000, function(){ $applyItems(); }, false); }, false);
d.addEventListener('new_post', function(){ $applyItems(); $.time(2000, function(){ $applyItems(); }, false); }, false);
})();
Comments