diff --git a/README.md b/README.md index 1cb25f2..6b8883b 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,15 @@ - [阅读模式](http://ksria.com/simpread/docs/#/阅读模式): 简悦 `原创` 功能,逐一适配了 [数百种类型](https://simpread.ksria.cn/sites/) 的网站,自动提取 `标题` `描述` `正文` `媒体资源( 图片/ 视频 )` 等,生成 `符合中文阅读` 的页面 - * 支持 `自动生成目录` [TXT 阅读器](http://ksria.com/simpread/docs/#/TXT-阅读器) [论坛类页面及分页](http://ksria.com/simpread/docs/#/论坛类页面及分页) 如:知乎 · 百度贴吧等 + * 支持 `自动生成目录` + + * 支持 [TXT 阅读器](http://ksria.com/simpread/docs/#/TXT-阅读器) + + * 支持 [论坛类页面及分页](http://ksria.com/simpread/docs/#/论坛类页面及分页) 如:知乎 · 百度贴吧等 + + * ![new纯色.png](https://i.loli.net/2018/09/05/5b8f718046acb.png) 支持 [代码段的高亮](http://ksria.com/simpread/docs/#/代码段的高亮),包含了大部分常见的网站 + + * ![new纯色.png](https://i.loli.net/2018/09/05/5b8f718046acb.png) 支持 [LaTeX 解析](http://ksria.com/simpread/docs/#/LaTeX-阅读器) · [Markdown 阅读器](http://ksria.com/simpread/docs/#/Markdown-阅读器) * 更符合 `中文阅读` 习惯的设置,包括:`字间距` `行间距` 等 以及 `自定义 CSS` ,详细请看 [自定义样式](http://ksria.com/simpread/docs/#/自定义样式) @@ -56,7 +64,9 @@ 通过简单的一个步骤,就可以让 `非适配页面` 支持阅读模式,详细请看 [主动适配](http://ksria.com/simpread/docs/#/主动适配阅读模式) 以及 [操作](http://ksria.com/simpread/welcome/version_1.0.5.html#mate-read-mode) - 智能适配: - 自动识别出 Wordpress · Hexo · Ghost · Discuz 等博客 / 论坛的页面以及只要是结构良好的页面,(无需适配)自动生成阅读模式,详细请看 [智能适配](http://ksria.com/simpread/docs/#/智能适配模式) + + * ![new纯色.png](https://i.loli.net/2018/09/05/5b8f718046acb.png) 全新的 `词法分析引擎`,更智能、更精准的提取正文,辅以精准适配,任意网页均「不在话下」,不仅能自动识别出 Wordpress · Hexo · Ghost · Discuz 等博客 / 论坛的页面,甚至于只要是结构良好的页面,(无需适配)自动生成阅读模式,详细请看 [词法分析引擎](http://ksria.com/simpread/docs/#/词法分析引擎) + - 导入 / 导出 / 同步适配列表 / 初始化数据,以及(相对简悦来说)适度的设置选项; diff --git a/src/userscript/simpread.js b/src/userscript/simpread.js index 541ad2d..69385dc 100644 --- a/src/userscript/simpread.js +++ b/src/userscript/simpread.js @@ -1,33 +1,35 @@ // ==UserScript== // @name 简悦( SimpRead ) · 轻阅版 // @namespace http://ksria.com/simpread/ -// @version 1.1.1.1025 +// @version 1.1.2.5005 // @description 简悦 - 让你瞬间进入沉浸式阅读的 User Script 扩展 // @author Kenshin // @include http://*/* // @include https://*/* -// @require https://cdn.bootcss.com/jquery/2.1.1/jquery.min.js -// @require https://greasyfork.org/scripts/40244-mduikit/code/MDUIKit.js?version=264103 -// @require https://greasyfork.org/scripts/40236-notify/code/Notify.js?version=263047 +// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js +// @require https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js +// @require https://greasyfork.org/scripts/40244-mduikit/code/MDUIKit.js?version=697886 +// @require https://greasyfork.org/scripts/40236-notify/code/Notify.js?version=697887 // @require https://greasyfork.org/scripts/40172-mousetrap/code/Mousetrap.js?version=262594 -// @require https://greasyfork.org/scripts/39995-pureread/code/PureRead.js?version=261636 -// @require https://greasyfork.org/scripts/39997-puplugin/code/PuPlugin.js?version=262834 -// @resource global_sites http://sr.ksria.cn/website_list_v3.json?data=0402 -// @resource origins http://sr.ksria.cn/website_list_origins.json -// @resource notify_style http://sr.ksria.cn/puread/notify.css -// @resource main_style http://sr.ksria.cn/puread/simpread.css -// @resource option_style http://sr.ksria.cn/puread/option.css +// @require https://greasyfork.org/scripts/383025-bloomingmenu/code/BloomingMenu.js?version=698175 +// @require https://greasyfork.org/scripts/39995-pureread/code/PureRead.js?version=697882 +// @require https://greasyfork.org/scripts/39997-puplugin/code/PuPlugin.js?version=697883 +// @resource global_sites http://sr.ksria.cn/website_list_v4.json?data=1.1.2.5005 +// @resource notify_style http://sr.ksria.cn/puread/notify.css?version=1.1.2.5005 +// @resource main_style http://sr.ksria.cn/puread/simpread.css?version=1.1.2.5005 +// @resource mntips_style http://sr.ksria.cn/puread/mintooltip.css?version=1.1.2.5005 +// @resource option_style http://sr.ksria.cn/puread/option.css?version=1.1.2.5005 // @resource user_style https://gist.github.com/Kenshin/365a91c61bad550b5900247539113f06/raw/3e666bee279f249e5b59140d8a777192ecb121cd/simpread_user.css -// @resource theme_common http://sr.ksria.cn/puread/theme_common.css -// @resource theme_dark http://sr.ksria.cn/puread/theme_dark.css -// @resource theme_github http://sr.ksria.cn/puread/theme_github.css -// @resource theme_gothic http://sr.ksria.cn/puread/theme_gothic.css -// @resource theme_night http://sr.ksria.cn/puread/theme_night.css -// @resource theme_pixyii http://sr.ksria.cn/puread/theme_pixyii.css -// @resource theme_engwrite http://sr.ksria.cn/puread/theme_engwrite.css -// @resource theme_monospace http://sr.ksria.cn/puread/theme_monospace.css -// @resource theme_newsprint http://sr.ksria.cn/puread/theme_newsprint.css -// @resource theme_octopress http://sr.ksria.cn/puread/theme_octopress.css +// @resource theme_common http://sr.ksria.cn/puread/theme_common.css?version=1.1.2.5005 +// @resource theme_dark http://sr.ksria.cn/puread/theme_dark.css?version=1.1.2.5005 +// @resource theme_github http://sr.ksria.cn/puread/theme_github.css?version=1.1.2.5005 +// @resource theme_gothic http://sr.ksria.cn/puread/theme_gothic.css?version=1.1.2.5005 +// @resource theme_night http://sr.ksria.cn/puread/theme_night.css?version=1.1.2.5005 +// @resource theme_pixyii http://sr.ksria.cn/puread/theme_pixyii.css?version=1.1.2.5005 +// @resource theme_engwrite http://sr.ksria.cn/puread/theme_engwrite.css?version=1.1.2.5005 +// @resource theme_monospace http://sr.ksria.cn/puread/theme_monospace.css?version=1.1.2.5005 +// @resource theme_newsprint http://sr.ksria.cn/puread/theme_newsprint.css?version=1.1.2.5005 +// @resource theme_octopress http://sr.ksria.cn/puread/theme_octopress.css?version=1.1.2.5005 // @grant GM_getResourceText // @grant GM_addStyle // @grant GM_getValue @@ -43,6 +45,7 @@ const pr = new PureRead(), global_sites = GM_getResourceText( "global_sites" ), notify_style = GM_getResourceText( "notify_style" ), main_style = GM_getResourceText( "main_style" ), + mntips_style = GM_getResourceText( "mntips_style" ), option_style = GM_getResourceText( "option_style" ), user_style = GM_getResourceText( "user_style" ), theme_common = GM_getResourceText( "theme_common" ), @@ -55,7 +58,7 @@ const pr = new PureRead(), theme_monospace = GM_getResourceText( "theme_monospace" ), theme_newsprint = GM_getResourceText( "theme_newsprint" ), theme_octopress = GM_getResourceText( "theme_octopress" ), - theme = { theme_dark, theme_github, theme_gothic, theme_night, theme_pixyii, theme_engwrite, theme_monospace, theme_newsprint, theme_octopress }, + theme = { theme_github, theme_newsprint, theme_gothic, theme_engwrite, theme_octopress, theme_pixyii, theme_monospace, theme_night, theme_dark }, focus = { version : "2016-12-29", bgcolor : "rgba( 235, 235, 235, 0.9 )", @@ -66,6 +69,8 @@ const pr = new PureRead(), }, read = { version : "2017-03-16", + cleanup : true, + pure : true, auto : false, controlbar: true, highlight : true, @@ -78,6 +83,8 @@ const pr = new PureRead(), ], fontsize : "62.5%", layout : "20%", + toc : true, + toc_hide : true, }, option = { version : "2017-04-03", @@ -182,9 +189,31 @@ const pr = new PureRead(), # 支持 minimatch,域名 和 name,例如: "v2ex.com", "http://www.ifanr.com/**/*" # 默认为空,每个名单由小写 , 分隔 set_whitelist: + + # 是否启用增强解析模式? + # 增强解析模式会对版面重新设计,包括:去除多余空格、优化版面结构等,此功能为测试版,遇到解析失败时,请关闭此功能。 + # 默认为 true,取值范围 true | false + set_cleanup: true + + # 是否启用纯粹模式? + # 比【增强解析模式】还要彻底优化版本,包括:字形、颜色、字号、代码段等,专治页面及不规范,如:微信订阅号,CSDN 等。 + # 此功能在 cleanup = true 时才会生效 + # 默认为 true,取值范围 true | false + set_pure: true + + # 是否自动生成大纲(目录)? + # 只整理 h1, h2, h3, h4 的内容为大纲 + # 默认为 true,取值范围 true | false + set_toc: true + + # 大纲(目录)是否开启「鼠标移动到左上角」自动显示? + # 关闭意味着「一直显示」 + # 此功能在 toc = true 时才会生效 + # 默认为 true,取值范围 true | false + set_toc_hide: true `; let current_state = "", // include: focus, read, option - simpread = { version: "1.1.1", focus, read, option }, + simpread = { version: "1.1.2", focus, read, option }, org_simp = { ...simpread }; /**************************** @@ -199,6 +228,7 @@ if ( !blacklist() ) { // add simpread style GM_addStyle( notify_style ); GM_addStyle( main_style ); + GM_addStyle( mntips_style ); GM_addStyle( option_style ); GM_addStyle( user_style ); GM_addStyle( theme_common ); @@ -210,6 +240,8 @@ if ( !blacklist() ) { pr.Addsites( JSON.parse( global_sites )); GM_setValue( "simpread_db", pr.sites ); } + pr.cleanup = simpread.read.cleanup; + pr.pure = simpread.read.pure; pr.AddPlugin( puplugin.Plugin() ); pr.Getsites(); @@ -383,9 +415,9 @@ function controlbar() { */ function entryMode( type ) { type = type == "focus" ? "focus" : "read"; - if ( [ "none", "temp" ].includes( pr.state ) ) { + if ( [ "none" ].includes( pr.state ) ) { if ( simpread[type].highlight == true ) tempMode( type ); - else new Notify().Render( `当前未启用 临时阅读模式,并当前站点也未适配,如需要适配请提交到 此页面` ); + else new Notify().Render( `当前未启用 临时阅读模式,并当前站点也未适配,如需要适配请提交到 此页面` ); } else type == "focus" ? focusMode() : readMode(); } @@ -496,12 +528,26 @@ function readMode() { - 全文完 + + + 全文完 + + - 本文由 简悦 SimpRead 优化,用以提升阅读体验。 +
本文由 简悦 SimpRead 优化,用以提升阅读体验
+
使用了 全新的简悦词法分析引擎beta点击查看详细说明
+
-
- + + + @@ -549,6 +595,22 @@ function readMode() { } }; + if ( pr.isMathJax() && pr.state == "temp" ) { + console.warn( '=== MathJax Mode ===' ) + const dom = pr.MathJaxMode(); + if ( typeof dom == "undefined" ) { + new Notify().Render( "智能感知失败,请移动鼠标框选。" ); + highlight().done( dom => { + storage.pr.TempMode( "read", dom ); + Render( false ); + }); + } else if ( typeof dom == "string" ) { + const html = pr.GetDom( dom, "html" ); + pr.Newsite( "read", html ); + } else { + pr.TempMode( "read", dom[0] ); + } + } pr.ReadMode(); if ( special() ) return; @@ -589,8 +651,11 @@ function readMode() { style.FontSize( simpread.read.fontsize ); style.Layout( simpread.read.layout ); + pr.pure && codehighlight(); + simpread.read.toc && toc(); + // exit - $( ".simpread-read-root sr-rd-crlbar fab" ).one( "click", event => { + $( ".simpread-read-root sr-rd-crlbar fab:not(.setting)" ).one( "click", event => { $( ".simpread-read-root" ).animate( { opacity: 0 }, { delay: 100, complete: () => { @@ -603,6 +668,15 @@ function readMode() { } }).addClass( "simpread-read-root-hide" ); }); + $( ".simpread-read-root sr-rd-crlbar fab:not(.setting)" ).mouseover( () => { + $( ".simpread-read-root sr-rd-crlbar fab.setting" ).addClass( "show" ); + }); + $( ".simpread-read-root sr-rd-crlbar" ).mouseleave( () => { + $( "sr-rd-crlbar fab.setting" ).removeClass( "show" ); + }); + $( ".simpread-read-root sr-rd-crlbar fab.setting" ).click( () => { + wheelmenu(); + }); }; /** @@ -611,7 +685,7 @@ function readMode() { * @param {string} include: focus, read */ function tempMode( mode = "read" ) { - new Notify().Render( "当前并未适配阅读模式,请移动鼠标手动生成 临时阅读模式。" ); + new Notify().Render( "当前并未适配阅读模式,请移动鼠标手动生成 临时阅读模式。" ); highlight().done( dom => { if ( mode == "read" ) { pr.TempMode( mode, dom.outerHTML ); @@ -656,6 +730,180 @@ function highlight() { return dtd; } +/** + * Code highlight + */ +function codehighlight() { + $("head").append('') + $("head").append( '' ) + $("sr-rd-content").find( 'pre' ).map( function(idx,item){ + hljs.highlightBlock(item); + }); +} + +/** + * Wheel menu buttons + */ +function wheelmenu() { + const menu = new BloomingMenu({ + startAngle: -180, + endAngle: 0, + radius: 120, + itemsNum: 7, + itemAnimationDelay: 0, + isAutoClose: false + }); + menu.render(); + menu.open() + menu.props.elements.items.forEach(function (item, index) { + item.addEventListener('click', function () { + switch ( index ) { + case 0: + case 1: + const size = parseFloat( simpread.read.fontsize ) + ( index == 0 ? 3 : -3 ); + simpread.read.fontsize = `${size}%`; + style.FontSize( simpread.read.fontsize ); + GM_setValue( "simpread", simpread ); + break; + case 2: + case 3: + const layout = parseFloat( simpread.read.layout ) + ( index == 3 ? 3 : -3 ); + simpread.read.layout = `${layout}%`; + style.Layout( simpread.read.layout ); + GM_setValue( "simpread", simpread ); + break; + case 4: + case 5: + const arr = Object.keys( theme ), + len = arr.length; + let idx = arr.indexOf( `theme_${simpread.read.theme}` ) + + ( index == 4 ? 1 : -1 ); + if ( idx == len ) { + idx = 0; + } else if ( idx == -1 ) { + idx = len -1; + } + // remove old theme + $( "head" ).find( "style" ).map( (index, item) => { + const $target = $(item), + css = $target.text(); + if ( css.startsWith( "sr-rd-theme-" + simpread.read.theme ) ) { + $target.remove(); + } + }); + // add new theme + simpread.read.theme = arr[idx].replace( "theme_", "" ); + GM_setValue( "simpread", simpread ); + GM_addStyle( theme[`theme_${simpread.read.theme}`] ); + break; + case 6: + menu.remove(); + $(".sr-rd-trigger").remove(); + $("head #blooming-menu__root").remove(); + break; + } + }) + }); + const css = ` + .sr-rd-trigger { + position: fixed; + right: 50%; + bottom: 35px; + } + .blooming-menu__container { + transition: all 1s cubic-bezier(.23,1,.32,1) .1s!important; + } + .blooming-menu__main { + background-color: rgba(244, 67, 54, 1); + } + .blooming-menu__item-btn-wrapper { + background-color: #03a9f4!important; + } + .blooming-menu__main.is-active { + transform: rotate(0); + -webkit-transform: rotate(0); + } + .blooming-menu__item:nth-of-type(3) button, + .blooming-menu__item:nth-of-type(4) button { + transform: rotate(90deg); + } + .blooming-menu__item:nth-of-type(6) button { + transform: rotate(180deg); + } + `; + $( "head" ).append( `` ); + setTimeout( ()=> { + $(".simpread-read-root").append( `
` ); + $(".sr-rd-trigger").append( $(".blooming-menu__container") ); + $(".simpread-read-root .blooming-menu__main-content").html( `` ); + $($(".simpread-read-root .blooming-menu__item-btn")[0]).html( `` ); + $($(".simpread-read-root .blooming-menu__item-btn")[1]).html( `` ); + $($(".simpread-read-root .blooming-menu__item-btn")[2]).html( `` ); + $($(".simpread-read-root .blooming-menu__item-btn")[3]).html( `` ); + $($(".simpread-read-root .blooming-menu__item-btn")[4]).html( `` ); + $($(".simpread-read-root .blooming-menu__item-btn")[5]).html( `` ); + $($(".simpread-read-root .blooming-menu__item-btn")[6]).html( `` ); + $( "body" ).find( ".blooming-menu__container" ).remove(); + }, 1000); + + let preScroll = 0; + $(document).scroll( () => { + if ( $(document).scrollTop() > preScroll ) { + $(".blooming-menu__container").css({transform: 'translate(-50%, 20%)', opacity: 0.5 }); + menu.close(); + } else { + $(".blooming-menu__container").css({transform: 'translate(-50%, -50%)', opacity: 1 }); + } + preScroll = $(document).scrollTop(); + }); +} + +/** + * toc + */ +function toc() { + const table = [], + cls = simpread.read.toc_hide ? "toc-bg-hidden" : ""; + $("sr-read").find( "h1, h2, h3, h4" ).map( ( idx, item) => { + const $item = $( item ), + tag = $item[0].tagName.toLowerCase(), + value = $item.text(); + let id = $item.attr( "id" ); + id = id == undefined ? `sr-toc-${idx}` : `${id}-${idx}` + $item.attr( "id", id ); + value && table.push({ + level: `toc-level-${tag}`, + id, + value, + }); + }); + console.log( "current toc is ", table ) + let tmpl = ""; + table.forEach( ( item, idx ) => { + tmpl += ` + + ${ item.value } + `; + }); + $("sr-read").append( `${tmpl}` ); + let is_click = false; + $("sr-read toc outline a").on( "click", event => { + is_click = true; + const $target = $( event.target ).parent(); + $target.parent().find( "active" ).removeClass( "toc-outline-active" ); + $target.find( "active" ).addClass( "toc-outline-active" ); + + const href = $( event.target ).attr("href"), + offsetTop = href === "#" ? 0 : $(href).offset().top - 5; + $( "html" ).stop().animate({ + scrollTop: offsetTop + }, 300, () => { + setTimeout( ()=>is_click = false, 500 ); + }); + event.preventDefault(); + }) + simpread.read.toc_hide && $('head').append( `` ); +} + /** * Option Mode */ @@ -683,20 +931,21 @@ function optionMode() { if ( event && event.target && event.target.result ) { try { const json = JSON.parse( event.target.result ); - if ( json.version && json.version.replace( /\./g, "" ) >= simpread.version.replace( /\./g, "" ) ) { - Object.keys( simpread.focus ).forEach( key => { json.focus[key] != undefined && (simpread.focus[key] = json.focus[key] )}); - Object.keys( simpread.read ).forEach( key => { json.read[key] != undefined && (simpread.read[key] = json.read[key] )}); - Object.keys( simpread.option ).forEach( key => { json.option[key] != undefined && (simpread.option[key] = json.option[key] )}); - GM_setValue( "simpread", simpread ); - if ( json.websites ) { - pr.sites.custom = [ ...json.websites.custom ]; - pr.sites.local = [ ...json.websites.local ]; - GM_setValue( "simpread_db", pr.sites ); - new Notify().Render( `已导入本地适配源:${ pr.sites.local.length} 条;官方次适配源:${pr.sites.custom.length} 条。` ); - console.log( "new simpread db", pr.sites ) - } - new Notify().Render( "导入成功,请刷新当前页面,以便新配置文件生效。" ); - } else new Notify().Render( 2, "上传的版本太低,请重新上传!" ); + if ( json.version && json.version.replace( /\./g, "" ) < simpread.version.replace( /\./g, "" ) ) { + new Notify().Render( 2, "上传的版本太低,已转换为最新版版本!" ); + } + Object.keys( simpread.focus ).forEach( key => { json.focus[key] != undefined && (simpread.focus[key] = json.focus[key] )}); + Object.keys( simpread.read ).forEach( key => { json.read[key] != undefined && (simpread.read[key] = json.read[key] )}); + Object.keys( simpread.option ).forEach( key => { json.option[key] != undefined && (simpread.option[key] = json.option[key] )}); + GM_setValue( "simpread", simpread ); + if ( json.websites ) { + pr.sites.custom = [ ...json.websites.custom ]; + pr.sites.local = [ ...json.websites.local ]; + GM_setValue( "simpread_db", pr.sites ); + new Notify().Render( `已导入本地适配源:${ pr.sites.local.length} 条;官方次适配源:${pr.sites.custom.length} 条。` ); + console.log( "new simpread db", pr.sites ) + } + new Notify().Render( "导入成功,请刷新当前页面,以便新配置文件生效。" ); } catch ( error ) { new Notify().Render( 2, "上传失败,配置文件解析失败,请重新确认。" ); } } }; @@ -719,7 +968,7 @@ function optionMode() { new Notify().Render( `请勿在 https 下面使用此功能,请前往 http 的页面,如: 点击这里` ); return; } - $.getJSON( "http://sr.ksria.cn/website_list_v3.json" + "?_=" + Math.round(+new Date()), result => { + $.getJSON( "http://sr.ksria.cn/website_list_v4.json" + "?_=" + Math.round(+new Date()), result => { const count = pr.Addsites( result ); count == 0 ? new Notify().Render( "适配列表已同步至最新版本。" ) : new Notify().Render( 0, `适配列表已同步成功,本次新增 ${ count } 个站点。` ); }); @@ -853,14 +1102,18 @@ function aboutMode() { 关于

-
+
+ + versionversion1.1.21.1.2 + +
你好,我是 简悦 · 轻阅版 的开发者 Kenshin,很高兴看到你能使用它。
它是一个阅读模式类的油猴脚本,也是 简悦 的轻量级版本。
拥有 简悦的一切特性,更具有「加载速度快 · 只关注阅读模式呈现」等 特点
简悦的初衷:还原一个干净的阅读空间,提升你的阅读体验。
- 截至到目前为止,简悦已经适配了 ${ pr.sites.global.length }个 网址,详细请看 这里
+ 截至到目前为止,简悦已经精准适配了 ${ pr.sites.global.length }个 网址,详细请看 这里
简悦是一个免费且开源的项目,占用了我绝大多数的业余时间。
如果觉得它还不错,希望可以给我 投票请我喝杯咖啡,这是对简悦的最大鼓励。
现在就加入 Telegram 群,获取简悦的第一手资料。