Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name CJMT #
- // @namespace erin
- // @description Adds the new thread number!
- // @include *://8ch.net/lewd/*
- // @version 0.01
- // @grant none
- // ==/UserScript==
- function cjmt(){
- var d, db, h, $, $$, namespace;
- d = document;
- db = document.body;
- h = document.getElementsByTagName('head')[0];
- namespace = 'lewd';
- $ = 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);
- };
- $.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);
- }
- }
- };
- $.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;
- }
- }
- }
- };
- function initCJMT(){
- var $open = {};
- $open['id'] = 'cjmt-open';
- $open['style'] = 'cursor:pointer;';
- $open = $.elm('span', $open, $('.kqr-leftopts'));
- $open.innerHTML = '<a>[#]</a>';
- var $win = {};
- $win['id'] = 'cjmt-win';
- $win['style'] = 'display:none;text-align:center;';
- $win = $.elm('div', $win, $('#kqr'));
- $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>';
- $('#cjmt-set').innerHTML = '#' + (parseInt($.getVal('CJMT', '0'))+1);
- $open.addEventListener('click', function(){
- if($win.style.display == "none"){
- $win.style.display = "";
- }else{
- $win.style.display = "none";
- }
- }, false);
- $.each($$('.subject'), function(za, zi){
- if(za.innerHTML.indexOf('CJMT') > -1 && za.innerHTML.indexOf('#') > 0){
- var $pat = /[0-9]+/g;
- var $match = $pat.exec(za.innerHTML.split('#')[1]);
- console.log($match[0]);
- if($match[0] >= parseInt($.getVal('CJMT', '0'))){
- $.setVal('CJMT', $match[0]);
- $('#cjmt-set').innerHTML = '#' + (parseInt($match[0])+1);
- }
- }
- });
- $('#cjmt-set').addEventListener('click', function(){
- if($('#kqr-subject').value.indexOf('CJMT #') < 0){
- $.setVal('rest', $('#kqr-subject').value);
- }
- $('#kqr-subject').value = 'CJMT #' + (parseInt($.getVal('CJMT', '0'))+1);
- }, false);
- $('#cjmt-cust').addEventListener('click', function(){
- if($('#kqr-subject').value.indexOf('CJMT #') < 0){
- $.setVal('rest', $('#kqr-subject').value);
- }
- $('#kqr-subject').value = 'CJMT #' + $('#cjmt-num').value;
- }, false);
- $('#cjmt-rest').addEventListener('click', function(){
- $('#kqr-subject').value = $.getVal('rest', '');
- }, false);
- }
- $.time(2000, initCJMT, false);
- }
- cjmt();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement