Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
inkss committed Apr 13, 2022
1 parent d5272f0 commit 3773ed1
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions source/js/plugins/rightMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ const RightMenus = {
*/
writeClipImg: async (link, success, error) => {
try {
const data = await fetch(link);
// 如果使用了cdn的自适应Webp,png格式的图片会返回image/webp导致复制失败
// 伪装一个旧版本的Safari浏览器,同时添加time用以避免获取缓存文件
// 请求头里设置no-cache造成了莫名其妙的cors问题
const data = await fetch(`${link}?time=${Date.now()}`, {
mode: 'cors',
headers: {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0 Safari/605.1.15"
}
});
const blob = await data.blob();
await navigator.clipboard
.write([
Expand All @@ -66,10 +74,7 @@ const RightMenus = {
]).then(() => {
success(true);
}, (e) => {
if (blob.type !== 'image/png')
error(`当前文件类型不正确,不支持复制。`)
else
error(e);
error(blob.type !== 'image/png' ? '当前文件类型不正确,不支持复制。' : e);
});
} catch (e) {
error(e)
Expand Down Expand Up @@ -201,7 +206,7 @@ RightMenus.fun = (() => {
*/
fn.menuControl = (event) => {
fn.globalDataSet(event);
if(!!_menuMusic) _menuMusic.style.display = globalData.isShowMusic ? 'block' : 'none';
if (!!_menuMusic) _menuMusic.style.display = globalData.isShowMusic ? 'block' : 'none';
_rightMenuList.forEach(item => {
item.style.display = 'none';
const nodeName = item.firstElementChild.nodeName;
Expand Down

0 comments on commit 3773ed1

Please sign in to comment.