Filters Redesign (#658)

* Add XCheckboxFilter

* Fix madara typo

* Change the branch name in config

* Add typing for madara popoularnovels filters

* Add preview and refactor PluginWrapper

* Add preview HTML sanitize and other improv.

* Web improvements + sanitizeHTML

* Add dark mode

* Add git run less to compile less

* Add less.js to remove the need for compiling less
This commit is contained in:
Marcin Majewski
2023-12-27 15:49:46 +01:00
committed by GitHub
parent 9cdace3460
commit d7a76063bf
170 changed files with 94169 additions and 80752 deletions
+7 -4
View File
@@ -3,6 +3,7 @@ import { languages } from "@libs/languages";
import path from "path";
import { PluginList } from "@typings/types";
import { Plugin, isPlugin } from "@typings/plugin";
import { Filters } from "@libs/filterInputs";
const root = path.dirname(require?.main?.filename || "");
export const all_plugins = (): PluginList => {
@@ -43,18 +44,20 @@ export const all_plugins = (): PluginList => {
const getPlugin = async (
requirePath: string
): Promise<Plugin.PluginBase | null> => {
console.log("loading plugin", requirePath);
const plugin = await require(requirePath).default;
console.log(plugin);
if (isPlugin(plugin)) return plugin;
console.log("Not a plugin!");
return null;
};
export const getFilter = async (
pluginRequirePath: string
) => (await getPlugin(pluginRequirePath))?.filters;
export const getFilter = async (pluginRequirePath: string) =>
(await getPlugin(pluginRequirePath))?.filters;
export const popularNovels = async (
pluginRequirePath: string,
options: Plugin.PopularNovelsOptions
options: Plugin.PopularNovelsOptions<Filters>
) => (await getPlugin(pluginRequirePath))?.popularNovels(1, options);
export const searchNovels = async (
+163 -31
View File
@@ -8,26 +8,46 @@
<link rel="shortcut icon" sizes="128x128" type="image/png" href="/static/ico.png" defer />
<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/mdb5.css">
<link rel="stylesheet" href="/static/css/index.css">
<link rel="stylesheet/less" type="text/css" href="/static/css/index.less" />
<script src="/static/js/less.js"></script>
<script src="static/md5Themes/themes.js"></script>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/html-sanitize.js" defer></script>
<script src="/static/js/bootstrap.min.js" defer></script>
<script src="/static/js/mdb5.js" defer></script>
<script src="/static/js/index.js" defer></script>
<title>Testing plugin</title>
</head>
<body>
<nav class="navbar navbar-light bg-light">
<body class="darkmode">
<nav class="navbar">
<form class="form-inline">
<input id="plugin" class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="button" id="clear-search">Clear</button>
<div id="search-results">
<div id="turnoff-catch"></div>
</div>
</form>
<div class="input-group">
<select class="custom-select" id="language">
<option value=""></option>
</select>
<div class="input-group-append">
<label class="input-group-text" for="language">Language</label>
</div>
<select class="custom-select" id="language">
<option value="">Any</option>
</select>
</div>
<button class="btn btn-secondary" style="float:left;" onclick="toggleDarkMode(this)">Light mode</div>
<script>
const toggleDarkMode = (btn) => {
if (document.body.classList.contains("darkmode")) {
document.body.classList.remove("darkmode");
btn.innerText = "Dark mode";
} else {
document.body.classList.add("darkmode")
btn.innerText = "Light mode";
}
}
</script>
</nav>
<div id="test-container">
<div class="test-wrapper" id="popularNovels">
@@ -35,21 +55,22 @@
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#filtersModal">
Filters
</button>
<div class="modal fade" id="filtersModal" tabindex="-1" role="dialog" aria-labelledby="filtersModalLabel" aria-hidden="true">
<div class="modal fade" id="filtersModal" tabindex="-1" role="dialog"
aria-labelledby="filtersModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="filterModalLabel">Filters</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="filterModalLabel">Filters</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
@@ -83,9 +104,10 @@
<div class="title">
parseNovelAndChapters
<div class="input-group">
<input type="text" class="form-control" placeholder="novel url">
<input type="text" class="form-control" placeholder="novel url" id="parse-novel-url">
<div class="input-group-append">
<button class="btn btn-primary parseNovelAndChapters-btn" type="button">fetch</button>
<button class="btn btn-primary parseNovelAndChapters-btn" type="button"
id="parse-novel-btn">fetch</button>
</div>
</div>
<div class="spinner-border" role="status">
@@ -95,7 +117,9 @@
<div class="novel-list">
<div class="novel-item">
</div>
<div class="chapter-list">
<div class="chapter-list-container">
<div class="chapter-list">
</div>
</div>
</div>
</div>
@@ -103,18 +127,130 @@
<div class="title">
parseChapter
<div class="input-group">
<input type="text" class="form-control" placeholder="chapter url">
<input type="text" class="form-control" placeholder="chapter url" id="chapter-parse-url">
<div class="input-group-append">
<button class="btn btn-primary parseChapter-btn" type="button">fetch</button>
<button class="btn btn-primary parseChapter-btn" type="button"
id="chapter-parse-btn">fetch</button>
</div>
</div>
<div id="preview-toggler">
<div class="slider-checkbox">
<label>
<input type="checkbox" id="raw-preview-switch" />
<span>Raw</span>
</label>
</div>
<div class="slider-checkbox">
<label>
<input type="checkbox" id="sanitize-preview-html" />
<span>Sanitized HTML</span>
</label>
</div>
<div id="scaled-info"></div>
<div class="modal-container">
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#settingsModal">
Preview settings
</button>
<div class="modal fade" id="settingsModal" tabindex="-1" role="dialog"
aria-labelledby="settingsModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="settingsModalLabel">Settings</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<div>
<label class="filter-label">Preview Size</label>
<div id="size-input">
<div>
<select id="size-preset">
<option value="800,1200">Default</option>
<option value="2200,2480">8" Fold</option>
<option value="1536,2048">Nexus 9 (Tablet)</option>
<option value="1440,2560">Pixel XL</option>
<option value="1440,3120">Pixel 6 Pro</option>
<option value="1080,2400">Pixel 6</option>
<option value="1080,2340">Pixel 5</option>
<option value="1440,3040">Pixel 4 XL</option>
<option value="1080,2280">Pixel 4</option>
<option value="1080,2160">Pixel 3</option>
<option value="1080,1920">Pixel 2</option>
<option value="768,1280">Nexus 4</option>
<option value="720,1280">720p</option>
<option value="480,854">480p</option>
<option value="480,800">Nexus One</option>
<option value="320,480">320p</option>
</select>
<div class="btn btn-primary" id="load-preset-size">Load preset</div>
</div>
<div>
<input type="number" id="width-input"
style="display:inline-block" />
<input type="number" id="height-input"
style="display:inline-block" />
<div class="btn btn-primary" id="swap-iframe-size">Rotate</div>
</div>
</div>
</div>
<div>
<label class="filter-label">Theme</label>
<div id="theme-picker">
</div>
</div>
<div>
<label class="filter-label">Background Color</label>
<input type="text" id="bgc-input" />
</div>
<div>
<label class="filter-label">Text Color</label>
<input type="text" id="txt-input" />
</div>
<div>
<label class="filter-label">Text Align</label>
<select id="ta-input" class="custom-select">
<option value="left" selected>Left</option>
<option value="right">Right</option>
<option value="center">Center</option>
<option value="justify">Justify</option>
</select>
</div>
<div>
<label class="filter-label">Font Size</label>
<input type="number" id="fs-input" />
</div>
<div>
<label class="filter-label">Line Height</label>
<input step="0.1" type="number" id="lh-input" />
</div>
<hr />
<div>
<label class="filter-label">Custom CSS</label>
<textarea rows="5" id="css-ta"></textarea>
</div>
<hr />
<div>
<label class="filter-label">Custom JS</label>
<textarea rows="5" id="js-ta"></textarea>
</div>
<hr />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary"
data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="spinner-border" role="status">
<span class="sr-only">Loading...</span>
</div>
</div>
<div class="form-group">
<textarea maxlength="10000000" class="form-control" rows="10">
</textarea>
<div class="form-group" id="chapter-viewer">
</div>
</div>
<div class="test-wrapper" id="fetchImage">
@@ -134,9 +270,5 @@
</div>
</div>
</body>
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>
<script src="/static/js/mdb5.js"></script>
<script src="/static/js/index.js"></script>
</html>
+94
View File
@@ -0,0 +1,94 @@
:root {
--main-bg: rgb(24, 26, 27);
--highlight-bg: rgb(28, 31, 32);
--btn-secondary-color: rgb(33, 37, 38);
--text-color: rgb(182, 176, 166);
--light-text-color: rgb(232, 230, 227);
--dark-border-color: rgb(60, 65, 68);
--hr-color: rgb(50, 55, 57);
}
.darkmode {
color-scheme: dark;
background-color: var(--main-bg);
select,
input {
background-color: var(--main-bg);
color: var(--text-color);
border-color: var(--dark-border-color);
}
.navbar {
background-color: var(--main-bg);
color: white;
label {
color: var(--text-color);
background-color: var(--main-bg);
border-color: var(--dark-border-color);
}
form > input {
background-color: var(--main-bg);
color: var(--text-color);
border-color: var(--dark-border-color);
}
}
button.btn-secondary {
background-color: var(--btn-secondary-color);
&:focus {
box-shadow: none;
}
}
#search-results {
background-color: var(--main-bg);
color: var(--text-color);
}
.chapter-item {
.info-item,
.info-value,
.info-item .btn,
.info-item samp {
color: var(--light-text-color);
}
samp {
background-color: var(--main-bg);
}
}
.novel-item {
.info-item,
.info-value,
.info-item .btn,
.info-item samp {
color: var(--light-text-color);
}
samp {
background-color: var(--main-bg);
}
}
.form-control {
color: rgb(182, 176, 166);
background-color: var(--main-bg);
border-color: var(--dark-border-color);
}
.test-wrapper {
background-color: var(--highlight-bg);
color: var(--text-color);
input {
&[type="text"] {
background-color: var(--main-bg);
border-color: var(--dark-border-color);
}
}
}
.modal-content {
background-color: var(--main-bg);
.close {
color: var(--text-color);
text-shadow: var(--main-bg) 0px 1px 0px;
}
.modal-header {
border-bottom: 2px solid var(--hr-color);
}
.modal-footer {
border-top: 2px solid var(--hr-color);
}
}
}
-130
View File
@@ -1,130 +0,0 @@
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
.navbar{
width: 1080px;
align-items: center;
padding-left: 5%;
justify-content: space-between;
}
.input-group{
width: 20rem;
}
#search-results{
position: absolute;
top: calc(100% - 0.5rem);
width: 15rem;
padding: 0.375rem 0;
border-radius: 5px;
background-color: white;
z-index: 3;
}
.btn.disabled, .btn:disabled{
opacity: 1;
}
#test-container{
align-items: center;
height: max-content;
margin-bottom: 100px;
}
.test-wrapper{
margin: 1rem;
padding: 0.5rem;
background-color: aliceblue;
}
#popularNovels, #searchNovels{
height: 350px;
min-width: 95%;
max-width: 95%;
overflow-y: hidden;
overflow-x: scroll;
}
#parseNovelAndChapters{
height: 380px;
min-width: 95%;
max-width: 95%;
}
.title{
font-weight: bold;
}
.spinner-border {
display: none;
width: 1rem;
height: 1rem;
vertical-align: text-bottom;
border: 0.25em solid currentColor;
border-right-color: transparent;
border-radius: 50%;
-webkit-animation: spinner-border .75s linear infinite;
animation: spinner-border .75s linear infinite;
}
@keyframes spinner-border{
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.novel-list{
display: flex;
margin-top: 0.5rem;
height: 300px;
width: 100%;
}
.novel-item{
display: flex;
padding: 0.5rem;
}
.novel-item img {
max-height: 90%;
}
.novel-info{
width: 16rem;
}
.info-item{
display: flex;
margin-top: 5px;
}
.info-value{
width: 10rem;
padding-left: 0.25rem;
font-size: 0.65rem;
word-wrap:break-word;
}
.btn{
font-size: 0.75rem;
padding: 0.25rem 0.25rem;
}
.chapter-list{
position: relative;
display: grid;
min-width: 50%;
overflow-y: scroll;
overflow-x: scroll;
grid-template-columns: 15rem 15rem 15rem 15rem;
grid-gap: 0, 0;
}
.select-option-text{
padding-left: 1rem;
}
+464
View File
@@ -0,0 +1,464 @@
@import "./darkmode";
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.navbar {
width: 100vw;
align-items: center;
padding-inline: 3%;
gap: auto;
justify-content: space-between;
label.input-group-text {
height: 100%;
}
button.btn-secondary {
padding-inline: 5px;
}
}
#search-results {
position: absolute;
top: calc(100% - 0.5rem);
width: fit-content;
max-height: 500%;
overflow-y: scroll;
overflow-x: hidden;
padding: 0.375rem 0;
border-radius: 5px;
background-color: white;
z-index: 3;
}
#turnoff-catch {
width: 100vw;
height: 100vh;
position: absolute;
top: 0;
left: 0;
z-index: 2;
}
.input-group {
width: 20rem;
}
.checkbox-groupbox {
border: 1px solid rgb(182, 176, 166);
padding: 5px;
display: grid;
gap: 10px;
grid-template-columns: repeat(3, auto);
justify-content: center;
}
.xcheckbox-groupbox {
border: 1px solid rgb(182, 176, 166);
padding: 5px;
display: grid;
gap: 10px;
grid-template-columns: repeat(3, auto);
justify-content: center;
}
.xcheckbox {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
/* Hide the browser's default checkbox */
input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
span {
position: absolute;
top: 6px;
left: 5px;
height: 20px;
width: 20px;
background-color: #eee;
border: 1px solid white;
&::after {
content: "";
position: absolute;
display: none;
}
}
&[data-state="i"] {
span {
background-color: #2196f3;
&::after {
left: 6px;
top: 3px;
width: 6px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
}
&:hover {
span {
background-color: #56a3ff;
}
}
}
&[dara-state="x"] {
span {
background-color: #f32196;
position: absolute;
height: 20px;
width: 20px;
display: flex;
flex-direction: column;
justify-content: center;
background-color: red;
&::after,
&::before {
position: absolute;
content: "";
width: 80%;
left: 10%;
height: 2px;
background-color: white;
}
&::before {
transform: rotate(45deg);
}
&::after {
transform: rotate(-45deg);
}
}
&:hover {
span {
background-color: #ff56a3;
}
input ~ span {
background-color: #ccc;
}
}
}
input:checked ~ span::after {
display: block;
}
}
.modal-body {
padding: 16px 50px 0 50px;
}
.checkbox-groupbox input {
margin-right: 5px;
}
.SwitchFilter {
display: flex;
justify-content: center;
}
.SwitchFilter input {
margin-left: 10px;
}
.PickerFilter select {
text-align: center;
}
.filter-label {
display: block;
text-align: center;
font-weight: bold;
}
#filtersModal {
.modal-body div {
display: grid;
align-content: center;
}
hr {
margin-bottom: 10px;
margin-top: 10px;
/* visibility: hidden; */
}
}
#settingsModal {
.modal-body > div {
display: grid;
align-content: center;
}
input {
text-align: center;
}
textarea {
display: block;
width: 100%;
margin-inline: auto;
}
}
#test-container {
align-items: center;
height: max-content;
margin-bottom: 100px;
}
.test-wrapper {
margin: 1rem;
padding: 0.5rem;
background-color: aliceblue;
}
#popularNovels,
#searchNovels,
#parseNovelAndChapters,
#parseChapter,
#fetchImage {
min-width: 95%;
max-width: 95%;
margin-inline: auto;
}
#popularNovels,
#searchNovels {
height: 350px;
overflow-y: hidden;
overflow-x: scroll;
}
.novel_info {
display: grid;
grid-auto-flow: row;
grid-auto-rows: min-content;
}
.parse-novel-btn {
width: 85%;
margin-inline: auto;
margin-top: 5px;
}
#parseNovelAndChapters {
height: 380px;
}
.title {
font-weight: bold;
}
@keyframes spinner-border {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.spinner-border {
display: none;
width: 1rem;
height: 1rem;
vertical-align: text-bottom;
border: 0.25em solid currentColor;
border-right-color: transparent;
border-radius: 50%;
-webkit-animation: spinner-border 0.75s linear infinite;
animation: spinner-border 0.75s linear infinite;
}
.novel-list {
display: flex;
margin-top: 0.5rem;
height: 300px;
width: 100%;
}
.novel-item {
display: flex;
padding: 0.5rem;
img {
max-height: 90%;
}
}
.novel-info {
width: 16rem;
}
/* comment */
.info-item {
display: grid;
grid-auto-columns: min-content auto 50px;
margin-top: 5px;
grid-auto-flow: column;
div {
display: grid;
align-items: center;
}
}
.info-value {
width: 10rem;
padding-inline: 0.25rem;
font-size: 0.65rem;
word-wrap: break-word;
}
.info-copy {
display: grid;
align-content: center;
}
.btn {
font-size: 0.75rem;
padding: 0.25rem 0.25rem;
&.disabled,
&:disabled {
opacity: 1;
}
}
.chapter-list-container {
max-height: 95%;
overflow-y: scroll;
}
.chapter-list {
column-count: 2;
}
.chapter-item {
display: grid;
grid-template-areas: "name btn1 btn2" "date btn1 btn2";
}
.ci-topleft {
grid-area: name;
}
.ci-bottomleft {
grid-area: date;
}
.ci-btn1 {
grid-area: btn1;
}
.ci-btn2 {
grid-area: btn2;
}
.select-option-text {
padding-left: 1rem;
}
/* Slider checkbox */
.slider-checkbox {
--ball-width: 15px;
--box-margin: 5px;
--box-width: calc(2 * var(--ball-width) + var(--box-margin));
input {
display: none;
}
label {
height: fit-content;
width: fit-content;
span {
position: relative;
left: calc(var(--box-margin) + var(--box-width));
user-select: none;
&::after {
transition: 0.2s ease-out;
position: absolute;
content: "";
top: calc((100% - var(--ball-width)) / 2);
width: var(--ball-width);
height: var(--ball-width);
left: calc(-1 * (var(--box-width) + var(--box-margin)) + 2px);
border-radius: 50%;
display: inline-block;
background-color: rgb(0, 60, 255);
}
&::before {
position: absolute;
top: 0;
left: calc(-1 * var(--box-width) - var(--box-margin));
content: "";
width: var(--box-width);
height: 100%;
border-radius: 10px;
background-color: red;
display: inline-block;
}
}
input:checked ~ span::after {
left: calc(-1 * (var(--box-margin) + var(--ball-width) + 3px));
background-color: rgb(0, 60, 255);
}
input:checked ~ span::before {
background-color: rgb(0, 255, 0);
}
}
}
iframe {
margin: 0 auto;
border: 1px solid black;
background-color: white;
display: block;
overflow: scroll;
}
#preview-toggler {
display: flex;
flex-direction: row;
gap: 50px;
}
#theme-picker {
display: grid;
grid-template-columns: repeat(5, auto);
gap: 10px;
justify-content: center;
.theme {
width: 50px;
height: 50px;
padding: 5px;
word-wrap: break-word;
word-break: break-all;
border-radius: 50%;
border: 1px solid gray;
transition-duration: 0.2s;
display: grid;
text-align: center;
justify-content: center;
align-content: center;
&:hover {
border: 1px solid blue;
cursor: pointer;
transform: translateY(-5px);
}
}
}
#size-input {
select {
padding: 5px;
}
& > div:first-child {
margin-bottom: 5px;
}
}
+85
View File
@@ -0,0 +1,85 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<style>
:root {
--StatusBar-currentHeight:
/*{ StatusBar.currentHeight }*/
;
--readerSettings-theme:
/*{ readerSettings.theme }*/
;
--readerSettings-padding:
/*{ readerSettings.padding }*/
;
--readerSettings-textSize:
/*{ readerSettings.textSize }*/
;
--readerSettings-textColor:
/*{ readerSettings.textColor }*/
;
--readerSettings-textAlign:
/*{ readerSettings.textAlign }*/
;
--readerSettings-lineHeight:
/*{ readerSettings.lineHeight }*/
;
--readerSettings-fontFamily:
/*{ readerSettings.fontFamily }*/
;
--theme-primary:
/*{ theme.primary }*/
;
--theme-onPrimary:
/*{ theme.onPrimary }*/
;
--theme-secondary:
/*{ theme.secondary }*/
;
--theme-onSecondary:
/*{ theme.onSecondary }*/
;
--theme-surface:
/*{ theme.surface }*/
;
--theme-surface-0-9:
/*{ theme.surface09 }*/
;
--theme-onSurface:
/*{ theme.onSurface }*/
;
--theme-outline:
/*{ theme.outline }*/
;
--chapterCtn-height:
/*{ layoutHeight }*/
;
}
body {
background-color: var(--readerSettings-theme);
}
/*{ fillCSS }*/
</style>
<style>
/*{ customCSS }*/
</style>
</head>
<body>
<div class="chapterCtn">
<chapter data-plugin-id='/*{ novel.pluginId }*/' data-novel-id='/*{ chapter.novelId }*/'
data-chapter-id='/*{ chapter.id }*/'>
/*{ html }*/
</chapter>
</div>
</body>
<script>
/*{ fillJS }*/
</script>
</body>
</html>
@@ -0,0 +1,59 @@
// This is an un-browserified version of the script! If you make any changes to this file you need to run
// npx browserify html-sanitize-nonbrowser.js -o html-sanitize.js
// for your changes to be visible inside of the browser!
const sanitizeHtml = require("sanitize-html");
/** @typedef {{removeExtraParagraphSpacing?: boolean}} Options */
const loadingGif =
"https://raw.githubusercontent.com/LNReader/lnreader/plugins/android/app/src/main/assets/images/loading.gif";
/**
*
* @param {string} html
* @param {Options?} options
*/
window.sanitizeChapterText = (html, options) => {
if (html) {
html = html.replace(/&lt;/g, "<").replace(/&gt;/g, ">");
}
let text = sanitizeHtml(html, {
allowedTags: sanitizeHtml.defaults.allowedTags.concat([
"img",
"i",
"em",
"b",
"a",
"div",
]),
allowedAttributes: {
img: ["src"],
a: ["href"],
},
allowedSchemes: ["data", "http", "https", "file"],
});
if (text) {
if (options?.removeExtraParagraphSpacing) {
text = text
.replace(/<\s*br[^>]*>/gi, "\n")
.replace(/\n{2,}/g, "\n\n");
}
const imgHandlerRegex = /<img([^>]*src="[^"]+"[^>]*)>/g;
const ttsHandlerRegex =
/(< *\w+ *>[^<.?!]+< *\/\w+ *>|< *a *href *= *"[^"]+" *>\s*(<img[^>]+>|[^<]+|(< *\w+ *>[^]+< *\/\w+ *>)*)\s*< *\/a *>|< *img[^>]+>|[^<>.?!]+[.?!])/g;
// first -> match whole tags which dont have attribute and [.?!] inside
// second -> match a tags and its childs
// third -> match img tags
// match sentence split by [.?!]
text = text
.replace(
imgHandlerRegex,
`<img alt="Plugin can't fetch this img" onload="reader.refresh()" onerror="this.setAttribute('error-src', this.src);reader.post({type:'error-img',data:this.src});this.src='${loadingGif}';this.onerror=undefined" $1>`
)
.replace(ttsHandlerRegex, "<t-t-s>$1</t-t-s>");
} else {
text = "HTML is empty";
}
return text;
};
File diff suppressed because one or more lines are too long
+1074 -320
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+4
View File
@@ -0,0 +1,4 @@
interface Window {
themes: Record<string, ThemeType>;
sanitizeChapterText(html: string, options?: Options);
}
+14
View File
@@ -0,0 +1,14 @@
// @ts-check
/** @typedef {{backgroundColor:string, textColor:string}[]} Theme */
/** @type {Theme} */
window.themes = [
{ backgroundColor: "#f5f5fa", textColor: "#111111" },
{ backgroundColor: "#F7DFC6", textColor: "#593100" },
{ backgroundColor: "#dce5e2", textColor: "#000000" },
{ backgroundColor: "#292832", textColor: "#CCCCCC" },
{
backgroundColor: "#000000",
textColor: "#FFFFFFB3",
},
];