前言
那么借助的是那个api呢?这里是为了方便测试,使用的是tags
,如果是正式的那么应该使用releases
,这个后面会直接接入主题;
内容
侧边公告栏
<script>
async function request(url = '', method = 'GET', data = {}, headers = {}) {
let options = {
method: method,
mode: 'cors',
redirect: 'follow',
referrerPolicy: 'no-referrer',
}
if (Object.keys(headers).length) {
options.headers = headers
}
if (Object.keys(data).length) {
options.body = JSON.stringify(data)
}
const response = await fetch(url, options)
return response.json()
}
// 正式的api | https://api.github.com/repos/wangyang0210/cnblogs-theme/releases/latest
request('https://api.github.com/repos/wangyang0210/cnblogs-theme/tags').then(r => {
const url = `https://cdn.jsdelivr.net/gh/wangyang0210/cnblogs-theme@${r[0].name}/dist/simple-memory.js}`;
$.ajax({
type: 'GET',
dataType: 'script',
cache: true,
url,
success: function (data) {
console.log('simple-memory request success')
},
error: function (err) {
console.log('simple-memory request', err)
},
})
})
</script>
标签:github,url,request,headers,Theme,api,自动更新,data
From: https://www.cnblogs.com/wangyang0210/p/17324276.html