var QRreplyButton;
var mydragg = function() {
return {
move: function(divid, xpos, ypos) {
divid.style.right = xpos + 'px';
divid.style.top = ypos + 'px';
},
startMoving: function(divid, container, evt) {
divid = document.getElementById('quick-reply');
evt = evt || window.event;
var posX = evt.clientX,
posY = evt.clientY,
divTop = divid.style.top,
divLeft = divid.style.right,
eWi = parseInt(divid.style.width),
eHe = parseInt(divid.style.height),
cWi = parseInt(document.getElementById(container).style.width),
cHe = parseInt(document.getElementById(container).style.height);
document.getElementById(container).style.cursor = 'move';
divTop = divTop.replace('px', '');
divLeft = divLeft.replace('px', '');
var diffX = (window.innerWidth - posX) - divLeft,
diffY = posY - divTop;
document.onmousemove = function(evt) {
evt = evt || window.event;
var posX = evt.clientX,
posY = evt.clientY,
aX = (window.innerWidth - posX) - diffX,
aY = posY - diffY;
if (aX < 0) aX = 0;
if (aY < 0) aY = 0;
if (aX + eWi > cWi) aX = cWi - eWi;
if (aY + eHe > cHe) aY = cHe - eHe;
mydragg.move(divid, aX, aY);
}
},
stopMoving: function(container) {
var a = document.createElement('script');
document.getElementById(container).style.cursor = 'default';
document.onmousemove = function() {}
},
}
}();
var toggle_qr_enabled = function () {
if(check_if_qr_enabled() == true) {
console.log('Disabling QR');
localStorage.setItem("disableqr", 'true');
} else {
console.log('Enabling QR');
localStorage.removeItem("disableqr");
}
}
var check_if_qr_enabled = function() {
// Check Localstorage
var loc = '';
loc = localStorage.getItem("disableqr");
if (loc != '' && loc != null) {
// Localstorage set
return false;
}
return true;
}
var should_show_qr = check_if_qr_enabled();
var add_quick_reply_quote = function(quote) {
if (typeof(window.show_quick_reply) == 'function'
&& window.should_show_qr ) {
window.show_quick_reply();
//if (typeof show_quick_reply != "undefined" && should_show_qr) {
//show_quick_reply();
} else {
return;
}
var qrBody=document.getElementById('qrbody');
if (qrBody==null) {
return;
}
/*
var selectedText=window.getSelection();
if (selectedText!='') {
document.getElementById('qrbody').value += '>' + selectedText + '\n';
}
*/
var textToAdd=">>"+quote+'\n'
+replace_reply_quote(window.getSelection().toString());
//console.log('textToAdd', textToAdd);
//document.getElementById('qrbody').value+='>>'+quote+'\n';
// make sure it ends with a newline
if (textToAdd[textToAdd.length-1]!=='\n') {
textToAdd=textToAdd+'\n';
}
var insertPos=0;
if (qrBody.selectionDirection==='forward') {
insertPos=qrBody.selectionEnd;
} else {
insertPos=qrBody.selectionStart;
}
// slice new text in
qrBody.value=qrBody.value.substring(0, insertPos)+textToAdd+
qrBody.value.substring(insertPos);
}
var replace_reply_quote = function( text ) {
var v = text.split('\n');
if ( 0 === v.length ) {
return text;
};
var idx = 0, len = v.length;
var q = ">";
if ( 0 === v[ v.length - 1 ].length ) {
len = len - 1; /* no quote empty line at the last. */
};
for (; idx < len ; ++idx ) {
if (null !== v[ idx ].match(/^(?:>>?[0-9]+|>>>?\/\w+\/\d*)/))
{ /* matches with starts with ">>50" , ">>>/cancer/" , ">>>/cancer/50" , ">50" , ">>/cancer/" , ">>/cancer/50" */
/* space is put so as to keeps link quoting format and non-link quoting format. */
q = "> ";
break;
};
};
for( idx = 0; idx < len ; ++idx ) {
v[ idx ] = q + v[ idx ];
};
return v.join('\n');
};
var show_quick_reply = function() {
var captcha = false;
var flags = false;
if (document.getElementById('quick-reply') !== null)
return;
if (document.getElementById('captchaDiv') !== null)
captcha = true;
if (document.getElementById('flagsDiv') !== null)
flags = true;
var QRshowname = document.getElementById('fieldName');
var boardName = document.getElementById('boardIdentifier').value;
var threadNum = document.getElementById('threadIdentifier').value;
var qrhtml = '
';
if (QRshowname) {
var qrhtml = qrhtml.concat(qrname);
}
var qrhtml = qrhtml.concat(qrmsg);
if (captcha) {
var qrhtml = qrhtml.concat(qrcaptcha);
}
var qrhtml = qrhtml.concat(closinghtml);
function appendHtml(el, str) {
var div = document.createElement('div');
div.innerHTML = str;
while (div.children.length > 0) {
el.appendChild(div.children[0]);
}
}
appendHtml(document.body, qrhtml);
if (flags) {
var div = document.getElementById('flagsDiv'),
clone = div.cloneNode(true); // true means clone all childNodes and all event handlers
clone.id = "QRflagsDiv";
document.getElementById('qrcheckboxSpoiler').appendChild(clone)
}
// Copy current vars
if (QRshowname) {
document.getElementById('qrname').value = document.getElementById('fieldName').value;
document.getElementById('fieldName').addEventListener('keyup', function(e) {
document.getElementById('qrname').value = document.getElementById('fieldName').value;
});
document.getElementById('qrname').addEventListener('keyup', function(e) {
document.getElementById('fieldName').value = document.getElementById('qrname').value;
});
}
document.getElementById('qremail').value = document.getElementById('fieldEmail').value;
document.getElementById('qrsubject').value = document.getElementById('fieldSubject').value;
document.getElementById('qrbody').value = document.getElementById('fieldMessage').value;
document.getElementById('qrpassword').value = document.getElementById('fieldPostingPassword').value;
document.getElementById('qrcheckboxSpoiler').checked = document.getElementById('checkboxSpoiler').checked;
// Sync it
document.getElementById('fieldEmail').addEventListener('keyup', function(e) {
document.getElementById('qremail').value = document.getElementById('fieldEmail').value;
});
document.getElementById('fieldSubject').addEventListener('keyup', function(e) {
document.getElementById('qrsubject').value = document.getElementById('fieldSubject').value;
});
document.getElementById('fieldMessage').addEventListener('change', function(e) {
document.getElementById('qrbody').value = document.getElementById('fieldMessage').value;
});
document.getElementById('fieldPostingPassword').addEventListener('keyup', function(e) {
document.getElementById('qrpassword').value = document.getElementById('fieldPostingPassword').value;
});
document.getElementById('checkboxSpoiler').addEventListener('change', function(e) {
document.getElementById('qrcheckboxSpoiler').checked = document.getElementById('checkboxSpoiler').checked;
});
if (captcha) {
// Copy current vars
document.getElementById('QRfieldCaptcha').value = document.getElementById('fieldCaptcha').value;
// Sync it
document.getElementById('fieldCaptcha').addEventListener('keyup', function(e) {
document.getElementById('QRfieldCaptcha').checked = document.getElementById('fieldCaptcha').checked;
});
// And the other way around
document.getElementById('QRfieldCaptcha').addEventListener('keyup', function(e) {
document.getElementById('fieldCaptcha').checked = document.getElementById('QRfieldCaptcha').checked;
});
}
if (flags) {
/* // Copy current vars
document.getElementById('QRfieldCaptcha').value = document.getElementById('fieldCaptcha').value;
// Sync it
document.getElementById('fieldCaptcha').addEventListener('keyup', function (e) {
document.getElementById('QRfieldCaptcha').checked = document.getElementById('fieldCaptcha').checked;
});
// And the other way around
document.getElementById('QRfieldCaptcha').addEventListener('keyup', function (e) {
document.getElementById('fieldCaptcha').checked = document.getElementById('QRfieldCaptcha').checked;
});*/
}
// And the other way around
document.getElementById('qremail').addEventListener('keyup', function(e) {
document.getElementById('fieldEmail').value = document.getElementById('qremail').value;
});
document.getElementById('qrsubject').addEventListener('keyup', function(e) {
document.getElementById('fieldSubject').value = document.getElementById('qrsubject').value;
});
document.getElementById('qrbody').addEventListener('keyup', function(e) {
document.getElementById('fieldMessage').value = document.getElementById('qrbody').value;
});
document.getElementById('qrpassword').addEventListener('keyup', function(e) {
document.getElementById('fieldPostingPassword').value = document.getElementById('qrpassword').value;
});
document.getElementById('qrcheckboxSpoiler').addEventListener('change', function(e) {
document.getElementById('checkboxSpoiler').checked = document.getElementById('qrcheckboxSpoiler').checked;
});
//Set QR reply button
QRreplyButton = document.getElementById('qrbutton');
setDragAndDrop(true);
for (var i = 0; i < selectedDiv.childNodes.length; i++) {
var originalCell = selectedDiv.childNodes[i];
var clonedCell = originalCell.cloneNode(true);
clonedCell.getElementsByClassName('removeButton')[0].onclick = originalCell.getElementsByClassName('removeButton')[0].onclick;
selectedDivQr.appendChild(clonedCell);
}
};
function QRreloadCaptcha() {
document.cookie = 'captchaid=; path=/;';
reloadCaptcha();
/*
if (document.getElementById('QRcaptchaDiv')) {
document.getElementById('QRcaptchaImage').src = '/captcha.js?d='
+ new Date().toString();
}
document.getElementById('captchaImageReport').src = '/captcha.js?d='
+ new Date().toString();
*/
}
var QRreplyCallback = function(status, data) {
//console.log('QRreplyCallback', status, data)
if (status === 'ok') {
var myPosts=getMyPosts()
//console.log('pushing data', data, 'onto', myPosts)
myPosts.push({ b: boardUri, p: data })
var days=365*10; // remember this settings for 10 years
setSetting('myPosts', JSON.stringify(myPosts), days)
clearSelectedFiles();
var elem
elem=document.getElementById('qrbody')
if (elem) elem.value = '';
elem=document.getElementById('fieldMessage')
if (elem) elem.value = '';
elem=document.getElementById('qrsubject')
if (elem) elem.value = '';
elem=document.getElementById('fieldSubject')
if (elem) elem.value = '';
QRreloadCaptcha();
setTimeout(function() {
refreshPosts();
}, 2000);
} else {
alert(status + ': ' + JSON.stringify(data));
}
};
QRreplyCallback.stop = function() {
replyButton.innerHTML = originalButtonText;
QRreplyButton.innerHTML = originalButtonText;
replyButton.disabled = false;
QRreplyButton.disabled = false;
if (!hiddenCaptcha) {
QRreloadCaptcha();
document.getElementById('fieldCaptcha').value = '';
document.getElementById('QRfieldCaptcha').value = '';
}
};
QRreplyCallback.progress = function(info) {
if (info.lengthComputable) {
var newText = 'Uploading ' + Math.floor((info.loaded / info.total) * 100)
+ '%';
replyButton.innerHTML = newText;
QRreplyButton.innerHTML = newText;
}
};
function QRsendReplyData(files, captchaId) {
var forcedAnon = !document.getElementById('qrname');
var hiddenFlags = !document.getElementById('QRflagsDiv');
var selectedFlag
if (!hiddenFlags) {
var combo = document.getElementById('flagCombobox');
// last50 has this element but it's not filled out
if (combo.options.length) {
selectedFlag = combo.options[combo.selectedIndex].value;
}
}
if (!forcedAnon) {
var typedName = document.getElementById('qrname').value.trim();
}
var typedEmail = document.getElementById('qremail').value.trim();
var typedMessage = document.getElementById('qrbody').value.trim();
var typedSubject = document.getElementById('qrsubject').value.trim();
var typedPassword = document.getElementById('qrpassword').value
.trim();
var threadId = document.getElementById('threadIdentifier').value;
if (!typedMessage.length && !files.length) {
alert('A message or a file is mandatory.');
return;
} else if (!forcedAnon && typedName.length > 32) {
alert('Name is too long, keep it under 32 characters.');
return;
} else if (typedMessage.length > 4096) {
alert('Message is too long, keep it under 4096 characters.');
return;
} else if (typedEmail.length > 64) {
alert('E-mail is too long, keep it under 64 characters.');
return;
} else if (typedSubject.length > 128) {
alert('Subject is too long, keep it under 128 characters.');
return;
} else if (typedPassword.length > 8) {
alert('Password is too long, keep it under 8 characters.');
return;
}
if (typedPassword.length) {
savePassword(typedPassword);
}
originalButtonText = replyButton.innerHTML;
replyButton.innerHTML = 'Uploading 0%';
QRreplyButton.innerHTML = 'Uploading 0%';
replyButton.disabled = true;
QRreplyButton.disabled = true;
console.log('files', files)
apiRequest('replyThread', {
name: forcedAnon ? null : typedName,
flag: hiddenFlags ? null : selectedFlag,
captcha: captchaId,
subject: typedSubject,
spoiler: document.getElementById('qrcheckboxSpoiler').checked,
password: typedPassword,
message: typedMessage,
email: typedEmail,
files: files,
boardUri: boardUri,
quickReply: true,
threadId: threadId
}, QRreplyCallback);
}
function QRprocessFilesToPost(captchaId) {
getFilestToUpload(function gotFiles(files) {
QRsendReplyData(files, captchaId);
});
}
function handleQR() {
//console.log("aborting form post")
//QRpostReply();
return false;
}
function QRpostReply() {
if (hiddenCaptcha) {
QRprocessFilesToPost();
} else {
var typedCaptcha = document.getElementById('QRfieldCaptcha').value.trim();
/*
if (typedCaptcha.length !== 6 && typedCaptcha.length !== 24) {
//alert('Captchas are exactly 6 (24 if no cookies) characters long.');
return;
} else if (/\W/.test(typedCaptcha)) {
alert('Invalid captcha.');
return;
}
*/
var parsedCookies = getCookies();
apiRequest('solveCaptcha', {
captchaId: parsedCookies.captchaid,
answer: typedCaptcha
}, function solvedCaptcha(status, data) {
QRprocessFilesToPost(parsedCookies.captchaid);
});
}
}