Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mobile(){
- var d, db, h, k, w;
- d = document;
- db = document.body;
- h = document.getElementsByTagName('head')[0];
- w = window.location.href;
- k = {};
- k.end = w.split('.net')[1];
- k.proto = window.location.protocol;
- if(k.end.indexOf('mod.php?') > 0){
- if(k.end.length > 3 && w.split('mod.php?/')[1].indexOf('/') > 0 && w.indexOf('/src/') < 1){
- k.board = w.split('mod.php?/')[1].split('/')[0];
- }else{
- k.board = null;
- }
- if(w.indexOf('/res/') > 1){
- k.thread = w.split('/res/')[1].split('+')[0].split('.')[0];
- }else if(w.indexOf('catalog') > 2){
- k.thread = 'catalog';
- }else{
- k.thread = 'mod';
- }
- }else{
- if(k.end.length > 3 && w.split('8ch.net/')[1].indexOf('/') > 0 && w.indexOf('/src/') < 1){
- k.board = w.split('8ch.net/')[1].split('/')[0];
- }else{
- k.board = null;
- }
- if(w.indexOf('/res/') > 1){
- k.thread = w.split('/res/')[1].split('+')[0].split('.h')[0];
- }else if(w.indexOf('catalog') > 2){
- k.thread = 'catalog';
- }else if(w.indexOf('index') > 2 || w.substring((w.length-1), w.length) == '/'){
- k.thread = 'index';
- }else{
- k.thread = null;
- }
- }
- function q(s, p){
- if(!p || p == null){
- p = db;
- }
- return p.querySelector(s);
- };
- function qq(s, p){
- if(!p || p == null){
- p = db;
- }
- return p.querySelectorAll(s);
- };
- function getVal(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("mobile." + k) != null){
- return localStorage.getItem("mobile." + k);
- }else{
- return v;
- }
- }
- }else{
- return 'storage unavailable';
- }
- };
- function setVal(k, v){
- if(typeof(Storage) !=="undefined"){
- if(v == null){
- return 'undefined';
- }else{
- return localStorage.setItem("mobile." + k, v);
- }
- }else{
- return 'storage unavailable';
- }
- };
- function delVal(k){
- return localStorage.removeItem("mobile." + k);
- };
- function elm(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;
- };
- function doThese(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 doJson(s){
- if(typeof s == 'string'){
- return JSON.parse(s);
- }else{
- return JSON.stringify(s);
- }
- };
- function spawnEvent(t, i, s){
- if (i == null) {
- i = {};
- }
- if (s == null) {
- s = d;
- }
- return s.dispatchEvent(new CustomEvent(t, i));
- };
- function addCss(s){
- var e = d.createElement('style');
- e.type = 'text/css';
- if (e.styleSheet){
- e.styleSheet.cssText = s;
- } else {
- e.appendChild(d.createTextNode(s));
- }
- h.appendChild(e);
- return e;
- };
- function thisAtt(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;
- }
- };
- function setTick(t, c, l){
- if(c == false){
- return clearInterval(t);
- }else{
- if(l == true){
- return setInterval(function(){
- c();
- },t);
- }else{
- return setTimeout(function(){
- c();
- },t);
- }
- }
- };
- function putNext(e, s){
- s.parentNode.insertBefore(e, s.nextSibling);
- return e;
- };
- function buildMobile(){
- 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; }');
- var mobileMeta = {};
- mobileMeta['name'] = 'viewport';
- mobileMeta['content'] = 'width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, target-densityDpi=device-dpi';
- mobileMeta = elm('meta', mobileMeta, h);
- var statusInit = 0;
- if(statusInit == 1){
- var statusBoard = {};
- statusBoard['id'] = "statusBoard";
- statusBoard['style'] = 'position:fixed;top:7px;left:1px;width:99%;background:#d6daf0;border:1px solid;max-height:75px;overflow-y:scroll;';
- statusBoard = elm('div', statusBoard, db);
- document.onscroll = function(){
- if(db.scrollTop < 100){
- statusBoard.style.display = 'none';
- }else{
- statusBoard.style.display = '';
- }
- };
- }
- var postForm = {};
- postForm['id'] = 'mobileQR';
- postForm['style'] = 'position:fixed;bottom:0px;left:1px;width:99%;background:#d6daf0;border:1px solid;color:black';
- postForm = elm('div', postForm, db);
- var persona = '<div id="mobile-persona" style="display:inline-block;width:96%;">\
- <input id="mobile-name" style="width:100%;" placeholder="Name"><br>\
- <input id="mobile-email" style="width:100%;" placeholder="Email"><br>\
- <input id="mobile-subject" style="width:100%;" placeholder="Subject">\
- </div>';
- var comment = '<div style="display:inline-block;width:69%;">\
- <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>\
- </div>';
- var controls = '<div id="mobile-buttons" style="display:inline-block;width:18%;margin-left:5px;margin-top:0px;margin-bottom:0px;padding:0px !important;">\
- <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>\
- <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>\
- </div>';
- 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>';
- var formCSS = addCss('.fauxButton{vertical-align:middle;display:inline-block;border-color: black;color:black;}');
- postForm.innerHTML = persona + comment + controls + menuButtonInp;
- q('#mobile-persona').style.display = 'none';
- q('#mobile-faux-file').addEventListener('click', function(){
- spawnEvent('click', {}, q('#mobile-file'));
- }, false);
- q('#mobile-file').addEventListener('change', function(){
- var fileName = q('#mobile-file').value.split('\\')[q('#mobile-file').value.split('\\').length - 1];
- q('#faux-file-tag').innerHTML = fileName.substring(0, 10) + '...';
- }, false);
- function flipMenu(){
- if(q('#mobile-persona').style.display == 'none'){
- q('#mobile-persona').style.display = '';
- }else{
- q('#mobile-persona').style.display = 'none';
- }
- }
- q('#mobile-menu-button').addEventListener('click', function(){
- flipMenu();
- }, false);
- function buttonText(tx){
- if(tx == 'post'){
- q('#faux-post-tag').innerHTML = 'Posting';
- }else if(tx == 'fail'){
- q('#faux-post-tag').innerHTML = 'Retry';
- }else{
- q('#faux-post-tag').innerHTML = 'Post';
- }
- }
- var ownData = getVal('own', 'false');
- if(ownData != 'false'){
- var ownPosts = doJson(ownData);
- }else{
- var ownPosts = doJson('[]');
- }
- function submitPost(){
- buttonText('post');
- var formData = new FormData();
- formData.append('json_response', '0');
- formData.append('post', q('input[type="submit"]', q('form[name="post"]')).value);
- formData.append("board", k.board);
- if(k.thread != 'index' && k.thread != 'catalog' && k.thread != 'mod'){
- formData.append("thread", k.thread);
- }
- formData.append("name", q('#mobile-name').value);
- formData.append("email", q('#mobile-email').value);
- formData.append("subject", q('#mobile-subject').value);
- formData.append("file", q("#mobile-file").files[0]);
- formData.append("body", q('#mobile-comment').value);
- var xhr = new XMLHttpRequest();
- xhr.open("POST", k.proto + '//sys.8ch.net/post.php');
- xhr.onreadystatechange = function(){
- if(statusInit == 1){statusBoard.innerHTML = xhr.readyState + '...';}
- if(xhr.readyState == 4){
- var re = doJson(xhr.responseText);
- if(statusInit == 1){ statusBoard.innerHTML = xhr.status + ': ' + xhr.responseText; }
- if(re.hasOwnProperty('error')){
- alert(re['error']);
- buttonText('fail');
- }else{
- ownPosts.push(re['id']);
- var newPosts = doJson(ownPosts);
- setVal('own', newPosts);
- q('#mobile-comment').value = '';
- buttonText();
- q('#mobile-file-container').innerHTML = '<input type="file" id="mobile-file" style="display:none;">';
- q('#faux-file-tag').innerHTML = 'File';
- }
- }
- }
- function updateProgress(e){
- if (e.lengthComputable){
- var percentComplete = parseInt((e.loaded / e.total)*100).toFixed(0);
- if(percentComplete > 100) percentComplete = 100;
- q('#faux-post-tag').innerHTML = percentComplete + '%';
- }
- }
- xhr.upload.addEventListener("progress", updateProgress, false);
- xhr.send(formData);
- }
- function parseQuotes(){
- doThese(qq('.post_no'), function(xe, xi){
- if(xe.innerHTML != 'No.'){
- if(thisAtt(xe, 'data-mobile') != 'passed'){
- thisAtt(xe, 'data-mobile', 'passed');
- xe.addEventListener('click', function(e){
- e.preventDefault();
- e.stopPropagation();
- q('#mobile-comment').value += '>>' + xe.innerHTML + '\n';
- q('#mobile-comment').focus();
- }, false);
- }
- }
- });
- doThese(qq('.body'), function(ze, zi){
- doThese(qq('a', ze), function(ye, yi){
- if(ye.innerHTML.indexOf('>>') == 0){
- var postNum = ye.innerHTML.split('>>')[1];
- if(ownPosts.indexOf(postNum) > -1 && ye.innerHTML.indexOf('(You)') < 0){
- ye.innerHTML += ' (You)';
- }
- }
- });
- });
- }
- q('#mobile-name').onfocus = function(e){
- window.scrollTo(0, (db.scrollTop-30));
- postForm.style.position = 'absolute';
- postForm.style.bottom = '';
- postForm.style.top = (db.scrollTop+100) + 'px';
- }
- q('#mobile-email').onfocus = function(e){
- window.scrollTo(0, (db.scrollTop-30));
- postForm.style.position = 'absolute';
- postForm.style.bottom = '';
- postForm.style.top = (db.scrollTop+100) + 'px';
- }
- q('#mobile-subject').onfocus = function(e){
- window.scrollTo(0, (db.scrollTop-30));
- postForm.style.position = 'absolute';
- postForm.style.bottom = '';
- postForm.style.top = (db.scrollTop+100) + 'px';
- }
- q('#mobile-comment').onfocus = function(e){
- window.scrollTo(0, (db.scrollTop-30));
- postForm.style.position = 'absolute';
- postForm.style.bottom = '';
- postForm.style.top = (db.scrollTop+100) + 'px';
- }
- q('#mobile-file').onfocus = function(e){
- window.scrollTo(0, (db.scrollTop-30));
- postForm.style.position = 'absolute';
- postForm.style.bottom = '';
- postForm.style.top = (db.scrollTop+100) + 'px';
- }
- q('#mobile-name').onblur = function(e){
- postForm.style.position = 'fixed';
- postForm.style.bottom = '0px';
- postForm.style.top = '';
- putNext(postForm, q('bottom'));
- }
- q('#mobile-email').onblur = function(e){
- postForm.style.position = 'fixed';
- postForm.style.bottom = '0px';
- postForm.style.top = '';
- putNext(postForm, q('bottom'));
- }
- q('#mobile-subject').onblur = function(e){
- postForm.style.position = 'fixed';
- postForm.style.bottom = '0px';
- postForm.style.top = '';
- putNext(postForm, q('bottom'));
- }
- q('#mobile-comment').onblur = function(e){
- postForm.style.position = 'fixed';
- postForm.style.bottom = '0px';
- postForm.style.top = '';
- putNext(postForm, q('bottom'));
- }
- q('#mobile-file').onblur = function(e){
- postForm.style.position = 'fixed';
- postForm.style.bottom = '0px';
- postForm.style.top = '';
- putNext(postForm, q('bottom'));
- }
- q('#mobile-name').addEventListener('input', function(){
- setVal('name', q('#mobile-name').value);
- }, false);
- q('#mobile-email').addEventListener('input', function(){
- setVal('email', q('#mobile-email').value);
- }, false);
- q('#mobile-subject').addEventListener('input', function(){
- setVal('subject', q('#mobile-subject').value);
- }, false);
- q('#mobile-name').value = getVal('name', '');
- q('#mobile-email').value = getVal('email', '');
- q('#mobile-subject').value = getVal('subject', '');
- q('#mobile-submit').addEventListener('click', submitPost, false);
- setTick(3000, function(){
- parseQuotes();
- }, true);
- }
- buildMobile();
- }
- mobile();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement