Greasy Fork镜像 支持简体中文。

轻之国度论坛阅读模式

为轻之国度论坛帖子页面添加阅读模式的功能,还可提取本页帖子的文本内容

目前為 2016-01-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name        轻之国度论坛阅读模式
// @namespace   https://gf.qytechs.cn/users/4514
// @author      喵拉布丁
// @homepage    https://gf.qytechs.cn/scripts/16464
// @description 为轻之国度论坛帖子页面添加阅读模式的功能,还可提取本页帖子的文本内容
// @include     http://www.lightnovel.cn/thread-*.html
// @include     http://www.lightnovel.cn/forum.php?mod=viewthread*
// @require     https://code.jquery.com/jquery-2.2.0.min.js
// @version     1.4
// @grant       none
// @run-at      document-end
// @license     MIT
// ==/UserScript==
jQuery.noConflict();

// 配置类
var Config = {
    // 是否自动进入阅读模式(在当前版块的ID包含在下方列表时),true:开启;false:关闭
    autoEnterReadMode: false,
    // 自动进入阅读模式的版块ID列表
    autoEnterForumIdList: [4, 173, 91, 28, 133, 88],
    // 帖子文本之间的分隔符(用于提取本页帖子的文本内容)
    threadSeparator: '\n=================================\n',

    /* 阅读模式风格设置 */
    pageBgColor: '#F4F4F4', // 页面背景颜色
    threadBgColor: '#DBEED9', // 帖子背景颜色
    fontSize: '22px', // 帖子字体大小
    fontFamily: 'Microsoft YaHei', // 帖子字体名称
    lineHeight: '180%' // 帖子文字行高
};

(function ($) {
    // 进入阅读模式
    var enterReadMode = function () {
        $('head').append(
            ('<style id="pd_read_mode_style">' +
            '  body { background-color: {0}; }' +
            '  .pls { display: none; }' +
            '  #postlist { background-color: {1}; }' +
            '  [id^="postmessage_"] { font-size: {2}; line-height: {3}; }' +
            '  [id^="postmessage_"] font { font-size: {2} !important; line-height: {3}; font-family: "{4}"; }' +
            '  [id^="postmessage_"] img { max-width: 920px; max-height: 850px; }' +
            '</style>')
                .replace(/\{0\}/g, Config.pageBgColor)
                .replace(/\{1\}/g, Config.threadBgColor)
                .replace(/\{2\}/g, Config.fontSize)
                .replace(/\{3\}/g, Config.lineHeight)
                .replace(/\{4\}/g, Config.fontFamily)
        );
    };

    // 处理帖子文本内容
    var handleThreadContent = function (content) {
        content = content.replace(/<i class="pstatus">\s*本帖最后由.+?编辑\s*<\/i>/ig, '')
            .replace(/<ignore_js_op>(?:.|\r|\n)+?<img.+?src="([^"<>\r\n]+?)"(?:.|\r|\n)+?<\/ignore_js_op>/ig, '【图片:http://www.lightnovel.cn/$1】')
            .replace(/<img[^<>\r\n]+?src="http([^"<>\r\n]+?)"[^<>\r\n]+?>/ig, '【图片:http$1】')
            .replace(/<img[^<>\r\n]+?smilieid[^<>\r\n]+?>/ig, '【表情图片】')
            .replace(/(<.+?>|<\/.+?>)/ig, '')
            .replace(/&quot;/gi, '\"')
            .replace(/&#39;/gi, '\'')
            .replace(/&nbsp;/gi, ' ')
            .replace(/&gt;/gi, '>')
            .replace(/&lt;/gi, '<')
            .replace(/&amp;/gi, '&');
        return content;
    };

    var $enterReadModeLink = $('<a style="color:#FF6666;" href="#" title="进入或退出阅读模式">进入阅读模式</a>')
        .insertAfter('#wmffstranlink')
        .click(function (event) {
            event.preventDefault();
            var $this = $(this);
            if ($this.text() === '退出阅读模式') {
                $('#pd_read_mode_style').remove();
                $this.text('进入阅读模式');
            }
            else {
                enterReadMode();
                $this.text('退出阅读模式');
            }
        });

    $('<a style="color:#0099CC;" href="#" title="提取本页所有帖子的文本内容">提取帖子内容</a>')
        .insertBefore($enterReadModeLink)
        .click(function (event) {
            event.preventDefault();
            if ($('#pd_thread_content').length > 0) return;
            var content = '';
            $('[id^="postmessage_"]').each(function () {
                content += $(this).html() + Config.threadSeparator;
            });
            var $threadContent = $(
                '<div id="pd_thread_content" style="position: fixed; background-color: #2B7ACD;">' +
                '  <span style="float: right; font-size: 16px; margin-right: 5px; padding: 2px 5px; color: #FFF; cursor: pointer;">&times;</span><br />' +
                '  <textarea wrap="off" style="width: 750px; height: 450px; white-space: pre;"></textarea>' +
                '</div>'
            ).appendTo('body');
            $threadContent.css('left', ($(window).width() - $threadContent.outerWidth()) / 2 + 'px')
                .css('top', ($(window).height() - $threadContent.outerHeight()) / 2 + 'px')
                .find('span:first')
                .click(function (e) {
                    e.preventDefault();
                    $('#pd_thread_content').remove();
                });
            $threadContent.find('textarea').val(handleThreadContent(content)).focus().select();
        });

    $('img[id^="aimg_"]').each(function () {
        var $this = $(this);
        $this.attr('src', $this.attr('file')).removeAttr('width');
    });

    if (Config.autoEnterReadMode) {
        var forumId = parseInt($('input[type="hidden"][name="srhfid"]').val());
        if ($.inArray(forumId, Config.autoEnterForumIdList) > -1) {
            enterReadMode();
            $enterReadModeLink.text('退出阅读模式');
        }
    }
})(jQuery);

QingJ © 2025

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