tona-loader 1.0.1
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/LICENSE +21 -0
- package/README.md +39 -0
- package/README.zh-CN.md +39 -0
- package/dist/loader.min.js +1 -0
- package/package.json +26 -0
- package/src/constants.ts +11 -0
- package/src/global.d.ts +11 -0
- package/src/helpers.ts +26 -0
- package/src/index.ts +5 -0
- package/src/loader.ts +30 -0
- package/src/types.ts +15 -0
- package/tsdown.config.ts +11 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 guangzan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# tona-loader
|
|
2
|
+
|
|
3
|
+
**English** | [中文](./README.zh-CN.md)
|
|
4
|
+
|
|
5
|
+
🚀 Loading theme js file for Tona.
|
|
6
|
+
|
|
7
|
+
Loader receives a configuration object, mounts the object to window, and then loads the corresponding theme file according to the `configurationObject.theme.name` in the incoming object.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
Load skins via theme name.
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script src="https://blog-static.cnblogs.com/files/guangzan/loader.min.js"></script>
|
|
15
|
+
<script>
|
|
16
|
+
const opts = {
|
|
17
|
+
theme: {
|
|
18
|
+
name: "geek",
|
|
19
|
+
},
|
|
20
|
+
// 其他配置
|
|
21
|
+
};
|
|
22
|
+
$.tona(opts);
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Load skins via theme URL.
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="https://blog-static.cnblogs.com/files/guangzan/loader.min.js"></script>
|
|
30
|
+
<script>
|
|
31
|
+
const opts = {
|
|
32
|
+
theme: {
|
|
33
|
+
name: "https://blog-static.cnblogs.com/files/guangzan/reacg.js",
|
|
34
|
+
},
|
|
35
|
+
// 其他配置
|
|
36
|
+
};
|
|
37
|
+
$.tona(opts);
|
|
38
|
+
</script>
|
|
39
|
+
```
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# tona-loader
|
|
2
|
+
|
|
3
|
+
**中文** | [English](./README.md)
|
|
4
|
+
|
|
5
|
+
🚀 Tona 博客园皮肤加载器。
|
|
6
|
+
|
|
7
|
+
Loader 接收一个配置对象,将该对象挂载到窗口,然后根据传入的配置对象中的 `configurationObject.theme` 加载相应的皮肤文件。
|
|
8
|
+
|
|
9
|
+
## 使用
|
|
10
|
+
|
|
11
|
+
通过皮肤名称加载皮肤。
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script src="https://blog-static.cnblogs.com/files/guangzan/loader.min.js"></script>
|
|
15
|
+
<script>
|
|
16
|
+
const opts = {
|
|
17
|
+
theme: {
|
|
18
|
+
name: "geek",
|
|
19
|
+
},
|
|
20
|
+
// 其他配置
|
|
21
|
+
};
|
|
22
|
+
$.tona(opts);
|
|
23
|
+
</script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
通过皮肤 URL 加载皮肤。
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<script src="https://blog-static.cnblogs.com/files/guangzan/loader.min.js"></script>
|
|
30
|
+
<script>
|
|
31
|
+
const opts = {
|
|
32
|
+
theme: {
|
|
33
|
+
name: "https://blog-static.cnblogs.com/files/guangzan/reacg.js",
|
|
34
|
+
},
|
|
35
|
+
// 其他配置
|
|
36
|
+
};
|
|
37
|
+
$.tona(opts);
|
|
38
|
+
</script>
|
|
39
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(){let e={acg:`reacg`,bilibiliv1:`bilibili`},t=(()=>{let e=document.currentScript.getAttribute(`src`);return e.substring(0,e.lastIndexOf(`/`))})();function n(e,t=()=>{}){$.ajax({type:`GET`,dataType:`script`,cache:!0,url:e,success:()=>t()})}function r(e){return/http/.test(e)}function i(e){window.opts=e}function a(e){return typeof e?.base?.theme==`string`?e.base.theme:typeof e?.theme?.name==`string`?e.theme.name:`acg`}function o(n){return r(n)?n:`${t}/${e[n]??n}.js`}async function s(e){i(e),n(o(a(e)))}$.extend({awesCnb:s}),window.theme=s,window.tona=s})();
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tona-loader",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.0.1",
|
|
5
|
+
"description": "Loading theme js file",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://hub.fastgit.org/guangzan/loader.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"博客园",
|
|
14
|
+
"皮肤"
|
|
15
|
+
],
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"@types/jquery": "^3.5.33",
|
|
19
|
+
"tsdown": "latest",
|
|
20
|
+
"vitest": "^4.0.16"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsdown",
|
|
24
|
+
"dev": "tsdown --watch"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const DEFAULT_THEME_NAME = 'acg'
|
|
2
|
+
export const LEGACY_THEME = {
|
|
3
|
+
acg: 'reacg',
|
|
4
|
+
bilibiliv1: 'bilibili',
|
|
5
|
+
}
|
|
6
|
+
export const BASE_URL = (() => {
|
|
7
|
+
const src = (document.currentScript as HTMLScriptElement).getAttribute(
|
|
8
|
+
'src',
|
|
9
|
+
) as string
|
|
10
|
+
return src.substring(0, src.lastIndexOf('/'))
|
|
11
|
+
})()
|
package/src/global.d.ts
ADDED
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const getType = (obj: any) => Object.prototype.toString.call(obj).slice(8, -1)
|
|
2
|
+
|
|
3
|
+
export function loadJSON(
|
|
4
|
+
url: string,
|
|
5
|
+
callback: (data: any) => void = () => {},
|
|
6
|
+
) {
|
|
7
|
+
$.getJSON(url, (data: any) => callback(data))
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function loadScript(url: string, callback: () => void = () => {}) {
|
|
11
|
+
$.ajax({
|
|
12
|
+
type: 'GET',
|
|
13
|
+
dataType: 'script',
|
|
14
|
+
cache: true,
|
|
15
|
+
url,
|
|
16
|
+
success: () => callback(),
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isURL(str: string): boolean {
|
|
21
|
+
return /http/.test(str)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function isString(obj: any): obj is string {
|
|
25
|
+
return getType(obj) === 'String'
|
|
26
|
+
}
|
package/src/index.ts
ADDED
package/src/loader.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BASE_URL, DEFAULT_THEME_NAME, LEGACY_THEME } from './constants'
|
|
2
|
+
import { isURL, loadScript } from './helpers'
|
|
3
|
+
import type { IOptions } from './types'
|
|
4
|
+
|
|
5
|
+
function mountOptions(options: IOptions) {
|
|
6
|
+
window.opts = options
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function getUserConfig(options: IOptions) {
|
|
10
|
+
if (typeof options?.base?.theme === 'string') {
|
|
11
|
+
return options.base.theme
|
|
12
|
+
}
|
|
13
|
+
if (typeof options?.theme?.name === 'string') {
|
|
14
|
+
return options.theme.name
|
|
15
|
+
}
|
|
16
|
+
return DEFAULT_THEME_NAME
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function ensureThemeUrl(theme: string) {
|
|
20
|
+
if (isURL(theme)) {
|
|
21
|
+
return theme
|
|
22
|
+
}
|
|
23
|
+
const _theme = LEGACY_THEME[theme as keyof typeof LEGACY_THEME] ?? theme
|
|
24
|
+
return `${BASE_URL}/${_theme}.js`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function loader(options: IOptions) {
|
|
28
|
+
mountOptions(options)
|
|
29
|
+
loadScript(ensureThemeUrl(getUserConfig(options)))
|
|
30
|
+
}
|
package/src/types.ts
ADDED