refactor:日志打印级别改为debug
This commit is contained in:
parent
df5578f267
commit
d5e2b55c28
@ -4,14 +4,14 @@ chrome.runtime.onInstalled.addListener(() => {
|
||||
title: '添加到书签',
|
||||
id: "addBookmark",
|
||||
},
|
||||
() => console.log("创建右键菜单成功")
|
||||
() => console.debug("创建右键菜单成功")
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
|
||||
chrome.contextMenus.onClicked.addListener(async function (info, tab) {
|
||||
console.log(info, tab);
|
||||
console.debug(info, tab);
|
||||
let body = {
|
||||
name: tab.title,
|
||||
url: tab.url,
|
||||
@ -27,7 +27,7 @@ chrome.runtime.onMessage.addListener(async (data, sender, sendResponse) => {
|
||||
return;
|
||||
}
|
||||
sendResponse("ok");
|
||||
console.log("收到消息:", data, sender);
|
||||
console.debug("收到消息:", data, sender);
|
||||
if (data.code == 'setToken') {
|
||||
await setVal("token", data.data);
|
||||
// sendToContent
|
||||
@ -47,10 +47,10 @@ chrome.runtime.onMessage.addListener(async (data, sender, sendResponse) => {
|
||||
* @param {*} data
|
||||
*/
|
||||
function sendToContent (tabId, data) {
|
||||
console.log(tabId, data);
|
||||
console.debug(tabId, data);
|
||||
data.receiver = "content";
|
||||
chrome.tabs.sendMessage(tabId, data, res => {
|
||||
console.log("接受响应", res);
|
||||
console.debug("接受响应", res);
|
||||
})
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@ function sendToContent (tabId, data) {
|
||||
*/
|
||||
function sendToPopup (data) {
|
||||
data.receiver = "popup";
|
||||
chrome.runtime.sendMessage(data, res => console.log(res));
|
||||
chrome.runtime.sendMessage(data, res => console.debug(res));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,7 +72,7 @@ function sendToPopup (data) {
|
||||
function setVal (key, val) {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.storage.local.set({ [key]: val }, function () {
|
||||
console.log("设置值成功:", key, val)
|
||||
console.debug("设置值成功:", key, val)
|
||||
resolve();
|
||||
})
|
||||
})
|
||||
@ -87,11 +87,11 @@ function getVal (key) {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.storage.local.get([key], async function (res) {
|
||||
if (key === 'token' && !checkTokenValid(res[key])) {
|
||||
console.log("token过期");
|
||||
console.debug("token过期");
|
||||
await clearVal("token");
|
||||
res[key] = null;
|
||||
}
|
||||
console.log("取值成功", res);
|
||||
console.debug("取值成功", res);
|
||||
resolve(res[key]);
|
||||
})
|
||||
})
|
||||
@ -100,7 +100,7 @@ function getVal (key) {
|
||||
function clearVal (key) {
|
||||
return new Promise((resolve, reject) => {
|
||||
chrome.storage.local.remove(key, function () {
|
||||
console.log("remove成功", key);
|
||||
console.debug("remove成功", key);
|
||||
resolve();
|
||||
})
|
||||
})
|
||||
|
@ -1,5 +1,5 @@
|
||||
console.log("asdf");
|
||||
console.log(bookmarkHost);
|
||||
console.debug("asdf");
|
||||
console.debug(bookmarkHost);
|
||||
|
||||
var token;
|
||||
var login = document.getElementById("login");
|
||||
@ -14,7 +14,7 @@ var action = document.getElementById("action");
|
||||
let newestBlock = document.getElementById("newestVersion");
|
||||
newestBlock.href = bookmarkHost + "/static/bookmarkBrowserPlugin.zip";
|
||||
let res = await axios.get("/common/config/global");
|
||||
console.log(res);
|
||||
console.debug(res);
|
||||
newestBlock.innerText = res.data.data.map.pluginVersion;
|
||||
})();
|
||||
|
||||
@ -22,7 +22,7 @@ var action = document.getElementById("action");
|
||||
* 退出登陆
|
||||
*/
|
||||
document.getElementById("logout").addEventListener("click", () => {
|
||||
console.log("click");
|
||||
console.debug("click");
|
||||
sendToBg("clearToken", null);
|
||||
action.style.display = "none";
|
||||
login.style.display = "block";
|
||||
@ -33,7 +33,7 @@ document.getElementById("logout").addEventListener("click", () => {
|
||||
* @param {*} data
|
||||
*/
|
||||
function sendToBg (code, data) {
|
||||
chrome.runtime.sendMessage({ code, data, receiver: "background" }, res => console.log(res));
|
||||
chrome.runtime.sendMessage({ code, data, receiver: "background" }, res => console.debug(res));
|
||||
}
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ chrome.runtime.onMessage.addListener(async (data, sender, sendResponse) => {
|
||||
return;
|
||||
}
|
||||
sendResponse("ok");
|
||||
console.log("popup收到消息:", data);
|
||||
console.debug("popup收到消息:", data);
|
||||
if (data.code == 'setToken') {
|
||||
token = data.data;
|
||||
if (token) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
console.log('注入了页面');
|
||||
console.debug('注入了页面');
|
||||
|
||||
var bookmarkInfo = null;
|
||||
var addBlockDiv = null;
|
||||
@ -8,11 +8,11 @@ var iframe = null;
|
||||
* 接收当前注入页面传来的消息
|
||||
*/
|
||||
window.addEventListener('message', function (event) {
|
||||
console.log(event);
|
||||
console.debug(event);
|
||||
if (event.data.code === undefined) {
|
||||
return;
|
||||
}
|
||||
console.log('接受到网页消息:', event.data);
|
||||
console.debug('接受到网页消息:', event.data);
|
||||
if (event.data.code === 'getBookmarkData') {
|
||||
iframe.contentWindow.postMessage({ code: "addBookmarkAction", data: bookmarkInfo }, "*");
|
||||
} else if (event.data.code === 'setToken') {
|
||||
@ -31,7 +31,7 @@ chrome.runtime.onMessage.addListener(async (data, sender, sendResponse) => {
|
||||
return;
|
||||
}
|
||||
sendResponse("ok");
|
||||
console.log('收到消息:', data);
|
||||
console.debug('收到消息:', data);
|
||||
if (data.code == 'setTokenOk') {
|
||||
sendToPage(data);
|
||||
} else if (data.code == 'addBookmark') {
|
||||
@ -49,13 +49,13 @@ async function addBookmark (data) {
|
||||
try {
|
||||
if (data.data.iconUrl) {
|
||||
let icon = await axios.get(data.data.iconUrl, { responseType: 'arraybuffer' });
|
||||
console.log(JSON.stringify(new Uint8Array(icon.data)));
|
||||
console.debug(JSON.stringify(new Uint8Array(icon.data)));
|
||||
data.data.icon = `data:` + icon.headers['content-type'] + ';base64,' + window.btoa(String.fromCharCode(...new Uint8Array(icon.data)));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
console.log("新增书签", data.data);
|
||||
console.debug("新增书签", data.data);
|
||||
bookmarkInfo = data.data;
|
||||
addBlockDiv = document.createElement("div");
|
||||
addBlockDiv.setAttribute("style", "position:fixed;width:100%;height:100vh;z-index:100000;left:0;top:0;background:rgba(211, 211, 205, 0.8)");
|
||||
@ -73,7 +73,7 @@ async function addBookmark (data) {
|
||||
function sendToBg (data) {
|
||||
data.receiver = "background";
|
||||
chrome.runtime.sendMessage(data, response => {
|
||||
console.log(response);
|
||||
console.debug(response);
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user