Prettier (#852)
* add prettier * lint-staged * prettier * upgrade husky
This commit is contained in:
@@ -1,91 +1,91 @@
|
||||
/** @ts-check */
|
||||
|
||||
class AccordionContent extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.gridElement = document.createElement("div");
|
||||
}
|
||||
get content() {
|
||||
return this.gridElement;
|
||||
}
|
||||
connectedCallback() {
|
||||
// create a div that'll animate the collapsing
|
||||
this.gridElement.append(...Array.from(this.childNodes));
|
||||
this.gridElement.classList.add("accordion-animation-content");
|
||||
this.innerHTML = "";
|
||||
this.append(this.gridElement);
|
||||
}
|
||||
}
|
||||
|
||||
class AccordionHeader extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
console.log("contructor?");
|
||||
this.btn = document.createElement("button");
|
||||
}
|
||||
get html() {
|
||||
return this.btn.innerHTML;
|
||||
}
|
||||
set html(val) {
|
||||
this.btn.innerHTML = val;
|
||||
}
|
||||
get text() {
|
||||
return this.btn.innerText;
|
||||
}
|
||||
set text(val) {
|
||||
this.btn.innerText = val;
|
||||
}
|
||||
get parentBox() {
|
||||
return this.parentElement;
|
||||
}
|
||||
connectedCallback() {
|
||||
const childNodes = Array.from(this.childNodes);
|
||||
this.innerHTML = "";
|
||||
this.btn.append(...childNodes);
|
||||
this.append(this.btn);
|
||||
this.btn.addEventListener("click", this._btnClicked.bind(this));
|
||||
}
|
||||
_btnClicked() {
|
||||
this.parentBox?.toggle();
|
||||
}
|
||||
}
|
||||
|
||||
class AccordionBox extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
get collapsed() {
|
||||
return this.hasAttribute("collapsed");
|
||||
}
|
||||
set collapsed(val) {
|
||||
if (val) {
|
||||
this.setAttribute("collapsed", "");
|
||||
} else {
|
||||
this.removeAttribute("collapsed");
|
||||
}
|
||||
}
|
||||
toggle() {
|
||||
this.collapsed = !this.collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
class Accordion extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
window.customElements.define("main-accordion", Accordion);
|
||||
window.customElements.define("accordion-box", AccordionBox);
|
||||
window.customElements.define("accordion-header", AccordionHeader);
|
||||
window.customElements.define("accordion-content", AccordionContent);
|
||||
|
||||
// Export types for use in index.js
|
||||
const module = {};
|
||||
|
||||
module.exports = {
|
||||
AccordionBox,
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionHeader,
|
||||
};
|
||||
/** @ts-check */
|
||||
|
||||
class AccordionContent extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
this.gridElement = document.createElement('div');
|
||||
}
|
||||
get content() {
|
||||
return this.gridElement;
|
||||
}
|
||||
connectedCallback() {
|
||||
// create a div that'll animate the collapsing
|
||||
this.gridElement.append(...Array.from(this.childNodes));
|
||||
this.gridElement.classList.add('accordion-animation-content');
|
||||
this.innerHTML = '';
|
||||
this.append(this.gridElement);
|
||||
}
|
||||
}
|
||||
|
||||
class AccordionHeader extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
console.log('contructor?');
|
||||
this.btn = document.createElement('button');
|
||||
}
|
||||
get html() {
|
||||
return this.btn.innerHTML;
|
||||
}
|
||||
set html(val) {
|
||||
this.btn.innerHTML = val;
|
||||
}
|
||||
get text() {
|
||||
return this.btn.innerText;
|
||||
}
|
||||
set text(val) {
|
||||
this.btn.innerText = val;
|
||||
}
|
||||
get parentBox() {
|
||||
return this.parentElement;
|
||||
}
|
||||
connectedCallback() {
|
||||
const childNodes = Array.from(this.childNodes);
|
||||
this.innerHTML = '';
|
||||
this.btn.append(...childNodes);
|
||||
this.append(this.btn);
|
||||
this.btn.addEventListener('click', this._btnClicked.bind(this));
|
||||
}
|
||||
_btnClicked() {
|
||||
this.parentBox?.toggle();
|
||||
}
|
||||
}
|
||||
|
||||
class AccordionBox extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
get collapsed() {
|
||||
return this.hasAttribute('collapsed');
|
||||
}
|
||||
set collapsed(val) {
|
||||
if (val) {
|
||||
this.setAttribute('collapsed', '');
|
||||
} else {
|
||||
this.removeAttribute('collapsed');
|
||||
}
|
||||
}
|
||||
toggle() {
|
||||
this.collapsed = !this.collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
class Accordion extends HTMLElement {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
window.customElements.define('main-accordion', Accordion);
|
||||
window.customElements.define('accordion-box', AccordionBox);
|
||||
window.customElements.define('accordion-header', AccordionHeader);
|
||||
window.customElements.define('accordion-content', AccordionContent);
|
||||
|
||||
// Export types for use in index.js
|
||||
const module = {};
|
||||
|
||||
module.exports = {
|
||||
AccordionBox,
|
||||
Accordion,
|
||||
AccordionContent,
|
||||
AccordionHeader,
|
||||
};
|
||||
|
||||
Vendored
+5034
-9
File diff suppressed because one or more lines are too long
@@ -1,59 +1,57 @@
|
||||
// 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(/</g, "<").replace(/>/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;
|
||||
};
|
||||
// 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(/</g, '<').replace(/>/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;
|
||||
};
|
||||
|
||||
+14384
-12239
File diff suppressed because one or more lines are too long
+1618
-1661
File diff suppressed because it is too large
Load Diff
Vendored
+5594
-1
File diff suppressed because one or more lines are too long
+8765
-11
File diff suppressed because one or more lines are too long
+24179
-18759
File diff suppressed because it is too large
Load Diff
Vendored
+5
-5
@@ -1,5 +1,5 @@
|
||||
interface Window {
|
||||
themes: Record<string, ThemeType>;
|
||||
sanitizeChapterText(html: string, options?: Options);
|
||||
encodeHTML5(html: string, options?: Options);
|
||||
}
|
||||
interface Window {
|
||||
themes: Record<string, ThemeType>;
|
||||
sanitizeChapterText(html: string, options?: Options);
|
||||
encodeHTML5(html: string, options?: Options);
|
||||
}
|
||||
|
||||
@@ -1,14 +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",
|
||||
},
|
||||
];
|
||||
// @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',
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user