Advertisement
erinx

/Animus/ Customizer 0.5

Sep 26th, 2015
4,218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        /Animus/ Customizer
  3. // @namespace   erin
  4. // @description Customize your post through the /Animus/ store
  5. // @include     *8ch.net/animus/*
  6. // @version     0.5
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. (function(){
  11.  
  12.  
  13.   var d, db, h, namespace, $, $$, version;
  14.  
  15.   d = document;
  16.   db = document.body;
  17.   h = document.getElementsByTagName('head')[0];
  18.  
  19.   namespace = "animusCustom";
  20.   version = 0.5;
  21.  
  22.   if(window.location.href.indexOf('8ch.net') > 0){
  23.     var $siteDomain = '8ch.net';    
  24.   }else{
  25.     var $siteDomain = '8chan.co';
  26.   }
  27.  
  28.   $ = function(s, p){
  29.     if(!p || p == null){
  30.       p = db;
  31.     }
  32.     return p.querySelector(s);
  33.   };
  34.  
  35.   $$ = function(s, p){
  36.     if(!p || p == null){
  37.       p = db;
  38.     }
  39.     return p.querySelectorAll(s);
  40.   };
  41.  
  42.   $.getVal = function(k, v){
  43.     if(typeof(Storage) !=="undefined"){
  44.       if(v == null){
  45.         if(localStorage.getItem(namespace + "." + k) != null){
  46.           return localStorage.getItem(namespace  + "." + k);
  47.         }else{
  48.           return 'undefined';
  49.         }
  50.       }else{
  51.         if(localStorage.getItem(namespace + "." + k) != null){
  52.           return localStorage.getItem(namespace + "." + k);
  53.         }else{
  54.           return v;
  55.         }
  56.       }
  57.     }else{
  58.       return 'storage unavailable';
  59.     }
  60.   };
  61.  
  62.   $.setVal = function(k, v){
  63.     if(typeof(Storage) !=="undefined"){
  64.       if(v == null){
  65.         return 'undefined';
  66.       }else{
  67.         return localStorage.setItem(namespace  + "." + k, v);
  68.       }
  69.     }else{
  70.       return 'storage unavailable';
  71.     }
  72.   };
  73.  
  74.   $.delVal = function(k){
  75.     return localStorage.removeItem(namespace + "." + k);
  76.   };
  77.  
  78.   $.elm = function(t, a, s){
  79.     var e = d.createElement(t);
  80.     if(a){
  81.       for (key in a){
  82.         e.setAttribute(key, a[key]);
  83.       }
  84.     }
  85.     if(s){
  86.       s.appendChild(e);
  87.     }
  88.     return e;
  89.   };
  90.  
  91.   $.each = function(a, c, e){
  92.     for(var i = 0; i < a.length; i++){
  93.       c(a[i], i);
  94.       if(i == (a.length)-1){
  95.         if(e && e != null){
  96.           return e(a[i], i);
  97.         }else{
  98.           return a;
  99.         }
  100.       }
  101.     }
  102.   };
  103.  
  104.   $.JSON = function(s){
  105.     if(typeof s == 'string'){
  106.       return JSON.parse(s);
  107.     }else{
  108.       return JSON.stringify(s);
  109.     }
  110.   };
  111.  
  112.   $.time = function(t, c, l){
  113.     if(c == false){
  114.       return clearInterval(t);
  115.     }else{
  116.       if(l == true){
  117.         return setInterval(function(){
  118.           c();
  119.         },t);
  120.       }else{
  121.         return setTimeout(function(){
  122.           c();
  123.         },t);
  124.       }
  125.     }
  126.   };
  127.  
  128.   $.att = function(s, a, v) {
  129.     if (!v || v == null || v == false) {
  130.       if (v == false) {
  131.         return s.removeAttribute(a);
  132.       } else {
  133.         return s.getAttribute(a);
  134.       }
  135.     } else {
  136.       s.setAttribute(a, v);
  137.       return s;
  138.     }
  139.   };
  140.  
  141.   $.event = function(t, i, s){
  142.     if (i == null) {
  143.       i = {};
  144.     }
  145.     if (s == null) {
  146.       s = d;
  147.     }
  148.     return s.dispatchEvent(new CustomEvent(t, i));
  149.   };
  150.  
  151.  
  152.   $.after = function(e, s){
  153.     s.parentNode.insertBefore(e, s.nextSibling);
  154.     return e;
  155.   };
  156.  
  157.   $.before = function(e, s){
  158.     s.parentNode.insertBefore(e, s);
  159.     return e;
  160.   };
  161.  
  162.   var pageLength = $$('.post').length;
  163.  
  164.    var trackUpdater = function(t, n){
  165.     var updater = $('#update_secs');
  166.     if(updater.innerHTML != 'Updating...'){
  167.       if(t == true && $$('.post').length > pageLength){
  168.         var e = {};
  169.         e.detail = {};
  170.         e.detail['count'] = (parseFloat($$('.post').length) - parseFloat(pageLength));
  171.         $.event('threadUpdate', e, d);
  172.         pageLength = $$('.post').length;
  173.       }
  174.       if(parseFloat(updater.innerHTML) > 15){
  175.         return $.time(3000, function(){ trackUpdater(false, 0); }, false);
  176.       }else if(parseFloat(updater.innerHTML) < 3){
  177.         return $.time(200, function(){ trackUpdater(false, 0); }, false);      
  178.       }else{
  179.         return $.time(500, function(){ trackUpdater(false, 0); }, false);
  180.       }
  181.     }else{
  182.       return $.time(100, function(){ trackUpdater(true, $$('.post').length); }, false);
  183.     }  
  184.   }
  185.  
  186.   $.time(5000, function(){ trackUpdater(false, 0); }, false);
  187.  
  188.  
  189.   var $index = $.JSON($.getVal('list', '[]'));
  190.  
  191.   var $getList = function(){
  192.     var xhr = new XMLHttpRequest();
  193.     xhr.open("GET", window.location.protocol + '//erin.wtf/postassets.php');
  194.     xhr.onreadystatechange = function(){
  195.       if(xhr.readyState == 4 && xhr.status == 200){
  196.         $index = $.JSON(xhr.responseText);        
  197.         $.setVal('list', xhr.responseText);
  198.       }      
  199.     }
  200.     xhr.send();          
  201.   }
  202.  
  203.   $getList();
  204.  
  205.   $.time((1000*60*3), function(){
  206.     $getList();  
  207.   }, true);
  208.  
  209.   var $applyItems = function(){
  210.     $.each($$('.reply'), function(xe, xi){
  211.       if($('.trip', xe)){
  212.         var $trip = $('.trip', xe).innerHTML;
  213.         if($index[$trip]){
  214.           if($index[$trip]['background']){
  215.             xe.style.backgroundImage = 'url("' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['background'] + '")';
  216.             xe.style.backgroundRepeat = 'repeat';
  217.             $('.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';
  218.             $('.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';
  219.             if($('.subject', xe)){
  220.               $('.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';
  221.             }
  222.             if($index[$trip]['background'] != 'eeveetrans.png'){
  223.               xe.style.color = 'black';
  224.             }
  225.           }
  226.          
  227.           if($index[$trip]['nameicon']){
  228.             if(!$('.name-icon-mod', xe)){
  229.               var $icon = {};
  230.               $icon['class'] = 'name-icon-mod';
  231.               $icon = $.elm('span', $icon);
  232.               $icon.innerHTML = '<img style="height:16px;margin-bottom:-3px;" src="' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['nameicon'] + '"> ';
  233.               $.before($icon, $('.name', xe));
  234.             }
  235.           }
  236.          
  237.           if($index[$trip]['signature']){
  238.             $('.body', xe).style.backgroundImage = 'url("' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['signature'] + '")';
  239.             $('.body', xe).style.backgroundRepeat = 'no-repeat';
  240.             $('.body', xe).style.backgroundPosition = 'right bottom';
  241.             $('.body', xe).style.paddingBottom = '25px';
  242.            
  243.           }
  244.          
  245.           if($index[$trip]['imageborder']){
  246.             if($('.post-image', xe)){
  247.               $('.post-image', xe).style.border = "13px solid transparent";
  248.               $('.post-image', xe).style.borderImage = 'url("' + window.location.protocol + '//erin.wtf/postassets/' + $index[$trip]['imageborder'] + '") 13 repeat';
  249.              
  250.             }            
  251.           }
  252.          
  253.           if($index[$trip]['tripcode']){
  254.             $('.trip', xe).title = $trip;
  255.             $('.trip', xe).innerHTML = $index[$trip]['tripcode'];          
  256.           }
  257.        
  258.         }        
  259.       }    
  260.     });    
  261.   }
  262.   $applyItems();
  263.  
  264.   $.time(1300, function(){ $applyItems(); }, false);
  265.  
  266.   d.addEventListener('8chan-Z.NewPosts', function(){ $applyItems(); $.time(2000, function(){ $applyItems(); }, false); }, false);
  267.   d.addEventListener('threadUpdate', function(){ $applyItems(); $.time(2000, function(){ $applyItems(); }, false); }, false);
  268.   d.addEventListener('new_post', function(){ $applyItems(); $.time(2000, function(){ $applyItems(); }, false); }, false);
  269.    
  270. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement