Skip to content

Commit

Permalink
update Bing wallpaper cross -domain method
Browse files Browse the repository at this point in the history
  • Loading branch information
Cp0204 committed May 2, 2024
1 parent 1f11bae commit 8c2f4d1
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/mod/bing-wallpaper-v2/mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
// The official API cannot cross the domain
// https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN
const mkt = mapLanguageCode(localStorage.getItem('lang'));
const apiUrl = `https://bing.biturl.top/?resolution=1920&format=json&index=0&mkt=${mkt}`;
let apiUrl = `https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=${mkt}`;
apiUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(apiUrl)}`;
fetch(apiUrl)
.then(response => response.json())
.then(data => {
// 改壁纸
// Change wallpaper
const imageUrl = data.url;
const imageUrl = `https://www.bing.com${data.images[0].url}`;
console.log("Bing Wallpaper URL:", imageUrl);
const bgElement = document.querySelector(observedAnchor);
bgElement.style.backgroundImage = `url("${imageUrl}")`;
Expand All @@ -26,7 +27,7 @@
// 添加右键菜单
// Add right-click menu
const menuElement = document.querySelector(".dropdown-content");
const htmlString = `<a class="dropdown-item is-flex is-align-items-center" target="_blank" style="width:250px;white-space:normal;" href="${data.copyright_link}">${data.copyright}</a>`;
const htmlString = `<a class="dropdown-item is-flex is-align-items-center" target="_blank" style="width:250px;white-space:normal;" href="${data.images[0].copyrightlink}">${data.images[0].copyright}</a>`;
menuElement.insertAdjacentHTML("beforeend", htmlString)
})
.catch(error => {
Expand Down

0 comments on commit 8c2f4d1

Please sign in to comment.