Advertisement
erinx

CJMT #

Dec 30th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        CJMT #
  3. // @namespace   erin
  4. // @description Adds the new thread number!
  5. // @include     *://8ch.net/lewd/*
  6. // @version     0.01
  7. // @grant       none
  8. // ==/UserScript==
  9.  
  10. function cjmt(){
  11.  
  12.   var d, db, h, $, $$, namespace;
  13.  
  14.   d = document;
  15.   db = document.body;
  16.   h = document.getElementsByTagName('head')[0];
  17.   namespace = 'lewd';
  18.  
  19.   $ = function(s, p){
  20.     if(!p || p == null){
  21.       p = db;
  22.     }
  23.     return p.querySelector(s);
  24.   };
  25.  
  26.   $$ = function(s, p){
  27.     if(!p || p == null){
  28.       p = db;
  29.     }
  30.     return p.querySelectorAll(s);
  31.   };
  32.  
  33.   $.JSON = function(s){
  34.     if(typeof s == 'string'){
  35.       return JSON.parse(s);
  36.     }else{
  37.       return JSON.stringify(s);
  38.     }
  39.   };
  40.  
  41.   $.time = function(t, c, l){
  42.     if(c == false){
  43.       return clearInterval(t);
  44.     }else{
  45.       if(l == true){
  46.         return setInterval(function(){
  47.           c();
  48.         },t);
  49.       }else{
  50.         return setTimeout(function(){
  51.           c();
  52.         },t);
  53.       }
  54.     }
  55.   };
  56.  
  57.   $.getVal = function(k, v){
  58.     if(typeof(Storage) !=="undefined"){
  59.       if(v == null){
  60.         if(localStorage.getItem(namespace + "." + k) != null){
  61.           return localStorage.getItem(namespace  + "." + k);
  62.         }else{
  63.           return 'undefined';
  64.         }
  65.       }else{
  66.         if(localStorage.getItem(namespace + "." + k) != null){
  67.           return localStorage.getItem(namespace + "." + k);
  68.         }else{
  69.           return v;
  70.         }
  71.       }
  72.     }else{
  73.       return 'storage unavailable';
  74.     }
  75.   };
  76.  
  77.   $.setVal = function(k, v){
  78.     if(typeof(Storage) !=="undefined"){
  79.       if(v == null){
  80.         return 'undefined';
  81.       }else{
  82.         return localStorage.setItem(namespace  + "." + k, v);
  83.       }
  84.     }else{
  85.       return 'storage unavailable';
  86.     }
  87.   };
  88.  
  89.   $.delVal = function(k){
  90.     return localStorage.removeItem(namespace + "." + k);
  91.   };
  92.  
  93.   $.elm = function(t, a, s){
  94.     var e = d.createElement(t);
  95.     if(a){
  96.       for (key in a){
  97.         e.setAttribute(key, a[key]);
  98.       }
  99.     }
  100.     if(s){
  101.       s.appendChild(e);
  102.     }
  103.     return e;
  104.   };
  105.  
  106.   $.each = function(a, c, e){
  107.     for(var i = 0; i < a.length; i++){
  108.       c(a[i], i);
  109.       if(i == (a.length)-1){
  110.         if(e && e != null){
  111.           return e(a[i], i);
  112.         }else{
  113.           return a;
  114.         }
  115.       }
  116.     }
  117.   };
  118.  
  119.   function initCJMT(){
  120.    
  121.     var $open = {};
  122.     $open['id'] = 'cjmt-open';      
  123.     $open['style'] = 'cursor:pointer;';
  124.     $open = $.elm('span', $open, $('.kqr-leftopts'));
  125.     $open.innerHTML = '<a>[#]</a>';
  126.  
  127.     var $win = {};
  128.     $win['id'] = 'cjmt-win';  
  129.     $win['style'] = 'display:none;text-align:center;';
  130.     $win = $.elm('div', $win, $('#kqr'));
  131.     $win.innerHTML = 'CJMT <button id="cjmt-set"></button> / #<input id="cjmt-num" style="width:30px;">:<button id="cjmt-cust">Set</button> / <button id="cjmt-rest">Restore</button>';
  132.     $('#cjmt-set').innerHTML = '#' + (parseInt($.getVal('CJMT', '0'))+1);
  133.    
  134.     $open.addEventListener('click', function(){
  135.       if($win.style.display == "none"){
  136.         $win.style.display = "";
  137.       }else{
  138.         $win.style.display = "none";                                  
  139.       }
  140.     }, false);
  141.    
  142.     $.each($$('.subject'), function(za, zi){
  143.       if(za.innerHTML.indexOf('CJMT') > -1 && za.innerHTML.indexOf('#') > 0){
  144.         var $pat = /[0-9]+/g;
  145.         var $match = $pat.exec(za.innerHTML.split('#')[1]);
  146.         console.log($match[0]);
  147.         if($match[0] >= parseInt($.getVal('CJMT', '0'))){
  148.           $.setVal('CJMT', $match[0]);
  149.           $('#cjmt-set').innerHTML = '#' + (parseInt($match[0])+1);
  150.         }        
  151.       }
  152.     });
  153.    
  154.     $('#cjmt-set').addEventListener('click', function(){
  155.       if($('#kqr-subject').value.indexOf('CJMT #') < 0){
  156.         $.setVal('rest', $('#kqr-subject').value);
  157.       }
  158.       $('#kqr-subject').value = 'CJMT #' + (parseInt($.getVal('CJMT', '0'))+1);
  159.     }, false);
  160.    
  161.     $('#cjmt-cust').addEventListener('click', function(){
  162.       if($('#kqr-subject').value.indexOf('CJMT #') < 0){
  163.         $.setVal('rest', $('#kqr-subject').value);
  164.       }
  165.       $('#kqr-subject').value = 'CJMT #' + $('#cjmt-num').value;
  166.     }, false);
  167.    
  168.     $('#cjmt-rest').addEventListener('click', function(){
  169.       $('#kqr-subject').value = $.getVal('rest', '');
  170.     }, false);
  171.    
  172.    
  173.    
  174.   }
  175.  
  176.   $.time(2000, initCJMT, false);
  177.  
  178. }
  179. cjmt();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement