Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge #382

Closed
wants to merge 13 commits into from
Prev Previous commit
Next Next commit
最新提交避免跨域请求
  • Loading branch information
chenyinheng30 committed Nov 16, 2023
commit ad4429651ef33cacd1e423f715116d61f5cb8991
17 changes: 13 additions & 4 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
<div class="page home{{ if ne $posts.enable false }} posts{{ end }}">
<div id="weather"></div>
<script type="text/javascript">
function handleIpApi(ipData) {
var weatherElement = document.getElementById("weather");
weatherElement.innerHTML = `ip: ${ipData.query} ${ipData.city}`;
function handleApi(localData) {
var url = 'https://api.open-meteo.com/v1/forecast';
var params = new URLSearchParams();
params.append('latitude', localData.lat);
params.append('longitude', localData.lon);
params.append('current', 'temperature_2m');
fetch(`${url}?${params.toString()}`)
.then(response => response.json())
.then(weatherData => {
var weatherElement = document.getElementById("weather");
weatherElement.innerHTML = `实时气温:${weatherData.current.temperature_2m}&deg;C`;
})
}
</script>
<script type="application/javascript" src="https://request-cf.tenet.chat/?callback=handleIpApi"></script>
<script type="application/javascript" src="https://request-cf.tenet.chat/?Callback=handleApi"></script>

{{- /* Profile */ -}}
{{- if ne $profile.enable false -}}
Expand Down