// ==UserScript==
// @name Yamibo Forum Batch Reply
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author cleoreo
// @grant none
// @require http://code.jquery.com/jquery-3.3.1.min.js
// @include https://bbs.yamibo.com/*
// @include http://bbs.yamibo.com/*
// @downloadURL none
// ==/UserScript==
$.noConflict();
/* Add Image overflow fixing CSS */
jQuery(document).ready(function(){
jQuery ('head').append("");
jQuery ('head').append("");
});
function addCheckbox(){
var commentDivs = jQuery('#postlist >div[id^="post_"]');
var commentHeaders = jQuery('#postlist >div[id^="post_"] .plc >.pi >strong');
// append checkbox
commentHeaders.each(function(index){
//console.log(this);
var commentId = jQuery(this).closest('div[id^="post_"]').attr('id');
jQuery(this).append('');
});
}
function openReplyPageInNewTab(){
var forumUrl = "https://bbs.yamibo.com/";
var replyUrl = forumUrl + jQuery('#post_replytmp').attr('onclick').split(',')[1].split('\'')[1];
localStorage.setItem("quotedComment", getAllQuoteComments());
window.open(replyUrl, '_blank');
}
function copyAllQuoteComments(){
window.prompt("請按 Ctrl+C 以複製引用", getAllQuoteComments());
}
function getAllQuoteComments(){
var checkedBox = jQuery('.batch-reply-checkbox:checked');
var allQuoteComment = "";
checkedBox.each(function(){
allQuoteComment += formatQuoteComment(jQuery(this).val());
});
return allQuoteComment;
}
function formatQuoteComment(commentId){
var commentDiv = jQuery('#postlist >div[id="' + commentId + '"]');
var commentUrl = commentDiv.find('.plc >.pi >strong >a').attr('href').split("&fromuid")[0];
// console.log(commentUrl);
var commentAuthor = commentDiv.find('.favatar .authi >a').text();
// console.log(commentAuthor);
var commentTime = commentDiv.find('.plc .authi em').text();
// console.log(commentTime);
var commentTextHtml = commentDiv.find('.plc td[id^="postmessage_"]').parent().html();
commentTextHtml = jQuery(commentTextHtml).find('i').remove().end();
var commentText = jQuery(commentTextHtml).find('div').remove().end().text();
commentText = jQuery.trim(commentText).substr(0, 50);
commentText = jQuery.trim(commentText) + '...';
// console.log(commentText);
var quotedComment = "[quote][size=2]";
quotedComment += "[url=" + commentUrl + "]";
quotedComment += "[color=#999999]" + commentAuthor + " " + commentTime + "[/color][/url][/size]\n";
quotedComment += commentText;
quotedComment += "[/quote] \n\n\n";
return quotedComment;
}
function getUrlParameter(sParam) {
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : sParameterName[1];
}
}
}
jQuery(document).ready(function(){
var postHeader = jQuery('#postlist >table').first().find('td:last-of-type .y').first();
if(postHeader.length > 0){
postHeader.prepend("");
addCheckbox();
jQuery('#select-all-comment').click(function(){
jQuery('.batch-reply-checkbox').prop('checked', true);
});
var paginationDiv = jQuery('#modactions').next('div');
paginationDiv.append("");
paginationDiv.append("");
jQuery('#batch-reply').click(function(){
openReplyPageInNewTab();
});
jQuery('#copy-reply').click(function(){
copyAllQuoteComments();
});
}
if (jQuery('#editorbox').length > 0 && getUrlParameter('action') == 'reply' && localStorage.getItem('quotedComment').length > 0) {
newEditor(1, bbcode2html(localStorage.getItem('quotedComment')));
localStorage.removeItem('quotedComment');
}
});