diff --git a/js/bg.js b/js/bg.js index 526d863..dc4a654 100644 --- a/js/bg.js +++ b/js/bg.js @@ -333,6 +333,8 @@ var OneClick = Class(ObjectClass, { browserStorage.set({ 'shortcut': s }); }, setIogo: function (tab, path) { + // const cvs = new OffscreenCanvas(32, 32); + // const ctx = cvs.getContext('2d'); browserStorage.get('buttonicon', (item) => { if (item.buttonicon) { // 图标按钮的样式,可以避免和其他扩展图标相同而分不清。 @@ -340,7 +342,7 @@ var OneClick = Class(ObjectClass, { const cvs = new OffscreenCanvas(32, 32); const ctx = cvs.getContext('2d'); - fetchImageBitmap(path, isFirefox, (imgBitmap) => { + fetchImageBitmap(path, notChrome, (imgBitmap) => { if (!imgBitmap) { console.error('Failed to load image'); return; @@ -369,9 +371,9 @@ var OneClick = Class(ObjectClass, { // }) // } // ) - const faviconPath = isFirefox ? "https://t3.gstatic.cn/faviconV2?client=SOCIAL&size=32&url=" + const faviconPath = notChrome ? "https://t3.gstatic.cn/faviconV2?client=SOCIAL&size=32&url=" + from_url.origin : faviconURL(from_url.origin, 32); - fetchImageBitmap(faviconPath, isFirefox, (oldImgBitmap) => { + fetchImageBitmap(faviconPath, notChrome, (oldImgBitmap) => { if (!oldImgBitmap) { console.error('Failed to load small image'); return; @@ -408,6 +410,14 @@ var OneClick = Class(ObjectClass, { } }); } else { + // fetchImageBitmap(path, notChrome, (imgBitmap) => { + // ctx.drawImage(imgBitmap, 0, 0, 32, 32); + // const imageData = ctx.getImageData(0, 0, 32, 32); + // chrome.action.setIcon({ + // imageData: { 32: imageData }, + // tabId: tab.id + // }); + // }) // safari chrome.action.setIcon({ path: { 32: path }, tabId: tab.id @@ -486,7 +496,7 @@ var OneClick = Class(ObjectClass, { start: function () { var the = this; chrome.tabs.onUpdated.addListener(function (tabId, change) { - if (change.status === "loading") { + if (change.status === (isSafari ? "compelte" : "loading")) { chrome.tabs.get(tabId, function (tab) { the.updateAction(tab); }); @@ -552,12 +562,15 @@ function faviconURL(u, s) { return url.toString(); } -function fetchImageBitmap(url, isFirefox, callback) { +function fetchImageBitmap(url, isCors, callback) { const pattern = /^(https?|chrome(-extension)?|file|filesystem):\/\//; // check url is a local file or not if (!pattern.test(url)) url = chrome.runtime.getURL(url); - fetch(url, { mode: isFirefox ? 'cors' : 'no-cors' }) + + + + fetch(url, { mode: isCors ? 'cors' : 'no-cors' }) .then(response => response.blob()) .then(blob => createImageBitmap(blob)) .then(bitmap => callback(bitmap)) diff --git a/js/easyswitch.js b/js/easyswitch.js index 6023b4f..f67988b 100644 --- a/js/easyswitch.js +++ b/js/easyswitch.js @@ -1,6 +1,7 @@ const userAgent = navigator.userAgent.toLowerCase(); const isFirefox = userAgent.indexOf('firefox') > -1; const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent); +const notChrome = isFirefox || isSafari; const browserStorage = isSafari ? chrome.storage.local : chrome.storage.sync; if (!isSafari) diff --git a/js/options.js b/js/options.js index a7d14fe..1a581e4 100644 --- a/js/options.js +++ b/js/options.js @@ -280,8 +280,6 @@ function addUserSiteClick() { } q = q[1]; - // 判断是否为firefox - const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; var favicon_url; const ico_size = 32; @@ -290,7 +288,7 @@ function addUserSiteClick() { const favicon_url2 = `https://t3.gstatic.cn/faviconV2?client=SOCIAL&size=${ico_size}&url=${home}`; const favicon_url3 = faviconURL(home, ico_size); - if (isFirefox) { + if (notChrome) { const controller = new AbortController(); const signal = controller.signal; const fetchTimeout = setTimeout(() => { @@ -441,6 +439,7 @@ function initWays() { const userAgent = navigator.userAgent.toLowerCase(); const isFirefox = userAgent.indexOf('firefox') > -1; const isSafari = /^((?!chrome|android).)*safari/i.test(userAgent); +const notChrome = isFirefox || isSafari; const browserStorage = isSafari ? chrome.storage.local : chrome.storage.sync; document.addEventListener("DOMContentLoaded", init, false); \ No newline at end of file diff --git a/manifest.json b/manifest.json index d373c1c..916dcef 100644 --- a/manifest.json +++ b/manifest.json @@ -6,10 +6,12 @@ "content_security_policy": { "extension_pages": "script-src 'self' ; object-src 'self'; img-src https://*.gstatic.com https://*.gstatic.cn;" }, + "author": "書", "description": "__MSG_description__", "icons": { "16": "asset/logo/icon_16x16.png", "32": "asset/logo/icon_32x32.png", + "64": "asset/logo/icon_64x64.png", "128": "asset/logo/icon_128x128.png", "256": "asset/logo/icon_256x256.png" }, @@ -23,6 +25,7 @@ "default_icon": { "16": "asset/logo/icon_16x16.png", "32": "asset/logo/icon_32x32.png", + "64": "asset/logo/icon_64x64.png", "128": "asset/logo/icon_128x128.png", "256": "asset/logo/icon_256x256.png" },