Last active
November 29, 2023 08:45
-
-
Save hiepxanh/73fc9a242661e448d7fa44a06845405d to your computer and use it in GitHub Desktop.
lazy load file prism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// // this.loadFile('prism.css', 'prism-style'); | |
// // this.loadFile('prism.js', 'prism-script', 'script'); | |
// // https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+c+csharp+cpp+graphql+java+kotlin+markup-templating+php+python+ruby+scss+sql+swift+typescript+yaml&plugins=toolbar+copy-to-clipboard | |
loadFile(fileName: string, idName: string, mode: 'link' | 'script' = 'link') { | |
// for angular.json => if style go styles: [];, if script go scripts: [] | |
// { | |
// "input": "node_modules/quill/dist/quill.core.css", | |
// "inject": false, | |
// "bundleName": "quill.core" | |
// }, | |
// { | |
// "input": "node_modules/quill/dist/quill.snow.css", | |
// "inject": false, | |
// "bundleName": "quill.snow" | |
// } | |
const head = document.getElementsByTagName('head')[0]; | |
const themeLink = document.getElementById(idName ?? 'client-theme') as HTMLLinkElement; | |
if (themeLink) { | |
themeLink.href = fileName; | |
} else { | |
if (mode === 'link') { | |
const file = document.createElement('link'); | |
file.id = 'client-theme'; | |
file.rel = 'stylesheet'; | |
file.href = `${fileName}`; | |
head.appendChild(file); | |
} else { | |
const file = document.createElement('script'); | |
file.src = `${fileName}`; | |
head.appendChild(file); | |
} | |
} | |
} | |
buffChapter() { | |
const chapters = this.chaptersFacade.chaptersQuery.getAll(); | |
const list = prompt( | |
'chương đối tượng phải nằm trong danh sách bên dưới, dùng dấu cách để phân biệt số chương', | |
chapters | |
.slice(0, 5) | |
.map((chap) => chap.position) | |
.reverse() | |
.join(' '), | |
); | |
if (!list) return; | |
forkJoin( | |
chapters | |
.filter((chap) => list.split(' ').includes(chap.position + 1 + '')) | |
.map((chap) => | |
this.trackFacade.view( | |
this.chaptersFacade.chaptersQuery.getValue().currentBookId, | |
chap.chapterId, | |
Math.floor(Math.random() * 100) + 35, | |
Math.floor(Math.random() * 100) + 35, | |
), | |
), | |
).subscribe((results) => { | |
this.snackbarService.showSuccess('Đã buff ' + results.length + ' chương'); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment