// ==UserScript==
// @name 轻之国度论坛阅读模式
// @namespace https://greasyfork.org/users/4514
// @author 喵拉布丁
// @homepage https://greasyfork.org/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.5
// @grant none
// @run-at document-end
// @license MIT
// @downloadURL none
// ==/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(
('')
.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(/\s*本帖最后由.+?编辑\s*<\/i>/ig, '')
.replace(/(?:.|\r|\n)+?\r\n]+?)"(?:.|\r|\n)+?<\/ignore_js_op>/ig, '【图片:http://www.lightnovel.cn/$1】')
.replace(/
\r\n]+?src="http([^"<>\r\n]+?)"[^<>\r\n]+?>/ig, '【图片:http$1】')
.replace(/
\r\n]+?smilieid[^<>\r\n]+?>/ig, '【表情图片】')
.replace(/(<.+?>|<\/.+?>)/ig, '')
.replace(/"/gi, '\"')
.replace(/'/gi, '\'')
.replace(/ /gi, ' ')
.replace(/>/gi, '>')
.replace(/</gi, '<')
.replace(/&/gi, '&');
return content;
};
var $enterReadModeLink = $('进入阅读模式')
.insertAfter('#wmffstranlink')
.click(function (event) {
event.preventDefault();
var $this = $(this);
if ($this.text() === '退出阅读模式') {
$('#pd_read_mode_style').remove();
$this.text('进入阅读模式');
}
else {
enterReadMode();
$this.text('退出阅读模式');
}
});
$('提取帖子内容')
.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 = $(
'' +
' ×
' +
' ' +
'
'
).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);