Skip to content

Instantly share code, notes, and snippets.

@hiepxanh
Last active November 29, 2023 08:45
Show Gist options
  • Save hiepxanh/73fc9a242661e448d7fa44a06845405d to your computer and use it in GitHub Desktop.
Save hiepxanh/73fc9a242661e448d7fa44a06845405d to your computer and use it in GitHub Desktop.
lazy load file prism
// // 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