Greasy Fork

Greasy Fork is available in English.

Yamibo Forum Batch Reply

try to take over the world!

当前为 2018-05-08 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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/*
// ==/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];


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

});