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
@@ -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);
}