小町助手

1.自动点击"签到"按钮; 2.图墙模式(仅适用于"激音馆"与"柔音馆").

// ==UserScript==
// @name         小町助手
// @namespace    SOS
// @version      1.4
// @description  1.自动点击"签到"按钮; 2.图墙模式(仅适用于"激音馆"与"柔音馆").
// @author       电解熔融氧化铝
// @match        *://rainkmc.com/forum.php
// @match        *://rainkmc.com/forum.php?mod=forumdisplay&fid=42*
// @match        *://rainkmc.com/forum.php?mod=forumdisplay&fid=41*
// @require      http://libs.baidu.com/jquery/1.9.0/jquery.js
// ==/UserScript==


// 4.图片加载失败后重复加载
var addedScript = document.createElement("script");
addedScript.type = "text/javascript";
addedScript.innerHTML = "function resetImgUrl(imgObj,imgSrc,maxErrorNum){\
    if(maxErrorNum > 0){\
        imgObj.onerror=function(){\
            resetImgUrl(imgObj,imgSrc,maxErrorNum-1);\
        };\
        setTimeout(function(){\
            imgObj.src=imgSrc;\
        },500);\
    }else{\
        imgObj.onerror=null;\
        imgObj.src='https://rainkmc.com/uc_server/data/avatar/000/00/01/00_avatar_big.jpg';\
        imgObj.width='300';\
    }\
\}";
document.body.appendChild(addedScript);


// 1.自动签到
var button = $('button');
button = button[0];
if (button.innerHTML == "签到"){
    button.click();
}

// 2.隐藏"下一页"按钮
document.getElementById("autopbn").style.display="none";


// 3.插入封面图片
// 选择所有tbody标签中id以normalthread开头的id属性
var x = $('tbody[id^="normalthread"]');

for (var i = 0; i < x.length; i++) {
    // 获得dom对象
    var element = x[i];

    // 获取RJ号, 例如: "RJ123456"
    var RJNumber = element.outerText;
    var start = RJNumber.indexOf("RJ");
    var end = start + 8;
    RJNumber = RJNumber.slice(start, end);
    if ( RJNumber ==""){
        RJNumber = "RJ666666";
    }

    // 获取封面URL
    var picURL = "https://img.dlsite.jp/resize/images2/work/doujin/";
    if (RJNumber.slice(5, 8) == "000"){
        picURL += RJNumber + "/" + RJNumber + "_img_main_300x300.jpg";
    }else {
        var numLength = (parseInt(RJNumber.slice(2, 5))+ 1).toString().length; // 补零
        switch(numLength){
            case 3:
                picURL += "RJ" + (parseInt(RJNumber.slice(2, 5))+ 1).toString() + "000/" + RJNumber + "_img_main_300x300.jpg";
                break;
            case 2:
                picURL += "RJ0" + (parseInt(RJNumber.slice(2, 5))+ 1).toString() + "000/" + RJNumber + "_img_main_300x300.jpg";
                break;
            case 1:
                picURL += "RJ00" + (parseInt(RJNumber.slice(2, 5))+ 1).toString() + "000/" + RJNumber + "_img_main_300x300.jpg";
                break;
        }
    }
    // 插入图片
    var picLink = document.createElement("a"); // 创建一个a元素
    // a标签的属性
    picLink.href = "https://rainkmc.com/forum.php?mod=viewthread&tid=" + element.id.match(/\d+/g) + "&extra=page%3D1"; // 链接指向地址
    picLink.target = "_blank"; // 在新页面打开
    // a标签的内容
    picLink.innerHTML = "<img onerror='resetImgUrl(this,this.src,3)' src=" + picURL + " alt='加载中' width='300'>";
    // 向dom对象中添加新创建的元素
    element.appendChild(picLink);
}