hexo-theme-shokax 0.4.25 → 0.5.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -31
- package/UsageRestrictions.md +2 -2
- package/_config.yml +11 -25
- package/_images.yml +0 -7
- package/eslint.config.mjs +4 -5
- package/layout/_mixin/card.pug +1 -2
- package/layout/_mixin/comment.pug +0 -1
- package/layout/_mixin/segment.pug +1 -1
- package/layout/_partials/footer.pug +1 -4
- package/layout/_partials/head/head.pug +0 -8
- package/layout/_partials/head/pwa.pug +1 -1
- package/layout/_partials/header.pug +0 -1
- package/layout/_partials/layout.pug +4 -14
- package/layout/_partials/post/footer.pug +0 -2
- package/layout/_partials/post/post.pug +1 -2
- package/layout/_partials/post/reward.pug +1 -1
- package/layout/_partials/sidebar/overview.pug +0 -2
- package/layout/_partials/third-party/baidu-analytics.pug +1 -1
- package/layout/_partials/third-party/google-analytics.pug +1 -1
- package/layout/archive.pug +3 -0
- package/layout/category.pug +3 -0
- package/layout/index.pug +3 -0
- package/layout/page.pug +7 -0
- package/layout/post.pug +8 -0
- package/layout/tag.pug +3 -0
- package/package.json +9 -10
- package/scripts/filters/post.js +1 -1
- package/scripts/generaters/config.js +12 -7
- package/scripts/generaters/images.js +9 -8
- package/scripts/generaters/index.js +57 -44
- package/scripts/generaters/script.js +18 -33
- package/scripts/helpers/engine.js +2 -7
- package/scripts/plugin/index.js +32 -69
- package/scripts/tags/media.js +1 -1
- package/source/css/app.styl +0 -13
- package/source/css/page.styl +3 -0
- package/source/css/post.styl +5 -0
- package/source/css/scaffolding.styl +5 -0
- package/source/js/_app/components/comments.ts +2 -3
- package/source/js/_app/components/sidebar.ts +35 -35
- package/source/js/_app/components/tcomments.ts +0 -1
- package/source/js/_app/globals/globalVars.ts +0 -15
- package/source/js/_app/globals/handles.ts +9 -9
- package/source/js/_app/globals/themeColor.ts +5 -6
- package/source/js/_app/globals/thirdparty.ts +2 -2
- package/source/js/_app/globals/tools.ts +4 -6
- package/source/js/_app/library/anime.ts +30 -19
- package/source/js/_app/library/declare.d.ts +0 -5
- package/source/js/_app/library/proto.ts +0 -67
- package/source/js/_app/library/vue.ts +7 -7
- package/source/js/_app/page/common.ts +8 -10
- package/source/js/_app/page/fancybox.ts +6 -8
- package/source/js/_app/page/post.ts +42 -54
- package/source/js/_app/page/search.ts +1 -6
- package/source/js/_app/page/tab.ts +8 -9
- package/source/js/_app/pjax/domInit.ts +19 -14
- package/source/js/_app/pjax/refresh.ts +8 -36
- package/source/js/_app/pjax/siteInit.ts +13 -42
- package/source/js/_app/player.ts +14 -798
- package/toolbox/compiler.mjs +20 -48
- package/toolbox/dev-version.mjs +14 -0
- package/README_en.MD +0 -71
- package/scripts/plugin/lib/injects-point.js +0 -41
- package/scripts/plugin/lib/injects.js +0 -105
- package/source/js/_app/library/dom.ts +0 -28
- package/source/js/_app/library/loadFile.ts +0 -47
- package/source/js/_app/library/scriptPjax.ts +0 -56
- package/source/js/_app/library/storage.ts +0 -12
package/toolbox/compiler.mjs
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
/*
|
2
2
|
ShokaX ToolBox - Compiler
|
3
|
-
compatibility: ShokaX v0.
|
3
|
+
compatibility: ShokaX v0.5.x-dev
|
4
4
|
*/
|
5
|
-
import path from "node:path";
|
6
5
|
import fs from 'fs/promises'
|
7
|
-
import child_process from 'child_process'
|
8
6
|
import { buildSync } from 'esbuild'
|
9
7
|
import { glob } from 'glob'
|
10
8
|
|
11
9
|
const CONFIG = {
|
12
|
-
|
10
|
+
|
13
11
|
}
|
14
12
|
|
15
13
|
console.log('ShokaX ToolBox - Compiler')
|
@@ -18,50 +16,24 @@ console.log('Start compiling...')
|
|
18
16
|
const entryPoints = await glob('./scripts/**/*.ts');
|
19
17
|
const jsons = await glob('./scripts/**/*.json');
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
for (const entry of jsons) {
|
40
|
-
await fs.unlink(entry)
|
41
|
-
}
|
42
|
-
console.log('Finished compiling.')
|
43
|
-
})
|
44
|
-
})
|
45
|
-
} else {
|
46
|
-
console.log('RUN THIS SCRIPT IN YOUR SHOKAX THEME ROOT DIRECTORY!')
|
47
|
-
console.log('Using esbuild compiler...')
|
48
|
-
buildSync({
|
49
|
-
entryPoints: entryPoints,
|
50
|
-
outdir: 'scripts',
|
51
|
-
bundle: false,
|
52
|
-
format: 'cjs',
|
53
|
-
target: ['esnext'],
|
54
|
-
platform: 'node',
|
55
|
-
loader: { '.ts': 'ts' },
|
56
|
-
})
|
57
|
-
entryPoints.forEach(async (entry) => {
|
58
|
-
await fs.unlink(entry)
|
59
|
-
})
|
60
|
-
jsons.forEach(async (entry)=>{
|
61
|
-
await fs.unlink(entry)
|
62
|
-
})
|
63
|
-
console.log('Finished compiling.')
|
64
|
-
}
|
19
|
+
console.log('RUN THIS SCRIPT IN YOUR SHOKAX THEME ROOT DIRECTORY!')
|
20
|
+
console.log('Using esbuild compiler...')
|
21
|
+
buildSync({
|
22
|
+
entryPoints: entryPoints,
|
23
|
+
outdir: 'scripts',
|
24
|
+
bundle: false,
|
25
|
+
format: 'cjs',
|
26
|
+
target: ['esnext'],
|
27
|
+
platform: 'node',
|
28
|
+
loader: { '.ts': 'ts' },
|
29
|
+
})
|
30
|
+
entryPoints.forEach(async (entry) => {
|
31
|
+
await fs.unlink(entry)
|
32
|
+
})
|
33
|
+
jsons.forEach(async (entry)=>{
|
34
|
+
await fs.unlink(entry)
|
35
|
+
})
|
36
|
+
console.log('Finished compiling.')
|
65
37
|
|
66
38
|
console.log('Done.')
|
67
39
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import fs from 'node:fs';
|
2
|
+
import { execSync } from 'child_process';
|
3
|
+
|
4
|
+
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf-8'));
|
5
|
+
const currentVersion = packageJson.version;
|
6
|
+
|
7
|
+
const shortHash = execSync('git rev-parse --short HEAD').toString().trim();
|
8
|
+
|
9
|
+
const newVersion = `${currentVersion}-dev-${shortHash}`;
|
10
|
+
|
11
|
+
packageJson.version = newVersion;
|
12
|
+
fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 4));
|
13
|
+
|
14
|
+
console.log(`Updated package version to ${newVersion}`);
|
package/README_en.MD
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# hexo-theme-shokaX
|
2
|
-

