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 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 postForm = {};
postForm['id'] = 'mobileQR';
postForm['style'] = 'position:fixed;bottom:0px;left:1px;width:99%;background:#d6daf0;border:1px solid;';
postForm = elm('div', postForm, db);
var persona = '
\
\
\
\
';
var comment = '\
\
';
var controls = '';
var menuButtonInp = '';
var formCSS = addCss('.fauxButton{vertical-align:middle;display:inline-block;}');
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 + '//8ch.net/post.php');
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
var re = doJson(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 = '';
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+100));
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+100));
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+100));
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+100));
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+100));
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 = '';
}
q('#mobile-email').onblur = function(e){
postForm.style.position = 'fixed';
postForm.style.bottom = '0px';
postForm.style.top = '';
}
q('#mobile-subject').onblur = function(e){
postForm.style.position = 'fixed';
postForm.style.bottom = '0px';
postForm.style.top = '';
}
q('#mobile-comment').onblur = function(e){
postForm.style.position = 'fixed';
postForm.style.bottom = '0px';
postForm.style.top = '';
}
q('#mobile-file').onblur = function(e){
postForm.style.position = 'fixed';
postForm.style.bottom = '0px';
postForm.style.top = '';
}
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();