Yamibo Forum Batch Reply

try to take over the world!

目前為 2018-05-08 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Yamibo Forum Batch Reply
// @version      0.5
// @description  try to take over the world!
// @author       cleoreo
// @grant        none
// @license      MIT
// @require      http://code.jquery.com/jquery-3.3.1.min.js
// @include      https://bbs.yamibo.com/*
// @include      http://bbs.yamibo.com/*
// @namespace http://tampermonkey.net/
// ==/UserScript==

$.noConflict();
/* Add Image overflow fixing CSS */
jQuery(document).ready(function(){
    jQuery ('head').append("<style>img { max-width: 100% !important; }</style>");
    jQuery ('head').append("<style>.batch-reply-checkbox { float: right; } #batch-reply, #copy-reply { float: left; border-radius: 20px; border: 3px solid white; padding: 3px 10px; margin-top: 8px; height: auto; }</style>");
});


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('<input class="batch-reply-checkbox" type="checkbox" value="'+ commentId +'"/>');
    });
}

function openReplyPageInNewTab(){
    var forumUrl = "https://bbs.yamibo.com/";
    var replyUrl = forumUrl + jQuery('#post_replytmp').attr('onclick').split(',')[1].split('\'')[1];

    var allQuoteComment = getAllQuoteComments();
    if (allQuoteComment != false) {
        localStorage.setItem("quotedComment", allQuoteComment);
        window.open(replyUrl, '_blank');
    }

}

function copyAllQuoteComments(){
    var allQuoteComment = getAllQuoteComments();
    if (allQuoteComment != false) {
        window.prompt("請按 Ctrl+C 以複製引用", allQuoteComment);
    }
}

function getAllQuoteComments(){
    var checkedBox = jQuery('.batch-reply-checkbox:checked');

    if (checkedBox.length == 0) {
        window.alert('請先勾選回覆!');
        return false;
    }
    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";
    quotedComment += "@" + commentAuthor + "\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("<a id='select-all-comment' href='javascript:void(0);'>全選</a>");

        addCheckbox();

        jQuery('#select-all-comment').click(function(){
            jQuery('.batch-reply-checkbox').prop('checked', true);
        });

        var paginationDiv = jQuery('#modactions').next('div');
        paginationDiv.append("<button id='batch-reply' class='pn pnc vm' type='button'>批量回覆</button>");
        paginationDiv.append("<button id='copy-reply' class='pn pnc vm' type='button'>僅複製留言引用</button>");

        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');
    }

});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址