|
3
|
-

|
4
|
-

|
5
|
-

|
6
|
-
|
7
|
-
#### Language: Simplified Chinese | [English](./README_en.MD) \
|
8
|
-
This project is a secondary development version of Shoka (considered a spiritual successor), dedicated to improving performance and optimizing the custom modification experience. \
|
9
|
-
The reason for its creation is that Shoka hasn't been updated for three years, accumulating a large number of bugs and feature requests.
|
10
|
-
|
11
|
-
ShokaX's community resource guide and plugin repository can be found at [awesome-shokaX](https://github.com/theme-shoka-x/awesome-shokaX).
|
12
|
-
|
13
|
-
## 💬 Differences from Shoka
|
14
|
-
The original Shoka used javascript+Native+nunjucks technology, \
|
15
|
-
while ShokaX uses typescript+Vue 3+Pug technology. \
|
16
|
-
Many inaccessible CDN links have been changed.
|
17
|
-
|
18
|
-
## ✨ Feature List
|
19
|
-
|
20
|
-
| Feature Name | Status | Feature Name | Status |
|
21
|
-
|:--------------------------------:|:------:|:----------------------------:|:------:|
|
22
|
-
| PWA Support | ✅ | JSD Split | ✅ |
|
23
|
-
| API Injection | ✅ | Community Plugin System | ✅ |
|
24
|
-
| Custom Fonts | ✅* | Custom Styles | ✅* |
|
25
|
-
| Multiple Comment Systems Support | ✅ | AI-Generated Article Summary | 🔬 |
|
26
|
-
| Footer Record Number | ✅ | Custom Footer | ✅* |
|
27
|
-
| CSS Gradient Cover | ✅ | Typescript Support | ✅ |
|
28
|
-
|
29
|
-
Notes:
|
30
|
-
- *: Requires API injection
|
31
|
-
- 🔬: Experimental, may have issues
|
32
|
-
|
33
|
-
## 🔧 How to Install?
|
34
|
-
Note: This project requires node.js version 18.x or higher to run. \
|
35
|
-
See the [installation guide](https://docs-hexo.shokax.top/getting-started/) in the documentation.
|
36
|
-
|
37
|
-
## 📚 Sub-Projects
|
38
|
-
- [ShokaX docs](https://github.com/theme-shoka-x/shokaX-docs) ShokaX theme documentation (currently being written, feel free to join!)
|
39
|
-
- [HRMNMI](https://github.com/theme-shoka-x/hexo-renderer-multi-next-markdown-it) Markdown renderer used by ShokaX (awaiting refactoring)
|
40
|
-
- [ShokaX Pjax](https://github.com/theme-shoka-x/theme-shokax-pjax) Efficient Pjax implementation provided by ShokaX
|
41
|
-
- [ShokaX Anime](https://github.com/theme-shoka-x/theme-shokax-anime) Simplified version of Anime.js provided by ShokaX
|
42
|
-
|
43
|
-
# [License](https://github.com/theme-shoka-x/hexo-theme-shokaX/blob/main/LICENSE)
|
44
|
-
License: AGPL 3 or later
|
45
|
-
|
46
|
-
## Special Notes
|
47
|
-
The AGPL license primarily aims to restrict modified distribution behavior to avoid unauthorized secondary modifications and commercial packaging. \
|
48
|
-
Any modifications to the source code **must** be open-sourced because, according to the AGPL license, building a website requires the modified portions to be open-sourced.
|
49
|
-
|
50
|
-
## Special Usage Instructions
|
51
|
-
According to AGPLv3 Section 7, we have added some additional terms: \
|
52
|
-
Please see [Usage Restrictions](./UsageRestrictions.md). By using ShokaX, you acknowledge this file's content.
|
53
|
-
|
54
|
-
# Acknowledgements
|
55
|
-
## Open Source Projects
|
56
|
-
| Name | Author | Description |
|
57
|
-
|:----------------:|:-----------------:|:--------------------------------------------:|
|
58
|
-
| Hexo | Hexo contributors | Provided a great foundation for this project |
|
59
|
-
| hexo-theme-shoka | amehime | Parent theme of this project |
|
60
|
-
|
61
|
-
## Developers
|
62
|
-
Hexo theme: \
|
63
|
-
[](https://github.com/theme-shoka-x/hexo-theme-shokaX/graphs/contributors) \
|
64
|
-
ShokaX documentation: \
|
65
|
-
[](https://github.com/theme-shoka-x/shokaX-docs/graphs/contributors)
|
66
|
-
|
67
|
-
## Special Thanks
|
68
|
-
[<img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" width="25%">](https://jb.gg/OpenSourceSupport)
|
69
|
-
|
70
|
-
## Other Information
|
71
|
-

|
@@ -1,41 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var injects_point_exports = {};
|
20
|
-
__export(injects_point_exports, {
|
21
|
-
default: () => injects_point_default
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(injects_point_exports);
|
24
|
-
var injects_point_default = {
|
25
|
-
views: [
|
26
|
-
"head",
|
27
|
-
"sidebar",
|
28
|
-
"rightNav",
|
29
|
-
"postMeta",
|
30
|
-
"postBodyEnd",
|
31
|
-
"footer",
|
32
|
-
"bodyEnd",
|
33
|
-
"comment",
|
34
|
-
"status"
|
35
|
-
],
|
36
|
-
styles: [
|
37
|
-
"variable",
|
38
|
-
"mixin",
|
39
|
-
"style"
|
40
|
-
]
|
41
|
-
};
|
@@ -1,105 +0,0 @@
|
|
1
|
-
var __create = Object.create;
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
8
|
-
for (var name in all)
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
-
};
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
-
for (let key of __getOwnPropNames(from))
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var injects_exports = {};
|
29
|
-
__export(injects_exports, {
|
30
|
-
default: () => injects_default
|
31
|
-
});
|
32
|
-
module.exports = __toCommonJS(injects_exports);
|
33
|
-
var import_node_fs = __toESM(require("node:fs"));
|
34
|
-
var import_node_path = __toESM(require("node:path"));
|
35
|
-
var import_injects_point = __toESM(require("./injects-point"));
|
36
|
-
/*!
|
37
|
-
inject.js in next-theme/hexo-theme-next by next-theme
|
38
|
-
under GNU AFFERO GENERAL PUBLIC LICENSE v3.0 OR LATER
|
39
|
-
https://github.com/next-theme/hexo-theme-next/blob/master/LICENSE.md
|
40
|
-
*/
|
41
|
-
const defaultExtname = ".pug";
|
42
|
-
class StylusInject {
|
43
|
-
files;
|
44
|
-
base_dir;
|
45
|
-
constructor(base_dir) {
|
46
|
-
this.base_dir = base_dir;
|
47
|
-
this.files = [];
|
48
|
-
}
|
49
|
-
push(file) {
|
50
|
-
this.files.push(import_node_path.default.resolve(this.base_dir, file));
|
51
|
-
}
|
52
|
-
}
|
53
|
-
class ViewInject {
|
54
|
-
base_dir;
|
55
|
-
raws;
|
56
|
-
constructor(base_dir) {
|
57
|
-
this.base_dir = base_dir;
|
58
|
-
this.raws = [];
|
59
|
-
}
|
60
|
-
raw(name, raw, ...args) {
|
61
|
-
if (import_node_path.default.extname(name) === "") {
|
62
|
-
name += defaultExtname;
|
63
|
-
}
|
64
|
-
this.raws.push({ name, raw, args });
|
65
|
-
}
|
66
|
-
file(name, file, ...args) {
|
67
|
-
if (import_node_path.default.extname(name) === "") {
|
68
|
-
name += import_node_path.default.extname(file);
|
69
|
-
}
|
70
|
-
this.raw(name, import_node_fs.default.readFileSync(import_node_path.default.resolve(this.base_dir, file), "utf8"), ...args);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
function initInject(base_dir) {
|
74
|
-
const injects = {};
|
75
|
-
import_injects_point.default.styles.forEach((item) => {
|
76
|
-
injects[item] = new StylusInject(base_dir);
|
77
|
-
});
|
78
|
-
import_injects_point.default.views.forEach((item) => {
|
79
|
-
injects[item] = new ViewInject(base_dir);
|
80
|
-
});
|
81
|
-
return injects;
|
82
|
-
}
|
83
|
-
var injects_default = (hexo) => {
|
84
|
-
const injects = initInject(hexo.base_dir);
|
85
|
-
hexo.execFilterSync("theme_inject", injects);
|
86
|
-
hexo.theme.config.injects = {};
|
87
|
-
import_injects_point.default.styles.forEach((type) => {
|
88
|
-
hexo.theme.config.injects[type] = injects[type].files;
|
89
|
-
});
|
90
|
-
import_injects_point.default.views.forEach((type) => {
|
91
|
-
const configs = /* @__PURE__ */ Object.create(null);
|
92
|
-
hexo.theme.config.injects[type] = [];
|
93
|
-
injects[type].raws.forEach((injectObj, index) => {
|
94
|
-
const name = `inject/${type}/${injectObj.name}`;
|
95
|
-
hexo.theme.setView(name, injectObj.raw);
|
96
|
-
configs[name] = {
|
97
|
-
layout: name,
|
98
|
-
locals: injectObj.args[0],
|
99
|
-
options: injectObj.args[1],
|
100
|
-
order: injectObj.args[2] || index
|
101
|
-
};
|
102
|
-
});
|
103
|
-
hexo.theme.config.injects[type] = Object.values(configs).sort((x, y) => x.order - y.order);
|
104
|
-
});
|
105
|
-
};
|
@@ -1,28 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* 获取一个dom选择器对应的元素
|
3
|
-
* @deprecated Will be removed in the v0.5
|
4
|
-
*/
|
5
|
-
const $dom = (selector: string, element: Document = document): HTMLElement => {
|
6
|
-
// 在测试环境中这能优化0.01-0.02ms左右
|
7
|
-
if (selector[0] === '#') {
|
8
|
-
return <HTMLElement> element.getElementById(selector.substring(1))
|
9
|
-
}
|
10
|
-
return <HTMLElement> element.querySelector(selector)
|
11
|
-
}
|
12
|
-
|
13
|
-
/**
|
14
|
-
* 获取具有此选择器的所有dom节点
|
15
|
-
* @deprecated Will be removed in the v0.5
|
16
|
-
*/
|
17
|
-
$dom.all = (selector: string, element: Document = document): NodeListOf<HTMLElement> => {
|
18
|
-
return element.querySelectorAll(selector)
|
19
|
-
}
|
20
|
-
/**
|
21
|
-
* 获取具有此选择器的所有dom节点,并依次执行callback函数
|
22
|
-
* @deprecated Will be removed in the v0.5
|
23
|
-
*/
|
24
|
-
$dom.each = (selector: string, callback: (value: HTMLElement, key: number, parent: NodeListOf<Element>) => void, element?: Document): void => {
|
25
|
-
$dom.all(selector, element).forEach(callback)
|
26
|
-
}
|
27
|
-
|
28
|
-
export { $dom }
|
@@ -1,47 +0,0 @@
|
|
1
|
-
import { getScript } from './scriptPjax'
|
2
|
-
import { CONFIG } from '../globals/globalVars'
|
3
|
-
import { createChild } from './proto'
|
4
|
-
|
5
|
-
/**
|
6
|
-
* 用途是根据不同的资源名称和类型生成相应的资源 URL。
|
7
|
-
*/
|
8
|
-
const assetUrl = (asset: string, type: string): string => {
|
9
|
-
const str = CONFIG[asset][type].url as string
|
10
|
-
if (str.startsWith('https')) {
|
11
|
-
return str
|
12
|
-
}
|
13
|
-
if (str.startsWith('http')) {
|
14
|
-
console.warn(`Upgrade vendor ${asset}/${type} to HTTPS, Please use HTTPS url instead of HTTP url.`)
|
15
|
-
return str.replace('http', 'https')
|
16
|
-
}
|
17
|
-
return `/${str}`
|
18
|
-
}
|
19
|
-
|
20
|
-
export const vendorJs = (type: string, callback?: Function, condition?: string) => {
|
21
|
-
if (LOCAL[type]) {
|
22
|
-
getScript(assetUrl('js', type),CONFIG['js'][type].sri, callback || function () {
|
23
|
-
window[type] = true
|
24
|
-
}, condition || window[type])
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
export const vendorCss = (type: string, condition?: string): void => {
|
29
|
-
if (window['css' + type]) {
|
30
|
-
return
|
31
|
-
}
|
32
|
-
|
33
|
-
if (LOCAL[type]) {
|
34
|
-
const attr:any = {
|
35
|
-
rel: 'stylesheet',
|
36
|
-
href: assetUrl('css', type),
|
37
|
-
}
|
38
|
-
const vendor = CONFIG['css'][type] as vendorUrl
|
39
|
-
if (!vendor.local) {
|
40
|
-
attr.integrity = vendor.sri
|
41
|
-
attr.crossOrigin = 'anonymous'
|
42
|
-
}
|
43
|
-
createChild(document.head, 'link', attr)
|
44
|
-
|
45
|
-
window['css' + type] = true
|
46
|
-
}
|
47
|
-
}
|
@@ -1,56 +0,0 @@
|
|
1
|
-
export const getScript = (url: string,sri: string, callback?: Function, condition?: string): void => {
|
2
|
-
// url: 脚本文件的URL地址
|
3
|
-
// callback: 当脚本加载完成时要执行的回调函数
|
4
|
-
// condition: 可选的条件参数,如果存在,则执行callback
|
5
|
-
if (condition) {
|
6
|
-
// 如果条件存在,则执行回调函数
|
7
|
-
callback()
|
8
|
-
} else {
|
9
|
-
let script = document.createElement('script')
|
10
|
-
|
11
|
-
// @ts-ignore
|
12
|
-
script.onload = function (_, isAbort: boolean) {
|
13
|
-
// _: 事件对象
|
14
|
-
// isAbort: 是否中止
|
15
|
-
// @ts-ignore
|
16
|
-
if (isAbort || !script.readyState) {
|
17
|
-
console.log('abort!')
|
18
|
-
script.onload = null
|
19
|
-
script = undefined
|
20
|
-
if (!isAbort && callback) setTimeout(callback, 0)
|
21
|
-
}
|
22
|
-
}
|
23
|
-
script.src = url
|
24
|
-
script.integrity = sri
|
25
|
-
script.crossOrigin = 'anonymous'
|
26
|
-
document.head.appendChild(script)
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
export const pjaxScript = (element: HTMLScriptElement) => {
|
31
|
-
const { text, parentNode, id, className, type, src, dataset } = element
|
32
|
-
const code = text || element.textContent || element.innerHTML || ''
|
33
|
-
parentNode.removeChild(element)
|
34
|
-
const script = document.createElement('script')
|
35
|
-
if (id) {
|
36
|
-
script.id = id
|
37
|
-
}
|
38
|
-
if (className) {
|
39
|
-
script.className = className
|
40
|
-
}
|
41
|
-
if (type) {
|
42
|
-
script.type = type
|
43
|
-
}
|
44
|
-
if (src) {
|
45
|
-
// Force synchronous loading of peripheral JS.
|
46
|
-
script.src = src
|
47
|
-
script.async = false
|
48
|
-
}
|
49
|
-
if (dataset.pjax !== undefined) {
|
50
|
-
script.dataset.pjax = ''
|
51
|
-
}
|
52
|
-
if (code !== '') {
|
53
|
-
script.appendChild(document.createTextNode(code))
|
54
|
-
}
|
55
|
-
parentNode.appendChild(script)
|
56
|
-
}
|
@@ -1,12 +0,0 @@
|
|
1
|
-
// Html5LocalStorage的一个API
|
2
|
-
export const $storage = {
|
3
|
-
set (key: string, value: string): void {
|
4
|
-
localStorage.setItem(key, value)
|
5
|
-
},
|
6
|
-
get (key: string): string {
|
7
|
-
return localStorage.getItem(key)
|
8
|
-
},
|
9
|
-
del (key: string): void {
|
10
|
-
localStorage.removeItem(key)
|
11
|
-
}
|
12
|
-
}
|