console.log( "=== simpread read load ===" ) import ProgressBar from 'schedule'; import * as spec from 'special'; import ReadCtlbar from 'readctlbar'; import * as toc from 'toc'; import * as modals from 'modals'; import * as se from 'siteeditor'; import * as kbd from 'keyboard'; import { storage, Clone } from 'storage'; import th from 'theme'; import * as ss from 'stylesheet'; import {browser} from 'browser'; import * as msg from 'message'; import * as highlight from 'highlight'; import * as run from 'runtime'; import * as tooltip from 'tooltip'; import * as waves from 'waves'; const rdcls = "simpread-read-root", bgtmpl = `
`, rdclsjq = "." + rdcls, $root = $( "html" ), theme = "simpread-theme-root"; const Footer = () => { return ( 全文完 本文由 简悦 SimpRead 优化,用以提升阅读体验。 ) } class Read extends React.Component { componentWillMount() { loadPlugins( "read_start" ); $( "body" ).addClass( "simpread-hidden" ); th.Change( this.props.read.theme ); // hack code //storage.current.fap && $( "head" ).append( '' ); if ( storage.current.fap ) { $( "head" ).append( '' ); $( "head" ).append( '' ); } } async componentDidMount() { if ( $root.find( "sr-rd-content-error" ).length > 0 ) { this.componentWillUnmount(); if ( ! localStorage["sr-update-site"] ) { new Notify().Render({ content: "当前页面结构改变导致不匹配阅读模式,接下来请选择?", action: "更新", cancel: "高亮", callback: type => { if ( type == "action" ) { new Notify().Render( "2 秒钟后将会自动查找更新,请勿关闭此页面..." ); localStorage["sr-update-site"] = true; setTimeout( ()=>browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.update_site, { url: location.href, site: storage.pr.current.site } )), 2000 ); } else { this.props.read.highlight == true ? setTimeout( () => { Highlight().done( dom => { storage.pr.TempMode( "read", dom ); Render(); }); }, 200 ) : new Notify().Render( `请先开启 临时阅读模式 选项!` ); } }}); } else { new Notify().Render({ content: "更新后仍无法适配此页面,是否提交?", action: "是的", cancel: "取消", callback: type => { if ( type == "cancel" ) return; browser.runtime.sendMessage( msg.Add( msg.MESSAGE_ACTION.save_site, { url: location.href, site: storage.pr.current.site, uid: storage.user.uid, type: "failed" })); }}); } localStorage.removeItem( "sr-update-site" ); } else { $root .addClass( "simpread-font" ) .addClass( theme ) .find( rdclsjq ) .addClass( theme ) .sreffect( { opacity: 1 }, { delay: 100 }) .addClass( "simpread-read-root-show" ); this.props.read.fontfamily && ss.FontFamily( this.props.read.fontfamily ); this.props.read.fontsize && ss.FontSize( this.props.read.fontsize ); this.props.read.layout && ss.Layout( this.props.read.layout ); ss.Preview( this.props.read.custom ); storage.pr.state == "txt" && $( "sr-rd-content" ).css({ "word-wrap": "break-word", "white-space": "pre-wrap" }); storage.pr.current.site.desc == "" && $( "sr-rd-desc" ).addClass( "simpread-hidden" ); excludes( $("sr-rd-content"), this.props.wrapper.exclude ); storage.pr.Beautify( $( "sr-rd-content" ) ); storage.pr.Format( rdcls ); !this.props.wrapper.avatar && this.props.read.toc && toc.Render( "sr-read", $( "sr-rd-content" ), this.props.read.theme, this.props.read.toc_hide ); this.props.read.site.css && this.props.read.site.css.length > 0 && ss.SiteCSS( this.props.read.site.css ); kbd.Render( $( "sr-rd-content" )); tooltip.Render( rdclsjq ); waves.Render({ root: rdclsjq }); storage.Statistics( "read" ); loadPlugins( "read_complete" ); localStorage.removeItem( "sr-update-site" ); } } componentWillUnmount() { loadPlugins( "read_end" ); ss.FontSize( "" ); $root.removeClass( theme ) .removeClass( "simpread-font" ); $root.attr("style") && $root.attr( "style", $root.attr("style").replace( "font-size: 62.5%!important", "" )); ss.SiteCSS(); $( "body" ).removeClass( "simpread-hidden" ); $( rdclsjq ).remove(); tooltip.Exit( rdclsjq ); } /** * Controlbar action event * @param {string} type, include: exit, setting, save, scroll, option * @param {string} value * @param {string} custom value, storage.current.custom.art.xxx */ onAction( type, value, custom ) { switch ( type ) { case "exit": this.exit(); break; case "setting": modals.Render( ()=>setTimeout( ()=>se.Render(), 500 )); break; case "siteeditor": $( "panel-bg" ).length > 0 && $( "panel-bg" )[0].click(); setTimeout( ()=>se.Render(), 500 ); break; case "fontfamily": case "fontsize": case "layout": case "theme": case "shortcuts": case "custom": type != "custom" ? storage.current[type]=value : storage.current.custom.art[custom]=value; storage.Setcur( storage.current.mode ); break; case "remove": new Notify().Render( "移动鼠标选择不想显示的内容,只针对本次有效。" ); $( "panel-bg" ).length > 0 && $( "panel-bg" ).trigger( "click" ); Highlight().done( dom => { $(dom).remove(); }); break; case "highlight": new Notify().Render( "移动鼠标选择高亮区域,以便生成阅读模式,将会在页面刷新后失效。" ); this.exit(); Highlight().done( dom => { storage.pr.TempMode( "read", dom ); Render(); }); break; /* case "scroll": $( "sr-read" ).velocity( "scroll", { offset: $( "body" ).scrollTop() + value }); break; */ } } // exit read mode exit() { Exit(); } render() { const Article = this.props.wrapper.avatar ? : ; const Page = this.props.wrapper.paging && ; return ( { this.props.wrapper.title } { this.props.wrapper.desc } { Article } { Page }