Advertisement
erinx

8chan Mobile 0.5

Dec 13th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mobile(){
  2.   var d, db, h, k, w;  
  3.  
  4.   d = document;
  5.   db = document.body;
  6.   h = document.getElementsByTagName('head')[0];
  7.  
  8.   w = window.location.href;
  9.   k = {};  
  10.   k.end = w.split('.net')[1];    
  11.   k.proto = window.location.protocol;
  12.   if(k.end.indexOf('mod.php?') > 0){
  13.     if(k.end.length > 3 && w.split('mod.php?/')[1].indexOf('/') > 0 && w.indexOf('/src/') < 1){
  14.       k.board = w.split('mod.php?/')[1].split('/')[0];
  15.     }else{
  16.       k.board = null;
  17.     }
  18.     if(w.indexOf('/res/') > 1){
  19.       k.thread = w.split('/res/')[1].split('+')[0].split('.')[0];
  20.     }else if(w.indexOf('catalog') > 2){
  21.       k.thread = 'catalog';
  22.     }else{
  23.       k.thread = 'mod';
  24.     }
  25.   }else{
  26.     if(k.end.length > 3 && w.split('8ch.net/')[1].indexOf('/') > 0 && w.indexOf('/src/') < 1){
  27.       k.board = w.split('8ch.net/')[1].split('/')[0];
  28.     }else{
  29.       k.board = null;
  30.     }
  31.     if(w.indexOf('/res/') > 1){
  32.       k.thread = w.split('/res/')[1].split('+')[0].split('.h')[0];
  33.     }else if(w.indexOf('catalog') > 2){
  34.       k.thread = 'catalog';
  35.     }else if(w.indexOf('index') > 2 || w.substring((w.length-1), w.length) == '/'){
  36.       k.thread = 'index';
  37.     }else{
  38.       k.thread = null;
  39.     }
  40.   }
  41.  
  42.   function q(s, p){
  43.     if(!p || p == null){
  44.       p = db;
  45.     }
  46.     return p.querySelector(s);
  47.   };
  48.  
  49.   function qq(s, p){
  50.     if(!p || p == null){
  51.       p = db;
  52.     }
  53.     return p.querySelectorAll(s);
  54.   };
  55.  
  56.   function getVal(k, v){
  57.     if(typeof(Storage) !=="undefined"){
  58.       if(v == null){
  59.         if(localStorage.getItem(namespace + "." + k) != null){
  60.           return localStorage.getItem(namespace  + "." + k);
  61.         }else{
  62.           return 'undefined';
  63.         }
  64.       }else{
  65.         if(localStorage.getItem("mobile." + k) != null){
  66.           return localStorage.getItem("mobile." + k);
  67.         }else{
  68.           return v;
  69.         }
  70.       }
  71.     }else{
  72.       return 'storage unavailable';
  73.     }
  74.   };
  75.  
  76.   function setVal(k, v){
  77.     if(typeof(Storage) !=="undefined"){
  78.       if(v == null){
  79.         return 'undefined';
  80.       }else{
  81.         return localStorage.setItem("mobile." + k, v);
  82.       }
  83.     }else{
  84.       return 'storage unavailable';
  85.     }
  86.   };
  87.  
  88.   function delVal(k){
  89.     return localStorage.removeItem("mobile." + k);
  90.   };  
  91.  
  92.   function elm(t, a, s){
  93.     var e = d.createElement(t);
  94.     if(a){
  95.       for (key in a){
  96.         e.setAttribute(key, a[key]);
  97.       }
  98.     }
  99.     if(s){
  100.       s.appendChild(e);
  101.     }
  102.     return e;
  103.   };
  104.  
  105.   function htm(s, v){
  106.     if(v == null){
  107.       return s.innerHTML;
  108.     }else{
  109.       s.innerHTML = v;
  110.     }
  111.     return s;
  112.   };
  113.  
  114.  function destroy(s){
  115.     return s.parentNode.removeChild(s);
  116.   };
  117.  
  118.   function doThese(a, c, e){
  119.     for(var i = 0; i < a.length; i++){
  120.       c(a[i], i);
  121.       if(i == (a.length)-1){
  122.         if(e && e != null){
  123.           return e(a[i], i);
  124.         }else{
  125.           return a;
  126.         }
  127.       }
  128.     }
  129.   };
  130.  
  131.   function doJson(s){
  132.     if(typeof s == 'string'){
  133.       return JSON.parse(s);
  134.     }else{
  135.       return JSON.stringify(s);
  136.     }
  137.   };
  138.  
  139.   function spawnEvent(t, i, s){
  140.     if (i == null) {
  141.       i = {};
  142.     }
  143.     if (s == null) {
  144.       s = d;
  145.     }
  146.     return s.dispatchEvent(new CustomEvent(t, i));
  147.   };
  148.  
  149.   function addCss(s){
  150.     var e = d.createElement('style');
  151.     e.type = 'text/css';
  152.     if (e.styleSheet){
  153.       e.styleSheet.cssText = s;
  154.     } else {
  155.       e.appendChild(d.createTextNode(s));
  156.     }
  157.     h.appendChild(e);
  158.     return e;
  159.   };
  160.  
  161.   function thisAtt(s, a, v){
  162.     if (!v || v == null || v == false) {
  163.       if (v == false) {
  164.         return s.removeAttribute(a);
  165.       }else{
  166.         return s.getAttribute(a);
  167.       }
  168.     }else{
  169.       s.setAttribute(a, v);
  170.       return s;
  171.     }
  172.   };
  173.  
  174.   function setTick(t, c, l){
  175.     if(c == false){
  176.       return clearInterval(t);
  177.     }else{
  178.       if(l == true){
  179.         return setInterval(function(){
  180.           c();
  181.         },t);
  182.       }else{
  183.         return setTimeout(function(){
  184.           c();
  185.         },t);
  186.       }
  187.     }
  188.   };
  189.  
  190.   function putNext(e, s){
  191.     s.parentNode.insertBefore(e, s.nextSibling);
  192.     return e;
  193.   };
  194.  
  195.  
  196.  
  197.   function buildMobile(){
  198.    
  199.     var mobileCSS = addCss('body{ padding-bottom:100px !important; padding-left:0px !important;padding-right:0px !important;margin-left:0px !important;margin-right:0px !important; } .reply{ width:98% !important; } .board_image{ display:none !important; }');
  200.    
  201.     var mobileMeta = {};
  202.     mobileMeta['name'] = 'viewport';
  203.     mobileMeta['content'] = 'width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi';
  204.     mobileMeta = elm('meta', mobileMeta, h);
  205.    
  206.  
  207.  
  208. var statusInit = 0;
  209.  
  210. if(statusInit == 1){
  211.  
  212. var statusBoard = {};
  213. statusBoard['id'] = "statusBoard";
  214. statusBoard['style'] = 'position:fixed;top:7px;left:1px;width:99%;background:#d6daf0;border:1px solid;max-height:75px;overflow-y:scroll;';
  215. statusBoard = elm('div', statusBoard, db);
  216.  
  217. document.onscroll = function(){
  218. if(db.scrollTop < 100){
  219. statusBoard.style.display = 'none';
  220. }else{
  221. statusBoard.style.display = '';
  222. }
  223.  
  224. };
  225.  
  226. }
  227.  
  228.     var postForm = {};
  229.     postForm['id'] = 'mobileQR';
  230.     postForm['style'] = 'position:fixed;bottom:0px;left:1px;width:99%;background:#d6daf0;border:1px solid;color:black';
  231.     postForm = elm('div', postForm, db);
  232.    
  233.     var persona = '<div id="mobile-persona" style="display:inline-block;width:96%;">\
  234.    <input id="mobile-name" style="width:100%;" placeholder="Name"><br>\
  235.    <input id="mobile-email" style="width:100%;" placeholder="Email"><br>\
  236.    <input id="mobile-subject" style="width:100%;" placeholder="Subject">\
  237.    </div>';
  238.    
  239.     var comment = '<div style="display:inline-block;width:69%;">\
  240.    <textarea id="mobile-comment" placeholder="comment" style="width:100%;height:70px;margin:0px;padding:0px;margin-top:0px;margin-bottom: -15px ! important;padding:0px !important;"></textarea>\
  241.    </div>';
  242.    
  243.     var controls = '<div id="mobile-buttons" style="display:inline-block;width:18%;margin-left:5px;margin-top:0px;margin-bottom:0px;padding:0px !important;">\
  244.    <div id="mobile-faux-file" style="width:100%;height:32px;background:#b7c5d9;margin:2px;text-align:center;border-radius:3px;border:1px solid;"><span style="line-height:30px;"></span><div id="faux-file-tag" class="fauxButton">File</div></div><span id="mobile-file-container"><input type="file" id="mobile-file" style="display:none;"></span>\
  245.    <div id="mobile-submit" style="width:100%;height:32px;background:#b7c5d9;margin:2px;text-align:center;border-radius:3px;border:1px solid;"><span style="line-height:30px;"></span><div id="faux-post-tag" class="fauxButton">Post</div></div>\
  246.    </div>';
  247.    
  248.     var menuButtonInp = '<div style="display:inline-block;width:8%;margin-left:5px;"><div id="mobile-menu-button" style="width:100%;height:68px;background:#b7c5d9;margin:2px;text-align:center;border-radius:3px;border:1px solid;"><span style="line-height:102px;"></span><div id="faux-menu-tag" class="fauxButton" style="margin-top:-32px;">+</div></div></div>';
  249.    
  250.     var formCSS = addCss('.fauxButton{vertical-align:middle;display:inline-block;border-color: black;color:black;}');
  251.    
  252.     postForm.innerHTML = persona + comment + controls + menuButtonInp;
  253.    
  254.     q('#mobile-persona').style.display = 'none';
  255.    
  256.     q('#mobile-faux-file').addEventListener('click', function(){
  257.       spawnEvent('click', {}, q('#mobile-file'));
  258.     }, false);
  259.    
  260.     q('#mobile-file').addEventListener('change', function(){
  261.       var fileName = q('#mobile-file').value.split('\\')[q('#mobile-file').value.split('\\').length - 1];
  262.       q('#faux-file-tag').innerHTML = fileName.substring(0, 10) + '...';
  263.     }, false);
  264.    
  265.     function flipMenu(){
  266.       if(q('#mobile-persona').style.display == 'none'){
  267.        q('#mobile-persona').style.display = '';
  268.       }else{
  269.        q('#mobile-persona').style.display = 'none';
  270.       }
  271.     }
  272.    
  273.     q('#mobile-menu-button').addEventListener('click', function(){
  274.       flipMenu();
  275.     }, false);
  276.    
  277.    
  278.     function buttonText(tx){
  279.       if(tx == 'post'){
  280.         q('#faux-post-tag').innerHTML = 'Posting';
  281.       }else if(tx == 'fail'){
  282.         q('#faux-post-tag').innerHTML = 'Retry';
  283.       }else{
  284.         q('#faux-post-tag').innerHTML = 'Post';
  285.       }    
  286.     }
  287.    
  288.     var ownData = getVal('own', 'false');
  289.    
  290.     if(ownData != 'false'){
  291.       var ownPosts = doJson(ownData);
  292.     }else{
  293.       var ownPosts = doJson('[]');
  294.     }
  295.    
  296.    
  297.    
  298.     function submitPost(){
  299.       buttonText('post');
  300.       var formData = new FormData();  
  301.       formData.append('json_response', '0');
  302.       formData.append('post', q('input[type="submit"]', q('form[name="post"]')).value);
  303.       formData.append("board", k.board);
  304.       if(k.thread != 'index' && k.thread != 'catalog'  && k.thread != 'mod'){
  305.         formData.append("thread", k.thread);
  306.       }
  307.       formData.append("name", q('#mobile-name').value);
  308.       formData.append("email", q('#mobile-email').value);
  309.       formData.append("subject", q('#mobile-subject').value);
  310.       formData.append("file", q("#mobile-file").files[0]);
  311.       formData.append("body", q('#mobile-comment').value);
  312.      
  313.       var xhr = new XMLHttpRequest();
  314.  
  315.       xhr.open("POST", k.proto + '//sys.8ch.net/post.php');
  316.    
  317.       xhr.onreadystatechange = function(){
  318. if(statusInit == 1){statusBoard.innerHTML = xhr.readyState + '...';}
  319.         if(xhr.readyState == 4){
  320.           var re = doJson(xhr.responseText.replace('true|', '"true,",').replace('false|', '"false,",'));
  321.           var reb = doJson(xhr.responseText.replace('true|', '"true",').replace('false|', '"false",'));
  322.           if(statusInit == 1){ statusBoard.innerHTML = xhr.status + ': ' + xhr.responseText; }
  323.           if(re.hasOwnProperty('error') || reb.hasOwnProperty('captcha')){  
  324.             if(reb['captcha'] == 'true'){
  325.               alert('Please <a href="https://8ch.net/dnsbls_bypass.php" target="_blank">click here</a> to fill out a captcha.');
  326.               buttonText('fail');
  327.             }else if(re['error']){
  328.               alert(re['error']);
  329.               buttonText('fail');
  330.             }else{
  331.               alert('There was an error posting.');
  332.               buttonText('fail');
  333.             }
  334.           }else{
  335.             ownPosts.push(re['id']);
  336.             var newPosts = doJson(ownPosts);
  337.             setVal('own', newPosts);
  338.             q('#mobile-comment').value = '';
  339.             buttonText();
  340.             q('#mobile-file-container').innerHTML = '<input type="file" id="mobile-file" style="display:none;">';
  341.             q('#faux-file-tag').innerHTML = 'File';
  342.           }
  343.            
  344.            
  345.         }
  346.        
  347.       }
  348.      
  349.      
  350.       function updateProgress(e){
  351.         if (e.lengthComputable){
  352.           var percentComplete = parseInt((e.loaded / e.total)*100).toFixed(0);
  353.           if(percentComplete > 100) percentComplete = 100;
  354.           q('#faux-post-tag').innerHTML = percentComplete + '%';
  355.         }
  356.       }
  357.      
  358.       xhr.upload.addEventListener("progress", updateProgress, false);
  359.      
  360.       xhr.send(formData);
  361.    
  362.     }
  363.    
  364.    
  365.    
  366.     function parseQuotes(){
  367.       doThese(qq('.post_no'), function(xe, xi){
  368.         if(xe.innerHTML != 'No.'){
  369.           if(thisAtt(xe, 'data-mobile') != 'passed'){
  370.             thisAtt(xe, 'data-mobile', 'passed');
  371.             xe.addEventListener('click', function(e){
  372.               e.preventDefault();
  373.               e.stopPropagation();              
  374.               q('#mobile-comment').value += '>>' + xe.innerHTML + '\n';
  375.               q('#mobile-comment').focus();
  376.             }, false);
  377.           }
  378.         }
  379.       });
  380.       doThese(qq('.body'), function(ze, zi){
  381.         doThese(qq('a', ze), function(ye, yi){
  382.           if(ye.innerHTML.indexOf('&gt;&gt;') == 0){
  383.             var postNum = ye.innerHTML.split('&gt;&gt;')[1];
  384.             if(ownPosts.indexOf(postNum) > -1 && ye.innerHTML.indexOf('(You)') < 0){
  385.               ye.innerHTML += ' (You)';
  386.             }
  387.           }
  388.         });
  389.       });
  390.     }
  391.    
  392.    
  393.    
  394.     q('#mobile-name').onfocus = function(e){
  395.       window.scrollTo(0, (db.scrollTop-30));
  396.       postForm.style.position = 'absolute';
  397.       postForm.style.bottom = '';
  398.       postForm.style.top = (db.scrollTop+100) + 'px';
  399.     }
  400.    
  401.     q('#mobile-email').onfocus = function(e){
  402.       window.scrollTo(0, (db.scrollTop-30));
  403.       postForm.style.position = 'absolute';
  404.       postForm.style.bottom = '';
  405.       postForm.style.top = (db.scrollTop+100) + 'px';
  406.     }
  407.    
  408.     q('#mobile-subject').onfocus = function(e){
  409.       window.scrollTo(0, (db.scrollTop-30));
  410.       postForm.style.position = 'absolute';
  411.       postForm.style.bottom = '';
  412.       postForm.style.top = (db.scrollTop+100) + 'px';
  413.     }
  414.    
  415.     q('#mobile-comment').onfocus = function(e){
  416.       window.scrollTo(0, (db.scrollTop-30));
  417.       postForm.style.position = 'absolute';
  418.       postForm.style.bottom = '';
  419.       postForm.style.top = (db.scrollTop+100) + 'px';
  420.     }
  421.    
  422.     q('#mobile-file').onfocus = function(e){
  423.       window.scrollTo(0, (db.scrollTop-30));
  424.       postForm.style.position = 'absolute';
  425.       postForm.style.bottom = '';
  426.       postForm.style.top = (db.scrollTop+100) + 'px';
  427.     }
  428.    
  429.     q('#mobile-name').onblur = function(e){
  430.       postForm.style.position = 'fixed';
  431.       postForm.style.bottom = '0px';
  432.       postForm.style.top = '';
  433.       putNext(postForm, q('bottom'));
  434.  
  435.     }
  436.    
  437.     q('#mobile-email').onblur = function(e){
  438.       postForm.style.position = 'fixed';
  439.       postForm.style.bottom = '0px';
  440.       postForm.style.top = '';
  441. putNext(postForm, q('bottom'));
  442.  
  443.     }
  444.    
  445.     q('#mobile-subject').onblur = function(e){
  446.       postForm.style.position = 'fixed';
  447.       postForm.style.bottom = '0px';
  448.       postForm.style.top = '';
  449.       putNext(postForm, q('bottom'));
  450.  
  451.     }
  452.    
  453.     q('#mobile-comment').onblur = function(e){
  454.       postForm.style.position = 'fixed';
  455.       postForm.style.bottom = '0px';
  456.       postForm.style.top = '';
  457.       putNext(postForm, q('bottom'));
  458.     }
  459.    
  460.     q('#mobile-file').onblur = function(e){
  461.       postForm.style.position = 'fixed';
  462.       postForm.style.bottom = '0px';
  463.       postForm.style.top = '';
  464.       putNext(postForm, q('bottom'));
  465.     }
  466.    
  467.    
  468.     q('#mobile-name').addEventListener('input', function(){
  469.       setVal('name', q('#mobile-name').value);
  470.     }, false);
  471.    
  472.     q('#mobile-email').addEventListener('input', function(){
  473.       setVal('email', q('#mobile-email').value);
  474.     }, false);
  475.    
  476.     q('#mobile-subject').addEventListener('input', function(){
  477.       setVal('subject', q('#mobile-subject').value);
  478.     }, false);
  479.    
  480.     q('#mobile-name').value = getVal('name', '');
  481.     q('#mobile-email').value = getVal('email', '');
  482.     q('#mobile-subject').value = getVal('subject', '');
  483.    
  484.    
  485.     q('#mobile-submit').addEventListener('click', submitPost, false);
  486.    
  487.     setTick(3000, function(){
  488.       parseQuotes();
  489.     }, true);
  490.    
  491.   }
  492.   buildMobile();
  493.  
  494. }
  495. mobile();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement