move getUserInfo define to util.js
This commit is contained in:
15
globals.js
15
globals.js
@@ -14,21 +14,6 @@ if (typeof window.globalsLoaded === "undefined") {
|
|||||||
|
|
||||||
const CHECKBOX_CLASS = "conversation-checkbox";
|
const CHECKBOX_CLASS = "conversation-checkbox";
|
||||||
|
|
||||||
// Define getUserInfo function
|
|
||||||
function getUserInfo() {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
chrome.runtime.sendMessage({ action: "getUserInfo" }, (response) => {
|
|
||||||
if (chrome.runtime.lastError) {
|
|
||||||
reject(chrome.runtime.lastError);
|
|
||||||
} else if (response.error) {
|
|
||||||
reject(new Error(response.error));
|
|
||||||
} else {
|
|
||||||
resolve(response.userInfo);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expose variables to the global scope
|
// Expose variables to the global scope
|
||||||
window.Selectors = Selectors;
|
window.Selectors = Selectors;
|
||||||
window.shiftPressed = false;
|
window.shiftPressed = false;
|
||||||
|
|||||||
8
popup.js
8
popup.js
@@ -2,7 +2,7 @@ function loadGlobalsThenExecute(tabId, secondaryScript, callback) {
|
|||||||
chrome.scripting.executeScript(
|
chrome.scripting.executeScript(
|
||||||
{
|
{
|
||||||
target: { tabId: tabId },
|
target: { tabId: tabId },
|
||||||
files: ["globals.js"],
|
files: ["globals.js", "utils.js"],
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
chrome.scripting.executeScript(
|
chrome.scripting.executeScript(
|
||||||
@@ -37,8 +37,8 @@ function addButtonListener(buttonId, scriptName) {
|
|||||||
function updateProgressBar(progress) {
|
function updateProgressBar(progress) {
|
||||||
console.log("Updating progress bar:", progress);
|
console.log("Updating progress bar:", progress);
|
||||||
const bulkDeleteButton = document.getElementById("bulk-delete");
|
const bulkDeleteButton = document.getElementById("bulk-delete");
|
||||||
bulkDeleteButton.style.setProperty('--progress', `${progress}%`);
|
bulkDeleteButton.style.setProperty("--progress", `${progress}%`);
|
||||||
bulkDeleteButton.setAttribute('data-progress', progress);
|
bulkDeleteButton.setAttribute("data-progress", progress);
|
||||||
|
|
||||||
if (progress === 100 || progress === 0) {
|
if (progress === 100 || progress === 0) {
|
||||||
bulkDeleteButton.disabled = false;
|
bulkDeleteButton.disabled = false;
|
||||||
@@ -50,7 +50,7 @@ function updateProgressBar(progress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 在消息监听器中也添加文本重置
|
// 在消息监听器中也添加文本重置
|
||||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||||
console.log("Received message:", request);
|
console.log("Received message:", request);
|
||||||
if (request.action === "updateProgress") {
|
if (request.action === "updateProgress") {
|
||||||
updateProgressBar(request.progress);
|
updateProgressBar(request.progress);
|
||||||
|
|||||||
14
utils.js
14
utils.js
@@ -1,14 +1,14 @@
|
|||||||
|
// Define getUserInfo function
|
||||||
function getUserInfo() {
|
function getUserInfo() {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
chrome.identity.getProfileUserInfo({ accountStatus: "ANY" }, (userInfo) => {
|
chrome.runtime.sendMessage({ action: "getUserInfo" }, (response) => {
|
||||||
if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
console.error(chrome.runtime.lastError);
|
reject(chrome.runtime.lastError);
|
||||||
resolve(null);
|
} else if (response.error) {
|
||||||
|
reject(new Error(response.error));
|
||||||
} else {
|
} else {
|
||||||
resolve(userInfo);
|
resolve(response.userInfo);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.getUserInfo = getUserInfo;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user