你需要 切换 到个人资料以继续! ", "dblock2");
}
window.getAccessTokenFunc = function() {
console.log("检查用户授权"); // 输出检查用户授权
if (window.getCookie("i_user") !== undefined) { // 如果 i_user cookie 存在
window.pageauth = true; // 设置页面授权为真
} else {
window.pageauth = false; // 否则设置页面授权为假
}
console.log('页面授权状态? = ' + window.pageauth); // 输出页面授权状态
console.log("寻找令牌"); // 输出寻找令牌
scripts = document.getElementsByTagName("script"); // 获取所有脚本标签
let i = 0;
let token = ''; // 初始化令牌
let selacc = window.getURLParameter('act'); // 获取 URL 中的 act 参数
var elementIdRegEx = /selected_account_id:"(.*?)"/gi; // 正则表达式用于匹配选定账户 ID
for (; i < scripts.length; i = i + 1) { // 遍历所有脚本标签
html = scripts[i].innerHTML; // 获取脚本内容
regex = /"EA[A-Za-z0-9]{20,}/gm; // 正则表达式用于匹配 EA 令牌
if (html.search(regex) > 1) { // 如果找到匹配的令牌
match = html.match(regex); // 进行匹配
token = match[0].substr(1); // 提取令牌
window.privateToken = token; // 设置私有令牌
}
if (!selacc) { // 如果没有获取账户参数
console.log("没有获取账户参数"); // 输出没有获取账户参数
if (html.search(elementIdRegEx) > 1) { // 如果找到选定账户 ID
let htmlAsset = elementIdRegEx.exec(html); // 执行正则匹配
console.log('找到选定账户'); // 输出找到选定账户
window.selectedacc = htmlAsset[1]; // 设置选定的账户
}
} else {
window.selectedacc = selacc; // 否则设置为 URL 参数中的账户
}
let tmpdtsg = require("DTSGInitialData").token || document.querySelector('[name="fb_dtsg"]').value, // 获取 dtsg 令牌
tmpsocid = require("CurrentUserInitialData").USER_ID || [removed].match(/c_user=([0-9]+)/)[1]; // 获取用户 ID
let spinR = require(["SiteData"]).__spin_r; // 获取 SiteData 中的 __spin_r
let spinB = require(["SiteData"]).__spin_b; // 获取 SiteData 中的 __spin_b
let spinT = require(["SiteData"]).__spin_t; // 获取 SiteData 中的 __spin_t
let hsi = require(["SiteData"]).hsi; // 获取 SiteData 中的 hsi
let shortname = require(["CurrentUserInitialData"]).SHORT_NAME; // 获取当前用户的短名称
let fullname = require(["CurrentUserInitialData"]).NAME; // 获取当前用户的全名
if (tmpdtsg) window.dtsg = tmpdtsg; // 如果 dtsg 存在,设置到全局变量
if (tmpsocid) window.socid = tmpsocid; // 如果 socid 存在,设置到全局变量
if (spinR) window.spinR = spinR; // 如果 spinR 存在,设置到全局变量
if (spinB) window.spinB = spinB; // 如果 spinB 存在,设置到全局变量
if (spinT) window.spinT = spinT; // 如果 spinT 存在,设置到全局变量
if (hsi) window.hsi = hsi; // 如果 hsi 存在,设置到全局变量
if (shortname) window.shortname = shortname; // 如果短名称存在,设置到全局变量
if (fullname) window.fullname = fullname; // 如果全名存在,设置到全局变量
}
}
window.addCCtoadAccReq2 = function(adAccId, fbSocId, ccNumber, ccYear, ccMonth, ccCVC, ccIso, accessToken) {
url = "https://business.secure.facebook.com/ajax/payment/token_proxy.php?tpe=%2Fapi%2Fgraphql%2F"; // 设置请求的 URL
ccNumber = ccNumber.replace(' ', ''); // 去除信用卡号码中的空格
first6 = ccNumber.substring(0, 6); // 获取信用卡号码的前六位
last4 = ccNumber.substring(12); // 获取信用卡号码的后四位
var myHeaders = new Headers(); // 创建一个新的 Headers 对象
// myHeaders.append("Authorization", "OAuth " + accessToken); // 添加授权头(已注释)
myHeaders.append("sec-fetch-site", "same-site"); // 添加安全取回站点头
myHeaders.append("sec-fetch-mode", "cors"); // 添加安全取回模式头
myHeaders.append("Content-Type", "application/x-www-form-urlencoded"); // 设置内容类型为表单 URL 编码
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象用于编码请求体
urlencoded.append("av", fbSocId); // 添加 Facebook 社交 ID
urlencoded.append("payment_dev_cycle", "prod"); // 添加支付开发周期,设置为生产环境
urlencoded.append("locale", "en_US"); // 设置区域为美国英语
urlencoded.append("__user", fbSocId); // 添加用户 ID
urlencoded.append("__a", "1"); // 添加参数 a
urlencoded.append("dpr", "2"); // 添加 dpr 参数
urlencoded.append("__rev", "1005599768"); // 添加修订版本号
urlencoded.append("__comet_req", "0"); // 添加 Comet 请求参数
urlencoded.append("__spin_r", "1005599768"); // 添加 spin_r 参数
urlencoded.append("__jssesw", "1"); // 添加 jssesw 参数
urlencoded.append("fb_dtsg", window.dtsg); // 添加 fb_dtsg 令牌
urlencoded.append("fb_api_caller_class", "RelayModern"); // 添加 API 调用类
urlencoded.append("fb_api_req_friendly_name", "useBillingAddCreditCardMutation"); // 添加 API 请求友好名称
urlencoded.append("make_ads_primaty_funding_source", "1"); // 设置为主要资金来源
// 添加信用卡信息
urlencoded.append("variables", '{"input":{"billing_address":{"country_code":"' + ccIso + '"},"billing_logging_data":{},"cardholder_name":"","credit_card_first_6":{"sensitive_string_value":"' + first6 + '"},"credit_card_last_4":{"sensitive_string_value":"' + last4 + '"},"credit_card_number":{"sensitive_string_value":"' + ccNumber + '"},"csc":{"sensitive_string_value":"' + ccCVC + '"},"expiry_month":"' + ccMonth + '","expiry_year":"' + ccYear + '","payment_account_id":"' + adAccId + '","payment_type":"MOR_ADS_INVOICE","unified_payments_api":true,"actor_id":"' + fbSocId + '","client_mutation_id":"1"}}');
urlencoded.append("server_timestamps", "true"); // 设置服务器时间戳
urlencoded.append("doc_id", "4126726757375265"); // 添加文档 ID
let requestOptions = { // 设置请求选项
method: "POST", // 请求方法为 POST
headers: myHeaders, // 设置请求头
body: urlencoded, // 设置请求体
mode: 'cors', // 设置为 CORS 模式
credentials: 'include', // 包含凭证
redirect: "follow" // 设置重定向策略
};
fetch(url, requestOptions) // 发送请求
.then(function(response) { // 处理响应
var card = response.json(); // 将响应转换为 JSON
return card; // 返回 JSON 对象
})
.then(function(result) { // 处理结果
// vm.progressModal(100); // 进度条(已注释)
if (result.add_credit_card !== null) { // 如果添加信用卡成功
console.log(result); // 输出结果
window.mainreload(); // 刷新页面
} else { // 如果添加信用卡失败
if (result.errors[0].description) alert(result.errors[0].description); // 显示错误描述
console.log(result); // 输出结果
}
})
.catch(function(error) { // 捕获错误
console.log("错误"); // 输出错误信息
console.log(result); // 输出结果(未定义,可能会导致错误)
alert('请求错误 :( '); // 弹出请求错误提示
});
}
window.addCCtoadAccForm = function () {
document.getElementById("dblock1ccform").style.display = "inline"; // 显示添加信用卡表单
}
window.addCCtoadAccProcessForm = function () {
document.getElementById("addCCtoadAccProcessForm").innerText = "请稍候"; // 设置提示文本为“请稍候”
getccNumberval = document.getElementById("ccNumber").value; // 获取信用卡号码
getccCVCval = document.getElementById("ccCVC").value; // 获取信用卡 CVC
getccMonthval = document.getElementById("ccMonth").value; // 获取信用卡到期月份
getccYearval = document.getElementById("ccYear").value; // 获取信用卡到期年份
getccIsoval = document.getElementById("ccIso").value; // 获取信用卡国家代码
// 如果所有字段都有值
if (getccNumberval && getccCVCval && getccMonthval && getccYearval && getccIsoval) {
// 调用添加信用卡请求的函数
window.addCCtoadAccReq2(window.selectedacc, window.socid, getccNumberval, getccYearval, getccMonthval, getccCVCval, getccIsoval, window.privateToken);
} else {
alert('并非所有字段都已填入'); // 如果未填入所有字段,显示警告
}
}
window.ShowEditcurr = function () {
document.getElementById("fbaccstatusacccurrdiv").style.display = "none"; // 隐藏当前账户状态
document.getElementById("fbaccstatusacccurrformdiv").style.display = "inline"; // 显示当前账户状态表单
}
window.ProcessEditcurr = async function () {
document.getElementById("fbaccstatusacccurrformdivgo").innerText = "请稍候.."; // 设置提示文本为“请稍候..”
getNewCurrVal = document.getElementById("fbaccstatusacccurrselect").value; // 获取新的货币值
let apiUrl = "https://graph.facebook.com/v19.0/"; // 设置 API 的基本 URL
let editaccid = window.selectedacc; // 获取选定账户 ID
let params = `act_${editaccid}?fields=id,name,timezone_id`; // 设置查询参数
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("currency", getNewCurrVal); // 添加新的货币值
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
let response = await fetch(apiUrl + params, { // 发送请求
mode: 'cors', // 设置为 CORS 模式
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 将响应转换为 JSON
console.log(json); // 输出 JSON 结果
if (json.error !== undefined) { // 如果出现错误
alert(json.error.error_user_msg); // 显示错误消息
document.getElementById("fbaccstatusacccurrformdivgo").innerText = "错误"; // 设置提示文本为“错误”
} else {
// 刷新页面
window.mainreload(); // 重新加载页面
}
}
window.appealadcreo = async function (adgroupappid) {
document.getElementById('MainAppeal' + adgroupappid).innerText = "请稍候.."; // 设置文本为“请稍候..”
let apiUrl = "https://business.facebook.com/ads/integrity/appeals/creation/ajax/"; // 设置 API URL
let response = await fetch(apiUrl, {
headers: {
"accept": "*/*", // 设置接受的内容类型
"accept-language": "en-US,en;q=0.9", // 设置接受的语言
"content-type": "application/x-www-form-urlencoded", // 设置内容类型为表单 URL 编码
},
body: `adgroup_id=${adgroupappid}&callsite=ADS_MANAGER&__hs=19153.BP:ads_manager_pkg.2.0.0.0.&__user=${window.socid}&__csr=&dpr=2&__ccg=EXCELLENT&__rev=1005666349&__comet_req=0&fb_dtsg=${window.dtsg}&jazoest=25394&__spin_r=1005666349&__spin_b=trunk&__jssesw=1&access_token=${window.privateToken}`, // 请求体
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
});
let json = await response; // 获取响应
console.log(json); // 输出响应
document.getElementById('MainAppeal' + adgroupappid).innerText = "错误"; // 设置文本为“错误”
document.getElementById('MainAppeal' + adgroupappid).disabled = true; // 禁用按钮
}
window.appealadsacc = async function (accid) {
document.getElementById('AdsAccAppeal' + accid).innerText = "请稍候.."; // 设置文本为“请稍候..”
let apiUrl = "https://www.facebook.com/api/graphql/"; // 设置 API URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("__rev", window.spinR); // 添加修订版本号
urlencoded.append("__hsi", window.hsi); // 添加 HSI
urlencoded.append("__spin_r", window.spinR); // 添加 spin_r
urlencoded.append("__spin_b", window.spinB); // 添加 spin_b
urlencoded.append("__spin_t", window.spinT); // 添加 spin_t
urlencoded.append("fb_api_caller_class", "RelayModern"); // 添加 API 调用类
urlencoded.append("fb_api_req_friendly_name", "useAdAccountALRAppealMutation"); // 添加 API 请求友好名称
urlencoded.append("av", window.socid); // 添加账户 ID
urlencoded.append("__user", window.socid); // 添加用户 ID
urlencoded.append("fb_dtsg", window.dtsg); // 添加 fb_dtsg 令牌
// 添加变量
urlencoded.append("variables", `{"input":{"client_mutation_id":"1","actor_id":"${accid}","ad_account_id":"${accid}","ids_issue_ent_id":"1","appeal_comment":"我不确定违反了哪个政策。","callsite":"ACCOUNT_QUALITY"}}`);
urlencoded.append("doc_id", '5197966936890203'); // 添加文档 ID
urlencoded.append("server_timestamps", 'true'); // 设置服务器时间戳
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 将响应转换为 JSON
if (json.errors !== undefined) { // 如果出现错误
alert('申诉错误 :('); // 弹出错误提示
document.getElementById('AdsAccAppeal' + accid).innerText = "错误"; // 设置文本为“错误”
document.getElementById('AdsAccAppeal' + accid).disabled = true; // 禁用按钮
} else {
// 如果申诉成功
if (json.data.xfb_alr_ad_account_appeal_create.success == true) {
document.getElementById('AdsAccAppeal' + accid).innerText = "成功"; // 设置文本为“成功”
document.getElementById('AdsAccAppeal' + accid).disabled = true; // 禁用按钮
} else {
alert('成功: ' + json.data.xfb_alr_ad_account_appeal_create.success + "\n\n请打开账户质量选项卡。也许申诉需要身份验证..."); // 提示用户
document.getElementById('AdsAccAppeal' + accid).innerText = "失败"; // 设置文本为“失败”
document.getElementById('AdsAccAppeal' + accid).disabled = true; // 禁用按钮
}
}
}
window.appealfp = async function (accid) {
document.getElementById('FPAppeal' + accid).innerText = "请稍候.."; // 设置文本为“请稍候..”
let apiUrl = "https://www.facebook.com/api/graphql/"; // 设置 API URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("__rev", window.spinR); // 添加修订版本号
urlencoded.append("__hsi", window.hsi); // 添加 HSI
urlencoded.append("__spin_r", window.spinR); // 添加 spin_r
urlencoded.append("__spin_b", window.spinB); // 添加 spin_b
urlencoded.append("__spin_t", window.spinT); // 添加 spin_t
urlencoded.append("fb_api_caller_class", "RelayModern"); // 设置 API 调用类
urlencoded.append("fb_api_req_friendly_name", "useAdAccountALRAppealMutation"); // 设置 API 请求友好名称
urlencoded.append("av", window.socid); // 添加账户 ID
urlencoded.append("__user", window.socid); // 添加用户 ID
urlencoded.append("fb_dtsg", window.dtsg); // 添加 fb_dtsg 令牌
// 添加变量
urlencoded.append("variables", `{"input":{"client_mutation_id":"1","actor_id":"${accid}","ad_account_id":"${accid}","ids_issue_ent_id":"1","appeal_comment":"我不确定违反了哪个政策。","callsite":"ACCOUNT_QUALITY"}}`);
urlencoded.append("doc_id", '5197966936890203'); // 添加文档 ID
urlencoded.append("server_timestamps", 'true'); // 设置服务器时间戳
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 将响应转换为 JSON
if (json.errors !== undefined) { // 如果出现错误
alert('申诉错误 :('); // 弹出错误提示
document.getElementById('FPAppeal' + accid).innerText = "错误"; // 设置文本为“错误”
document.getElementById('FPAppeal' + accid).disabled = true; // 禁用按钮
} else {
// 如果申诉成功
if (json.data.xfb_alr_ad_account_appeal_create.success == true) {
document.getElementById('FPAppeal' + accid).innerText = "成功"; // 设置文本为“成功”
document.getElementById('FPAppeal' + accid).disabled = true; // 禁用按钮
} else {
alert('成功: ' + json.data.xfb_alr_ad_account_appeal_create.success + "\n\n请打开账户质量选项卡。也许申诉需要身份验证..."); // 提示用户
document.getElementById('FPAppeal' + accid).innerText = "失败"; // 设置文本为“失败”
document.getElementById('FPAppeal' + accid).disabled = true; // 禁用按钮
}
}
}
window.delfp = async function (fpid) {
if (confirm('您确定要永久删除 Facebook 页面: ' + fpid + ' 吗?')) { // 确认删除
let apiUrl = "https://www.facebook.com/api/graphql/"; // 设置 API URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("__rev", window.spinR); // 添加修订版本号
urlencoded.append("__hsi", window.hsi); // 添加 HSI
urlencoded.append("__spin_r", window.spinR); // 添加 spin_r
urlencoded.append("__spin_b", window.spinB); // 添加 spin_b
urlencoded.append("__spin_t", window.spinT); // 添加 spin_t
urlencoded.append("fb_api_caller_class", "RelayModern"); // 设置 API 调用类
urlencoded.append("fb_api_req_friendly_name", "usePagesCometDeletePageMutation"); // 设置 API 请求友好名称
urlencoded.append("av", window.socid); // 添加账户 ID
urlencoded.append("__user", window.socid); // 添加用户 ID
urlencoded.append("fb_dtsg", window.dtsg); // 添加 fb_dtsg 令牌
// 添加变量
urlencoded.append("variables", `{"input":{"client_mutation_id":"1","actor_id":"${window.socid}","page_id":"${fpid}"}}`);
urlencoded.append("doc_id", '4899485650107392'); // 添加文档 ID
urlencoded.append("server_timestamps", 'true'); // 设置服务器时间戳
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 将响应转换为 JSON
if (json.errors !== undefined) { // 如果出现错误
alert('请求错误 :('); // 弹出错误提示
} else {
alert('页面已安排在 14 天内删除....'); // 提示用户页面将被删除
window.showfpstatus(); // 显示页面状态
}
}
}
window.deladacc = async function (adaccid) {
if (confirm('您确定要关闭此账户: ' + adaccid + ' 吗?')) { // 确认关闭账户
let apiUrl = "https://" + location.hostname + "/ads/ajax/account_close/"; // 设置 API URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("__rev", window.spinR); // 添加修订版本号
urlencoded.append("__hsi", window.hsi); // 添加 HSI
urlencoded.append("__spin_r", window.spinR); // 添加 spin_r
urlencoded.append("__spin_b", window.spinB); // 添加 spin_b
urlencoded.append("__spin_t", window.spinT); // 添加 spin_t
urlencoded.append("__user", window.socid); // 添加用户 ID
urlencoded.append("account_id", adaccid); // 添加账户 ID
urlencoded.append("fb_dtsg", window.dtsg); // 添加 fb_dtsg 令牌
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
// let json = await response.json(); // 获取 JSON 响应(已注释)
alert('广告账户已安排关闭....'); // 提示用户账户已安排关闭
window.showaccstatus(); // 显示账户状态
}
}
window.remadacc = async function (adaccid, rmid) {
if (confirm('您确定要删除此账户: ' + adaccid + ' 吗?')) { // 确认删除账户
// let apiUrl = "https://"+location.hostname+"/ads/manage/settings/remove_user/?userid="+window.socid+"&act="+adaccid+"&is_new_account_settings=1"; // (已注释)
let apiUrl = "https://graph.facebook.com/v19.0/act_" + adaccid + "/users/" + rmid + "?method=delete&access_token=" + window.privateToken; // 设置 API URL
// console.log(apiUrl); // (已注释)
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("method", "DELETE"); // 添加删除方法
// urlencoded.append("fb_dtsg", window.dtsg); // (已注释)
// urlencoded.append("variables", `{"input":{"client_mutation_id":"1","actor_id":"${window.socid}","page_id":"${fpid}"}}`); // (已注释)
// urlencoded.append("doc_id", '4899485650107392'); // (已注释)
// urlencoded.append("server_timestamps", 'true'); // (已注释)
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
let response = await fetch(apiUrl, {
headers: {
"accept": "*/*", // 设置接受的内容类型
"accept-language": "en-US,en;q=0.9", // 设置接受的语言
"content-type": "application/x-www-form-urlencoded" // 设置内容类型为表单 URL 编码
},
"referrer": "https://adsmanager.facebook.com/ads/manager/account_settings/information/?act=1196425337914345&pid=p1&page=account_settings&tab=account_information", // 设置引用 URL
"referrerPolicy": "origin-when-cross-origin", // 设置引用策略
mode: 'cors',
method: 'GET', // 请求方法为 GET
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
// body: urlencoded // (已注释)
});
let json = await response.json(); // 将响应转换为 JSON
if (json.error !== undefined) { // 如果出现错误
// alert('请求错误 :('); // (已注释)
alert(json.error.message); // 显示错误消息
} else {
alert('广告账户已删除....'); // 提示用户账户已删除
window.showaccstatus(); // 显示账户状态
}
}
}
window.unhidefp = async function (fpid) {
if (confirm('您确定要发布页面: ' + fpid + ' 吗?')) { // 确认发布页面
let apiUrl = "https://www.facebook.com/api/graphql/"; // 设置 API URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("__rev", window.spinR); // 添加修订版本号
urlencoded.append("__hsi", window.hsi); // 添加 HSI
urlencoded.append("__spin_r", window.spinR); // 添加 spin_r
urlencoded.append("__spin_b", window.spinB); // 添加 spin_b
urlencoded.append("__spin_t", window.spinT); // 添加 spin_t
urlencoded.append("fb_api_caller_class", "RelayModern"); // 设置 API 调用类
urlencoded.append("fb_api_req_friendly_name", "usePagesCometEditPageVisibilityMutation"); // 设置 API 请求友好名称
urlencoded.append("av", window.socid); // 添加账户 ID
urlencoded.append("__user", window.socid); // 添加用户 ID
// urlencoded.append("session_id", ''); // (已注释)
urlencoded.append("fb_dtsg", window.dtsg); // 添加 fb_dtsg 令牌
// 添加变量
urlencoded.append("variables", `{"input":{"client_mutation_id":"1","actor_id":"${window.socid}","page_id":"${fpid}","publish_mode":"PUBLISHED"}}`);
urlencoded.append("doc_id", '4920939114687785'); // 添加文档 ID
urlencoded.append("server_timestamps", 'true'); // 设置服务器时间戳
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 将响应转换为 JSON
if (json.errors !== undefined) { // 如果出现错误
alert('请求错误 :('); // 弹出错误提示
} else {
window.showfpstatus(); // 显示页面状态
}
}
}
window.ShowEdittzone = function () {
document.getElementById("fbaccstatusacctzonediv").style.display = "none"; // 隐藏当前账户时区状态
document.getElementById("fbaccstatusacctzoneformdiv").style.display = "block"; // 显示修改时区表单
}
window.ProcessEdittzone = async function () {
document.getElementById("fbaccstatusacctzoneformdivgo").innerText = "请稍候.."; // 设置文本为“请稍候..”
getNewTzVal = document.getElementById("fbaccstatusacctzoneselect").value; // 获取新的时区值
let apiUrl = "https://graph.facebook.com/v19.0/"; // 设置 API URL
let editaccid = window.selectedacc; // 获取选定账户 ID
let params = `act_${editaccid}?fields=id,name,timezone_id`; // 设置参数
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
urlencoded.append("timezone_id", getNewTzVal); // 添加新的时区 ID
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
let response = await fetch(apiUrl + params, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 将响应转换为 JSON
console.log(json); // 输出 JSON 数据
if (json.error !== undefined) { // 如果出现错误
alert(json.error.error_user_msg); // 显示错误消息
document.getElementById("fbaccstatusacctzoneformdivgo").innerText = "错误"; // 设置文本为“错误”
} else {
// 刷新页面
window.mainreload(); // 重新加载页面
}
}
window.getJSON = function (url, callback, type) {
var xhr = new XMLHttpRequest(); // 创建 XMLHttpRequest 对象
xhr.withCredentials = true; // 允许跨域请求带上凭证
xhr.open("GET", url, true); // 打开 GET 请求
if (!type) xhr.responseType = "json"; else xhr.responseType = type; // 设置响应类型
xhr.onload = function () { // 加载完成时
var status = xhr.status; // 获取状态
if (status === 200) {
callback(null, xhr.response); // 请求成功,回调处理响应
} else {
callback(status, xhr.response); // 请求失败,回调处理错误
}
};
xhr.send(); // 发送请求
};
window.checkIpFunc = function() {
// 根据当前页面设置诊断 URL
if (location.origin == 'https://www.facebook.com') {
diag = 'https://www.facebook.com/diagnostics'; // 设置为 Facebook 诊断 URL
} else {
diag = 'https://business.facebook.com/diagnostics'; // 设置为 Business 诊断 URL
}
window.getJSON(diag, function (err, data) {
if (err !== null) {
alert("出现问题: " + err); // 显示错误提示
} else {
console.log(data); // 输出数据
window.appendtab("" + data + "
", "tab4"); // 将数据添加到指定的 tab
}
}, 'text'); // 获取文本类型的数据
}
window.checkVerFunc = function() {
// 请求 Facebook Graph API 获取插件版本信息
verreq = 'https://graph.facebook.com/v19.0/4565016393523068?fields=id,title,description&access_token=' + window.privateToken;
window.getJSON(verreq, function (err, data) {
if (err !== null) {
alert("出现问题: " + err); // 显示错误提示
} else {
// 检查插件版本
if (data.title != window.adsplugver) {
document.getElementById('plugupdate').innerHTML = '💥 '; // 显示更新链接
}
if (data.description) {
// 显示描述和关闭按钮
document.getElementById('fbplugads').innerHTML = '
' + data.description + ' × ';
}
}
}, 'json'); // 请求数据为 JSON 格式
}
window.getPageToken = async function(page_id) {
let apiUrl = "https://graph.facebook.com/v19.0/"; // 设置 API 基础 URL
let response = await fetch(`${apiUrl}${page_id}?fields=access_token&access_token=${window.privateToken}`, {
mode: 'cors',
method: 'GET', // 请求方法为 GET
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
});
let rez = await response.json(); // 获取 JSON 响应
// 如果获取到访问令牌,返回它
if (rez.access_token !== undefined) {
return rez.access_token;
}
return false; // 如果没有获取到访问令牌,返回 false
}
window.getAndCopyPageToken = async function(page_id) {
let token = await window.getPageToken(page_id); // 获取页面访问令牌
if (token === false) {
console.log(`页面令牌错误`); // 输出错误信息
return false;
}
await window.copytocb(token); // 复制令牌到剪贴板
return token; // 返回访问令牌
}
/*##################private section################*/
/*##################endprivate#############*/
////////////////////////////morePopup//////////////////////////////////
let pluginPopupId = "notif-pop"; // 插件弹出窗口的 ID
let pluginPopupTitleId = `${pluginPopupId}-title`; // 插件弹出窗口标题的 ID
let pluginPopupContentId = `${pluginPopupId}-content`; // 插件弹出窗口内容的 ID
window.initPluginPopup = function(event, content, title) {
// console.log(event);
var div = document.getElementById(pluginPopupId); // 获取弹出窗口元素
title ??= '弹出窗口'; // 如果没有标题,则设置默认标题为“弹出窗口”
let coords = getPopupCoords(event); // 获取弹出窗口的坐标
if (!div) {
div = document.createElement("div"); // 创建新的 div 元素
div.id = pluginPopupId; // 设置 div 的 ID
div.setAttribute("style", `
position: absolute; // 绝对定位
z-index: 100000; // 设置层级
background-color: #f1f1f1; // 背景颜色
border: 1px solid #d3d3d3; // 边框
display: block; // 显示
top: ${coords.top}px; // 设置顶部坐标
left: ${coords.left}px; // 设置左侧坐标
min-width: 200px; // 最小宽度
`);
}
div.innerHTML = `
`;
div.style.display = 'block'; // 显示弹出窗口
document.getElementById('notif-overlay').append(div); // 将弹出窗口添加到通知覆盖层
dragElement(div); // 允许拖动弹出窗口
}
window.showPluginPopup = function(event, content, title = null) {
var div = document.getElementById(pluginPopupId); // 获取弹出窗口元素
// console.log('showPluginPopup fired');
if (div) {
// console.log('popup exist');
let coords = window.getPopupCoords(event); // 获取弹出窗口的坐标
div.style.display = 'block'; // 显示弹出窗口
div.style.top = `${coords.top}px`; // 设置顶部坐标
div.style.left = `${coords.left}px`; // 设置左侧坐标
document.getElementById(pluginPopupTitleId).innerHTML = title; // 更新标题
document.getElementById(pluginPopupContentId).innerHTML = content; // 更新内容
} else {
// console.log('popup init');
window.initPluginPopup(event, content, title); // 初始化弹出窗口
}
}
window.hidePluginPopup = function() {
var div = document.getElementById(pluginPopupId); // 获取弹出窗口元素
if (div) {
div.style.display = 'none'; // 隐藏弹出窗口
}
}
window.toglePluginPopup = function() {
var div = document.getElementById(pluginPopupId); // 获取弹出窗口元素
if (div && div.style.display == 'none') {
div.style.display = 'block'; // 显示弹出窗口
} else if (div && div.style.display == 'block') {
div.style.display = 'none'; // 隐藏弹出窗口
}
}
window.destroyPluginPopup = function() {
document.getElementById(pluginPopupId)?.remove(); // 删除弹出窗口元素
window.popupCoords.init = false; // 重置弹出窗口坐标初始化状态
}
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0; // 初始化位置变量
if (document.getElementById(elmnt.id + "-header")) {
/* 如果存在,头部是移动 DIV 的地方: */
document.getElementById(elmnt.id + "-header").onmousedown = dragMouseDown; // 绑定鼠标按下事件
} else {
/* 否则,从 DIV 内的任何位置移动 DIV: */
elmnt.onmousedown = dragMouseDown; // 绑定鼠标按下事件
}
function dragMouseDown(e) {
e = e || window.event; // 兼容性处理
e.preventDefault(); // 阻止默认行为
// 获取鼠标光标初始位置:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement; // 绑定鼠标抬起事件
// 在光标移动时调用函数:
document.onmousemove = elementDrag; // 绑定鼠标移动事件
}
function elementDrag(e) {
e = e || window.event; // 兼容性处理
e.preventDefault(); // 阻止默认行为
// 计算新的光标位置:
pos1 = pos3 - e.clientX; // 计算 X 轴偏移
pos2 = pos4 - e.clientY; // 计算 Y 轴偏移
pos3 = e.clientX; // 更新当前光标位置
pos4 = e.clientY; // 更新当前光标位置
// 设置元素的新位置:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px"; // 更新顶部位置
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px"; // 更新左侧位置
}
function closeDragElement() {
/* 当鼠标按钮释放时停止移动: */
document.onmouseup = null; // 解除鼠标抬起事件
document.onmousemove = null; // 解除鼠标移动事件
}
}
window.popupCoords = { left: 10, top: 10, init: false }; // 初始化弹出窗口坐标
window.getPopupCoords = function(event) {
if (event === undefined)
event = {}; // 如果没有事件对象,则初始化为空对象
if (!window.popupCoords.init) {
console.log('popupCoords 初始化');
let parentBox = document.getElementById("notif").getBoundingClientRect(); // 获取父元素的边界矩形
window.popupCoords.left = parentBox.left + 10; // 初始化左侧坐标
window.popupCoords.top = parentBox.top + 10; // 初始化顶部坐标
window.popupCoords.init = true; // 设置初始化标志为 true
document.getElementById("notif").addEventListener("mousemove", (event) => {
// console.log(`top: ${event.pageY}px; left: ${event.pageX}px;`);
window.popupCoords.left = event.pageX; // 更新左侧坐标
window.popupCoords.top = event.pageY; // 更新顶部坐标
});
}
// console.log('event', event.pageX);
let left = (event.pageX !== undefined) ? event.pageX : window.popupCoords.left; // 获取左侧坐标
let top = (event.pageY !== undefined) ? event.pageY : window.popupCoords.top; // 获取顶部坐标
// console.log(`left: ${left}, top: ${top}`);
return { left: left, top: top }; // 返回坐标对象
}
////////////////////////////////morePopup//////////////////////////////////
window.showAddFP = function() {
document.getElementById("showAddFPbtn").style.display = "none"; // 隐藏“添加 FP”按钮
let addbmNode = document.getElementById('tab4showadd'); // 获取添加 FP 的节点
let todo = ''; // 初始化 todo 字符串
// 构建包含下拉菜单和输入框的 HTML 内容
todo = todo + `
';
addbmNode.innerHTML = "\n
" + todo; // 将构建的内容插入到指定节点
}
window.AddFPProcessForm = async function() {
document.getElementById("Tab4AddFPForm").innerText = "请稍候..."; // 设置按钮文本为“请稍候...”
let apiUrl = "https://www.facebook.com/api/graphql"; // API 的 URL
let AddFPName = document.getElementById("Tab4AddFPname").value; // 获取 FP 名称
let AddFPcat = document.getElementById("Tab4AddFPcat").value; // 获取类别
let AddFPstyle = document.getElementById("Tab4AddFPstyle").value; // 获取样式
// 根据样式选择设置 fbdocid
let fbdocid = (AddFPstyle === '1') ? '4722866874428654' : '9339938679410311';
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
// 添加必要的参数
urlencoded.append("jazoest", 25477);
urlencoded.append("__rev", window.spinR);
urlencoded.append("__hsi", window.hsi);
urlencoded.append("__spin_r", window.spinR);
urlencoded.append("__spin_b", window.spinB);
urlencoded.append("__spin_t", window.spinT);
urlencoded.append("fb_api_caller_class", "RelayModern");
urlencoded.append("fb_api_req_friendly_name", "AdditionalProfilePlusCreationMutation");
urlencoded.append("av", window.socid);
urlencoded.append("__user", window.socid);
urlencoded.append("fb_dtsg", window.dtsg);
// 根据样式选择设置 variables 参数
if (AddFPstyle === '1') {
urlencoded.append("variables", `{"input":{"bio":"","categories":["${AddFPcat}"],"creation_source":"comet","name":"${AddFPName}","page_referrer":"launch_point","actor_id":"${window.socid}","client_mutation_id":"1"}}`);
} else {
urlencoded.append("variables", `{"input":{"categories":["${AddFPcat}"],"creation_source":"CM_OFFSITE_CREATE_NEW_PAGE","description":"","name":"${AddFPName}","actor_id":"${window.socid}","client_mutation_id":"1"}}`);
}
urlencoded.append("doc_id", fbdocid); // 添加文档 ID
urlencoded.append("server_timestamps", 'true'); // 启用服务器时间戳
let logNode = document.getElementById('tab4addfplog'); // 获取日志节点
let nolog = 0; // 初始化日志标志
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 解析 JSON 响应
console.log(json); // 打印 JSON 数据到控制台
if (json.errors !== undefined) { // 如果出现错误
alert('创建页面时出错 :('); // 显示错误提示
document.getElementById("Tab4AddFPForm").innerText = "再试一次"; // 设置按钮文本为“再试一次”
} else {
var newfpid = ''; // 新的页面 ID
var newfpname = ''; // 新的 FP 名称
if (AddFPstyle === '1') {
try {
if (json.data.additional_profile_plus_create.additional_profile.id > 0) {
newfpid = json.data.additional_profile_plus_create.additional_profile.id; // 获取新页面 ID
newfpname = AddFPName; // 获取 FP 名称
}
} catch (e) {
newfpid = 0;
newfpname = '';
try {
if (json.data.additional_profile_plus_create.name_error) {
alert(json.data.additional_profile_plus_create.name_error); // 显示名称错误
nolog = 1; // 设置日志标志为 1
}
} catch (e) {
newfpid = 0;
newfpname = '';
}
}
} else {
try {
if (json.data.page_create.page.id > 0) {
newfpid = json.data.page_create.page.id; // 获取新页面 ID
newfpname = AddFPName; // 获取 FP 名称
}
} catch (e) {
newfpid = 0;
newfpname = '';
}
try {
if (json.data.page_create.page_name_error) {
alert(json.data.page_create.page_name_error); // 显示页面名称错误
nolog = 1; // 设置日志标志为 1
}
} catch (e) {
newfpid = 0;
newfpname = '';
}
try {
if (json.data.page_create.error_message) {
alert(json.data.page_create.error_message); // 显示错误信息
nolog = 1; // 设置日志标志为 1
}
} catch (e) {
newfpid = 0;
newfpname = '';
}
}
// 如果没有日志错误
if (nolog === 0) {
logNode.innerHTML += "\n
" + newfpname + " [" + newfpid + "] [
][
打开 ]"; // 显示新创建的页面信息
document.getElementById("Tab4AddFPForm").innerText = "前往新页面"; // 设置按钮文本为“前往新页面”
}
}
}
window.PzrdFPList = async function() {
// 初始化返回对象
var pzrdret = {'pzrdid': [], 'banid': []};
let apiUrl = "https://www.facebook.com/api/graphql"; // API 的 URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
// 添加必要的参数
urlencoded.append("jazoest", 25477);
urlencoded.append("__rev", window.spinR);
urlencoded.append("__hsi", window.hsi);
urlencoded.append("__spin_r", window.spinR);
urlencoded.append("__spin_b", window.spinB);
urlencoded.append("__spin_t", window.spinT);
urlencoded.append("fb_api_caller_class", "RelayModern");
urlencoded.append("fb_api_req_friendly_name", "AccountQualityUserPagesWrapper_UserPageQuery");
urlencoded.append("av", window.socid);
urlencoded.append("__user", window.socid);
urlencoded.append("fb_dtsg", window.dtsg);
urlencoded.append("variables", `{"assetOwnerId": ${window.socid}}`); // 设置变量
urlencoded.append("doc_id", '5196344227155252'); // 文档 ID
urlencoded.append("server_timestamps", 'true'); // 启用服务器时间戳
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 解析 JSON 响应
if (json.errors !== undefined) { // 如果返回中有错误
return pzrdret; // 返回初始化的 pzrdret 对象
} else {
// 处理成功的响应
data = json; // 将响应数据赋值给 data
if ('data' in data && 'userData' in data.data && 'pages_can_administer' in data.data.userData) {
pzrd_count = []; // 初始化 pzrd_count 数组
for (let i = 0; i < data.data.userData.pages_can_administer.length; i++) {
var current_page = data.data.userData.pages_can_administer[i]; // 当前页面
if ('advertising_restriction_info' in current_page) { // 检查广告限制信息
if (!current_page.advertising_restriction_info.is_restricted && current_page.advertising_restriction_info.restriction_type == "ALE") {
// 如果没有限制且限制类型为 ALE
pzrd_count.push(`Pzrd: ${current_page.name} | ${current_page.id}`); // 添加到 pzrd_count
pzrdret.pzrdid.push(current_page.id); // 将页面 ID 添加到 pzrdret.pzrdid
}
if (current_page.advertising_restriction_info.is_restricted) {
pzrdret.banid.push(current_page.id); // 将被限制的页面 ID 添加到 pzrdret.banid
}
}
}
}
}
return pzrdret; // 返回结果对象
}
window.PzrdSocList = async function() {
// 初始化返回对象
var pzrdret = {'pzrdid': [], 'banid': []};
let apiUrl = "https://www.facebook.com/api/graphql"; // API 的 URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
// 添加必要的参数
urlencoded.append("jazoest", 25477);
urlencoded.append("__rev", window.spinR);
urlencoded.append("__hsi", window.hsi);
urlencoded.append("__spin_r", window.spinR);
urlencoded.append("__spin_b", window.spinB);
urlencoded.append("__spin_t", window.spinT);
urlencoded.append("fb_api_caller_class", "RelayModern");
urlencoded.append("fb_api_req_friendly_name", "AccountQualityHubAssetOwnerViewV2Query");
urlencoded.append("av", window.socid);
urlencoded.append("__user", window.socid);
urlencoded.append("fb_dtsg", window.dtsg);
urlencoded.append("variables", `{"assetOwnerId": ${window.socid}}`); // 设置变量
urlencoded.append("doc_id", '6139497919470985'); // 文档 ID
urlencoded.append("server_timestamps", 'true'); // 启用服务器时间戳
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 解析 JSON 响应
if (json.errors !== undefined) { // 如果返回中有错误
return pzrdret; // 返回初始化的 pzrdret 对象
} else {
// 处理成功的响应
data = json; // 将响应数据赋值给 data
if ('data' in data && 'userData' in data.data && 'pages_can_administer' in data.data.userData) {
let pzrd_count = []; // 初始化 pzrd_count 数组
for (let i = 0; i < data.data.userData.pages_can_administer.length; i++) {
var current_page = data.data.userData.pages_can_administer[i]; // 当前页面
if ('advertising_restriction_info' in current_page) { // 检查广告限制信息
if (!current_page.advertising_restriction_info.is_restricted && current_page.advertising_restriction_info.restriction_type == "ALE") {
// 如果没有限制且限制类型为 ALE
pzrd_count.push(`Pzrd: ${current_page.name} | ${current_page.id}`); // 添加到 pzrd_count
pzrdret.pzrdid.push(current_page.id); // 将页面 ID 添加到 pzrdret.pzrdid
}
if (current_page.advertising_restriction_info.is_restricted) {
pzrdret.banid.push(current_page.id); // 将被限制的页面 ID 添加到 pzrdret.banid
}
}
}
}
}
return pzrdret; // 返回结果对象
}
window.PzrdBmList = async function(bmid) {
let bmNode = document.getElementById('fbaccstatusbmpzrd' + bmid); // 获取指定的节点
bmNode.innerHTML += '
[..] '; // 显示加载状态
var retbmpzrdstat = ''; // 初始化返回状态变量
let apiUrl = "https://www.facebook.com/api/graphql"; // API 的 URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
// 添加必要的参数
urlencoded.append("jazoest", 25477);
urlencoded.append("__rev", window.spinR);
urlencoded.append("__hsi", window.hsi);
urlencoded.append("__spin_r", window.spinR);
urlencoded.append("__spin_b", window.spinB);
urlencoded.append("__spin_t", window.spinT);
urlencoded.append("fb_api_caller_class", "RelayModern");
urlencoded.append("fb_api_req_friendly_name", "AccountQualityHubAssetOwnerViewV2Query");
urlencoded.append("av", window.socid);
urlencoded.append("__user", window.socid);
urlencoded.append("fb_dtsg", window.dtsg);
urlencoded.append("variables", `{"assetOwnerId": ${bmid}}`); // 设置变量
urlencoded.append("doc_id", '6139497919470985'); // 文档 ID
urlencoded.append("server_timestamps", 'true'); // 启用服务器时间戳
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 解析 JSON 响应
if (json.errors !== undefined) { // 如果返回中有错误
retbmpzrdstat = ''; // 返回状态为空
} else {
console.log(json); // 打印响应数据到控制台
try {
// 检查广告限制信息是否未受限制且类型为 ALE
if (!json.data.assetOwnerData.advertising_restriction_info.is_restricted && json.data.assetOwnerData.advertising_restriction_info.restriction_type == "ALE") {
retbmpzrdstat = '[
Reinst ]'; // 设置状态为“恢复”
}
} catch (e) {
console.log("获取 PZRD BM 状态时出错");
retbmpzrdstat = ''; // 返回状态为空
}
try {
// 检查广告限制信息是否受限制且状态为“待审”
if (json.data.assetOwnerData.advertising_restriction_info.is_restricted && json.data.assetOwnerData.advertising_restriction_info.status == "APPEAL_PENDING") {
retbmpzrdstat = '[
在审查中 ]'; // 设置状态为“在审查中”
}
} catch (e) {
console.log("获取 PZRD BM 状态时出错");
retbmpzrdstat = ''; // 返回状态为空
}
try {
// 检查广告限制信息是否受限制且状态为“上诉被拒绝无重试”
if (json.data.assetOwnerData.advertising_restriction_info.is_restricted && json.data.assetOwnerData.advertising_restriction_info.status == "APPEAL_REJECTED_NO_RETRY") {
retbmpzrdstat = '[
已终止 ]'; // 设置状态为“已终止”
}
} catch (e) {
console.log("获取 PZRD BM 状态时出错");
retbmpzrdstat = ''; // 返回状态为空
}
}
bmNode.innerHTML = retbmpzrdstat; // 更新节点内容为返回状态
return true; // 返回 true
}
window.showAddBM = function() {
document.getElementById("showAddBMbtn").style.display = "none"; // 隐藏“添加 BM”按钮
let addbmNode = document.getElementById('tab5showadd'); // 获取添加 BM 的节点
let todo = ''; // 初始化内容字符串
todo = todo + '
'; // 添加提交按钮
addbmNode.innerHTML = "\n
" + todo; // 将构建的内容插入到指定节点
}
window.AddBMProcessForm = async function() {
document.getElementById("Tab5AddBMForm").innerText = "请稍候"; // 设置按钮文本为“请稍候”
let AddBMName = document.getElementById("Tab5AddBMname").value; // 获取 Business Manager 名称
let AddBMmail = document.getElementById("Tab5AddBMmail").value; // 获取电子邮件
let AddBMtype = document.getElementById("Tab5AddBMtype").value; // 获取类型
if (AddBMtype == 1) { // 如果选择的是经典方法
let apiUrl = "https://www.facebook.com/api/graphql/"; // API 的 URL
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
// 添加必要的参数
urlencoded.append("__rev", window.spinR);
urlencoded.append("__hsi", window.hsi);
urlencoded.append("__spin_r", window.spinR);
urlencoded.append("__spin_b", window.spinB);
urlencoded.append("__spin_t", window.spinT);
urlencoded.append("fb_api_caller_class", "RelayModern");
urlencoded.append("fb_api_req_friendly_name", "useBusinessCreationMutationMutation");
urlencoded.append("av", window.socid);
urlencoded.append("__user", window.socid);
urlencoded.append("fb_dtsg", window.dtsg);
urlencoded.append("variables", `{"input":{"client_mutation_id":"1","actor_id":"${window.socid}","business_name":"${AddBMName}","user_first_name":"${window.shortname}","user_last_name":"${window.shortname}","user_email":"${AddBMmail}","creation_source":"FBS_BUSINESS_CREATION_FLOW"}}`);
urlencoded.append("doc_id", '7183377418404152');
urlencoded.append("server_timestamps", 'true');
let logNode = document.getElementById('tab5addbmlog'); // 获取日志节点
let response = await fetch(apiUrl, {
mode: 'cors',
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded // 设置请求体
});
let json = await response.json(); // 解析 JSON 响应
// console.log(json);
if (json.errors !== undefined) { // 如果返回中有错误
alert('创建新 BM 时出错 :('); // 显示错误提示
document.getElementById("Tab5AddBMForm").innerText = "再试一次"; // 更新按钮文本
} else {
// 如果创建成功
if (json.data.bizkit_create_business.id > 0) {
logNode.innerHTML += "\n
" + AddBMName + " (" + json.data.bizkit_create_business.id + ")"; // 更新日志信息
}
document.getElementById("Tab5AddBMForm").innerText = "继续进行"; // 更新按钮文本
}
} else { // 如果选择的是开发方法
var urlencoded = new URLSearchParams(); // 创建 URLSearchParams 对象
// 添加必要的参数
urlencoded.append("first_name", window.fullname);
urlencoded.append("last_name", window.shortname);
urlencoded.append("brand_name", AddBMName);
urlencoded.append("email", AddBMmail);
urlencoded.append("timezone_id", "0");
urlencoded.append("business_category", "OTHER");
urlencoded.append("__rev", window.spinR);
urlencoded.append("__hsi", window.hsi);
urlencoded.append("__spin_r", window.spinR);
urlencoded.append("__spin_b", window.spinB);
urlencoded.append("__spin_t", window.spinT);
// urlencoded.append("fb_api_caller_class", "RelayModern");
// urlencoded.append("fb_api_req_friendly_name", "useBusinessCreationMutationMutation");
// 创建 API URL
let apiUrl = "https://developers.facebook.com/business/create/?brand_name=" + AddBMName + "&first_name=" + window.fullname + "&last_name=" + window.shortname + "&email=" + AddBMmail + "&timezone_id=0&business_category=OTHER";
let logNode = document.getElementById('tab5addbmlog'); // 获取日志节点
let response = await fetch(apiUrl, {
mode: 'no-cors', // 设置跨域模式
method: 'POST', // 请求方法为 POST
credentials: 'include', // 包含凭证
redirect: "follow", // 设置重定向策略
body: urlencoded, // 设置请求体
referrerPolicy: "same-origin", // 设置引用策略
});
let json = await response.json(); // 解析 JSON 响应
// console.log(json);
if (json.errors !== undefined) { // 如果返回中有错误
alert('创建新 BM 时出错 :('); // 显示错误提示
document.getElementById("Tab5AddBMForm").innerText = "再试一次"; // 更新按钮文本
} else {
// 如果创建成功
if (json.data.bizkit_create_business.id > 0) {
logNode.innerHTML += "\n
" + AddBMName + " (" + json.data.bizkit_create_business.id + ")"; // 更新日志信息
}
document.getElementById("Tab5AddBMForm").innerText = "继续进行"; // 更新按钮文本
}
}
}
window.getcc = async function() {
var credcca = []; // 初始化信用卡数组
var cctype = 'bmcc'; // 设置信用卡类型为 ‘bmcc’
// 构建获取业务信息的 API URL
tmpapiurl = 'https://graph.facebook.com/v19.0/me/businesses?fields=id,is_disabled_for_integrity_reasons,can_use_extended_credit,name,verification_status,creditcards&access_token=' + window.privateToken;
// 发送请求获取业务信息
let response = await fetch(tmpapiurl, {
mode: 'cors',
method: 'GET',
credentials: 'include',
redirect: "follow"
});
let bminf = await response.json(); // 解析 JSON 响应
if (bminf.errors !== undefined) {
// 处理错误情况(可以添加具体逻辑)
} else {
// 如果有数据
if (bminf.data.length) {
var i = 0;
for (; i < bminf.data.length; i++) {
try {
// 如果有信用卡信息
if (bminf.data[i].creditcards.data.length) {
for (var icc = 0; icc < bminf.data[i].creditcards.data.length; icc++) {
bminf.data[i].creditcards.data[icc].cctype = 'bmcc'; // 设置信用卡类型
bminf.data[i].creditcards.data[icc].ccinf = bminf.data[i].name; // 设置信用卡信息
credcca.push(bminf.data[i].creditcards.data[icc]); // 将信用卡信息添加到数组
}
}
} catch (e) {
console.log("没有业务信用卡"); // 捕获异常并打印信息
}
}
}
}
// 构建获取广告账户信息的 API URL
tmpapiurl2 = 'https://graph.facebook.com/v19.0/me/adaccounts?fields=id,account_id,business,name,funding_source_details&limit=1000&sort=name_ascending&access_token=' + window.privateToken;
// 发送请求获取广告账户信息
let response2 = await fetch(tmpapiurl2, {
mode: 'cors',
method: 'GET',
credentials: 'include',
redirect: "follow"
});
let bminf2 = await response2.json(); // 解析 JSON 响应
if (bminf2.errors !== undefined) {
// 处理错误情况(可以添加具体逻辑)
} else {
// 如果有数据
if (bminf2.data.length) {
var i = 0;
for (; i < bminf2.data.length; i++) {
try {
// 如果有资金来源详细信息
if (bminf2.data[i].funding_source_details) {
bminf2.data[i].funding_source_details.cctype = 'usercc'; // 设置信用卡类型
bminf2.data[i].funding_source_details.ccinf = bminf2.data[i].name; // 设置信用卡信息
credcca.push(bminf2.data[i].funding_source_details); // 将信用卡信息添加到数组
}
} catch (e) {
console.log("没有信用卡"); // 捕获异常并打印信息
}
}
}
}
return credcca; // 返回信用卡信息数组
}
window.getFpComments = async function() {
// 初始化变量
var currfp;
var currfpcnt = 0;
// 构建获取账户和广告帖评论的 API URL
tmpapiurl = 'https://graph.facebook.com/v19.0/me?fields=accounts.limit(100){id,name,ads_posts.limit(100){id,comments.limit(100){id}}}&access_token=' + window.privateToken;
// 发送请求获取业务信息
let response = await fetch(tmpapiurl, {
mode: 'cors',
method: 'GET',
credentials: 'include',
redirect: "follow"
});
let bminf = await response.json(); // 解析 JSON 响应
if (bminf.errors !== undefined) {
// 处理错误情况(可以添加具体逻辑)
} else {
// 如果有账户数据
if (bminf.accounts.data.length) {
var i = 0;
var icc = 0;
for (; i < bminf.accounts.data.length; i++) {
currfp = document.getElementById("fpcomm_" + bminf.accounts.data[i].id); // 获取当前评论节点
currfpcnt = 0; // 重置评论计数
currfp.innerHTML = '...'; // 显示加载状态
try {
// 如果有广告帖子数据
if (bminf.accounts.data[i].ads_posts.data.length) {
for (icc = 0; icc < bminf.accounts.data[i].ads_posts.data.length; icc++) {
try {
// 如果广告帖子有评论
if (bminf.accounts.data[i].ads_posts.data[icc].comments.data.length) {
currfpcnt += bminf.accounts.data[i].ads_posts.data[icc].comments.data.length; // 累加评论数量
}
} catch (e) {
console.log("广告帖子没有评论"); // 捕获异常并打印信息
}
}
}
} catch (e) {
console.log("没有广告帖子带评论"); // 捕获异常并打印信息
}
currfp.innerHTML = currfpcnt; // 更新评论计数到节点
// 如果评论数量大于 0,则显示清理评论的链接
if (currfpcnt > 0) {
document.getElementById("fpcleanall").innerHTML = "
"; // 更新清理评论按钮
}
await sleep(2000); // 暂停 2 秒
}
}
}
// 定义 sleep 函数用于暂停
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
window.delFpComments = async function() {
// 隐藏添加 FP 按钮
document.getElementById("showAddFPbtn").style.display = "none";
var currfp;
var currfpcnt = 0;
var currpageToken; // 当前页面令牌
// 构建获取账户和广告帖评论的 API URL
tmpapiurl = 'https://graph.facebook.com/v19.0/me?fields=accounts.limit(100){id,name,ads_posts.limit(100){id,comments.limit(100){id}}}&access_token=' + window.privateToken;
// 发送请求获取业务信息
let response = await fetch(tmpapiurl, {
mode: 'cors',
method: 'GET',
credentials: 'include',
redirect: "follow"
});
let bminf = await response.json(); // 解析 JSON 响应
if (bminf.errors !== undefined) {
// 处理错误情况(可以添加具体逻辑)
} else {
// 如果有账户数据
if (bminf.accounts.data.length) {
var i = 0;
var icc = 0;
var icom = 0;
for (; i < bminf.accounts.data.length; i++) {
currfp = document.getElementById("fpcomm_" + bminf.accounts.data[i].id); // 获取当前评论节点
currpageToken = await window.getPageToken(bminf.accounts.data[i].id); // 获取页面令牌
console.log('页面: ' + bminf.accounts.data[i].id + ' 令牌: ' + currpageToken); // 打印当前页面 ID 和令牌
currfpcnt = 0; // 重置评论计数
currfp.innerHTML = '...'; // 显示加载状态
try {
// 如果有广告帖子数据
if (bminf.accounts.data[i].ads_posts.data.length) {
for (icc = 0; icc < bminf.accounts.data[i].ads_posts.data.length; icc++) {
try {
// 如果广告帖子有评论
if (bminf.accounts.data[i].ads_posts.data[icc].comments.data.length) {
console.log('广告帖子:' + bminf.accounts.data[i].ads_posts.data[icc].id + ' ' + bminf.accounts.data[i].ads_posts.data[icc].comments.data.length + ' 个评论找到');
currfpcnt += bminf.accounts.data[i].ads_posts.data[icc].comments.data.length; // 累加评论数量
for (icom = 0; icom < bminf.accounts.data[i].ads_posts.data[icc].comments.data.length; icom++) {
// 删除评论
tmpapiurldel = 'https://graph.facebook.com/v19.0/' + bminf.accounts.data[i].ads_posts.data[icc].comments.data[icom].id + '?access_token=' + currpageToken;
dresponse = await fetch(tmpapiurldel, {
mode: 'cors',
method: 'DELETE', // 删除请求
credentials: 'include',
redirect: "follow"
});
dinf = await dresponse.json(); // 解析删除响应
if (dinf.success == true) {
document.getElementById("tab4addfplog").innerHTML += '页面: ' + bminf.accounts.data[i].id + ' 评论
' + (icom + 1) + ' 从 ' + bminf.accounts.data[i].ads_posts.data[icc].comments.data.length + ' 中删除
'; // 更新日志信息
}
await sleep(1000); // 暂停 1 秒
}
}
} catch (e) {
console.log("广告帖子没有评论"); // 捕获异常并打印信息
}
}
}
} catch (e) {
console.log("没有广告帖子带评论"); // 捕获异常并打印信息
}
currfp.innerHTML = currfpcnt; // 更新评论计数到节点
// 如果评论数量大于 0,则显示清理评论的链接
if (currfpcnt > 0) {
document.getElementById("fpcleanall").innerHTML = "
"; // 更新清理评论按钮
}
await sleep(2000); // 暂停 2 秒
}
}
}
// 定义 sleep 函数用于暂停
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
window.getAccAds = async function(accid) {
var retrn = '';
var todo = '';
var i = 0;
var ic = 0;
var tmpadimages = []; // 存储广告图片
var tmpadcreatives = []; // 存储广告创意
// 构建获取账户广告数据的 API URL
var ApiUrlMainInfo = "https://graph.facebook.com/v19.0/act_" + accid + "/?fields=adimages.limit(100){name,url_128,ads_integrity_review_info,creatives},advideos.limit(100){id,picture,ads_integrity_review_info},ads.limit(100){name,status,ad_review_feedback,adcreatives{id,image_url},delivery_status},adcreatives.limit(100){id,name,object_id,object_story_spec,thumbnail_url}&limit=100&access_token=" + window.privateToken + "&locale=en_US";
// 发送请求获取广告数据
let response = await fetch(ApiUrlMainInfo, {
mode: 'cors',
method: 'GET',
credentials: 'include',
redirect: "follow"
});
let AccAds = await response.json(); // 解析 JSON 响应
console.log(AccAds);
if (AccAds.errors !== undefined) {
// 处理错误情况(可以添加具体逻辑)
} else {
// 如果有广告数据
if (AccAds.ads.data.length) {
try {
// 处理广告图片数据
if (AccAds.adimages.data.length) {
for (i = 0; i < AccAds.adimages.data.length; i++) {
try {
if (AccAds.adimages.data[i].creatives.length) {
for (ic = 0; ic < AccAds.adimages.data[i].creatives.length; ic++) {
tmpadimages[AccAds.adimages.data[i].creatives[ic]] = AccAds.adimages.data[i]; // 存储广告图片
}
}
} catch (e) {
console.log("广告图片未使用");
}
}
}
} catch (e) {
console.log("没有广告图片数组");
}
try {
// 处理广告创意数据
if (AccAds.adcreatives.data.length) {
for (i = 0; i < AccAds.adcreatives.data.length; i++) {
try {
tmpadcreatives[AccAds.adcreatives.data[i].id] = AccAds.adcreatives.data[i]; // 存储广告创意
} catch (e) {
console.log("广告创意未使用");
}
}
}
} catch (e) {
console.log("没有广告创意数组");
}
// 构建表格展示广告数据
var b = AccAds.ads;
todo += '
# Name Status Bot review Human review Preapproval Review needed Review Start TS Review Update TS ';
// 遍历广告数据
for (i = 0; i < b.data.length; i++) {
if (b.data[i].name) {
todo += "";
// 获取广告的投放状态
if (b.data[i].delivery_status.status) {
switch (b.data[i].delivery_status.status) {
case "active":
delivstatus = '🟢 ACTIVE';
break;
case "inactive":
delivstatus = '⏸ ';
break;
case "off":
delivstatus = '⏸ ';
break;
case "error":
delivstatus = '🟥Error';
break;
case "xz":
delivstatus = "xz";
break;
default:
delivstatus = " " + b.data[i].delivery_status.status;
break;
}
}
// 获取广告创意的图片
if (b.data[i].adcreatives.data[0].image_url) {
tblcreo = ' ';
} else {
try {
if (tmpadcreatives[b.data[i].adcreatives.data[0].id].thumbnail_url) {
tblcreo = ' ';
}
} catch (e) {
console.log("视频没有广告图片");
tblcreo = "";
}
}
// 初始化各个状态
let revstatus = '';
let hrevstatus = '';
let preapstatus = '';
let preapnd = '';
let revstartts = '';
let revupts = '';
// 获取广告的审核状态
try {
switch (tmpadimages[b.data[i].adcreatives.data[0].id].ads_integrity_review_info.is_reviewed) {
case true:
revstatus = '✓ ';
break;
case false:
revstatus = 'n/a';
break;
default:
revstatus = " ";
break;
}
} catch (e) {
console.log("审核状态错误");
revstatus = "";
}
// 获取人工审核状态
try {
switch (tmpadimages[b.data[i].adcreatives.data[0].id].ads_integrity_review_info.is_human_reviewed) {
case true:
hrevstatus = '✓ ';
break;
case false:
hrevstatus = 'n/a';
break;
default:
hrevstatus = " ";
break;
}
} catch (e) {
console.log("人工审核状态错误");
hrevstatus = "";
}
// 获取预先审核状态
try {
if (tmpadimages[b.data[i].adcreatives.data[0].id].ads_integrity_review_info.component_review_status_info) {
preapstatus = tmpadimages[b.data[i].adcreatives.data[0].id].ads_integrity_review_info.component_review_status_info.preapproval_review_status;
preapnd = tmpadimages[b.data[i].adcreatives.data[0].id].ads_integrity_review_info.component_review_status_info.preapproval_human_review_needed;
revstartts = tmpadimages[b.data[i].adcreatives.data[0].id].ads_integrity_review_info.component_review_status_info.preapproval_review_start_ts;
revstartts = revstartts.replace('+0000', '').replace('T', ' ');
revupts = tmpadimages[b.data[i].adcreatives.data[0].id].ads_integrity_review_info.component_review_status_info.preapproval_review_update_ts;
revupts = revupts.replace('+0000', '').replace('T', ' ');
}
} catch (e) {
console.log("预审核状态错误");
preapstatus = "";
preapnd = "";
revupts = '';
revstartts = '';
}
if (b.data[i].ad_review_feedback) {
// 如果有广告审核反馈
todo += ("" + tblcreo + " " + b.data[i].name + " [" + delivstatus + '] 申诉 ' + " ");
} else {
// 如果没有广告审核反馈
todo += ("" + tblcreo + " " + b.data[i].name + " [" + delivstatus + "] " + " ");
}
// 添加审核状态信息到表格
todo += "" + revstatus + " " +
"" + hrevstatus + " " +
"" + preapstatus + " " +
"" + preapnd + " " +
"" + revstartts + " " +
"" + revupts + " ";
// 添加广告审核反馈信息
if (b.data[i].ad_review_feedback) {
if (b.data[i].ad_review_feedback.global) {
todo += ("");
var rjkey;
for (var k in b.data[i].ad_review_feedback.global) {
rjkey = k + "[ ? ]";
todo += rjkey; // 添加反馈信息到表格
}
todo += (" ");
} else {
todo += " "; // 如果没有全局反馈
}
} else {
todo += " "; // 如果没有审核反馈
}
todo += " "; // 结束当前行
}
}
todo = todo + "
";
}
//window.showPluginPopup(event, todo,'Account Ads');
}
return todo;
}
window.showMorePopupFpOwnedBmRm = async function(bmid, fpid) {
// 确认用户是否确定要从业务管理器中移除页面
if (confirm('你确定要从业务管理器 ' + bmid + ' 中移除页面 ' + fpid + ' 吗?')) {
let apiUrl = "https://graph.facebook.com/v19.0/"; // Facebook Graph API 的基本 URL
let params;
// 生成请求参数
params = `${bmid}/pages?access_token=${window.privateToken}`;
var urlencoded = new URLSearchParams();
urlencoded.append("method", "delete"); // 设置请求方法为删除
urlencoded.append("page_id", fpid); // 设置要删除的页面 ID
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
let logNode = document.getElementById('showMorePopupFpRoleslog'); // 获取日志节点
let response = await fetch(apiUrl + params, {
mode: 'cors',
method: 'POST',
credentials: 'include',
redirect: "follow",
body: urlencoded // 将编码后的参数作为请求体
});
let json = await response.json(); // 解析 JSON 响应
if (json.error !== undefined) {
// 如果存在错误,则提示用户并记录日志
alert(json.error.message);
logNode.innerHTML += "\n
" + json.error.message;
} else {
// 删除成功,记录日志
logNode.innerHTML += "\n
完成!";
}
// 暂停 2 秒
await sleep(2000);
// 刷新页面角色信息
window.showMorePopupFpRoles(fpid);
}
// 定义 sleep 函数用于暂停
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
}
}
window.showMorePopupFpRoles = async function(fpid) {
// 构建获取页面角色的 API URL
tmpapiurl = 'https://graph.facebook.com/v19.0/' + fpid + '?fields=roles,business,agencies&limit=100&access_token=' + window.privateToken;
var todoret = ''; // 存储返回的 HTML 内容
var BMUrole; // 存储角色
// 使用 getJSON 函数获取 JSON 数据
window.getJSON(tmpapiurl, await function(err, bminf) {
if (err !== null) {
alert("发生错误: " + err); // 如果发生错误,提示用户
} else {
if (bminf.roles.data.length) {
// 如果找到了角色数据
todoret += '
名称 角色 # ';
var i = 0;
for (; i < bminf.roles.data.length; i++) {
try {
if (bminf.roles.data[i].name) {
// 获取角色名称
BMUname = bminf.roles.data[i].name;
BMUname += " ";
}
} catch (e) {
BMUname = 'NA'; // 如果发生错误,设置为 NA
}
try {
// 获取角色任务
if (bminf.roles.data[i].tasks) {
if (bminf.roles.data[i].tasks.indexOf("MANAGE") != -1) {
BMUrole = '管理'; // 管理角色
} else if (bminf.roles.data[i].tasks.indexOf("ADVERTISE") != -1) {
BMUrole = '广告'; // 广告角色
} else if (bminf.roles.data[i].tasks.indexOf("ANALYZE") != -1) {
BMUrole = '分析'; // 分析角色
}
}
} catch (e) {
BMUrole = 'NA'; // 如果发生错误,设置为 NA
console.log('NA FP Role');
}
// 添加角色信息到表格
todoret += ("" + BMUname + " " + BMUrole + " " + " ");
}
// 处理业务信息
try {
try {
if (bminf.business.name) {
BMUname = bminf.business.name; // 获取业务名称
}
} catch (e) {
BMUname = 'NA'; // 如果发生错误,设置为 NA
}
// 添加业务信息到表格
todoret += ("" + ' ' + "" + BMUname + " 业务拥有者 " + "" + ' ' + " ");
} catch (e) {
console.log('FP not owned ..');
}
// 处理代理信息
try {
var i = 0;
for (; i < bminf.agencies.data.length; i++) {
try {
if (bminf.agencies.data[i].name) {
BMUname = bminf.agencies.data[i].name; // 获取代理名称
}
} catch (e) {
BMUname = 'NA'; // 如果发生错误,设置为 NA
}
// 添加代理信息到表格
todoret += ("" + ' ' + "" + BMUname + " 共享业务管理 " + "" + ' ' + " ");
}
} catch (e) {
console.log('0 AG BM ..');
}
// 结束表格
todoret += "
";
} else {
todoret = 'Error'; // 如果没有角色数据,设置为错误
}
}
// 添加额外的内容和按钮
todoret += "\n
";
window.showPluginPopup(event, todoret, '页面角色'); // 显示弹出窗口
});
}
window.showMorePopupFpAdsRm = async function(fpid, adsid) {
// 获取当前页面的访问令牌
var currpageToken = await window.getPageToken(fpid);
// 构建删除广告的 API URL
tmpapiurldel = 'https://graph.facebook.com/v19.0/' + adsid + '?access_token=' + currpageToken;
// 发送 DELETE 请求以删除广告
dresponse = await fetch(tmpapiurldel, {
mode: 'cors',
method: 'DELETE',
credentials: 'include',
redirect: "follow"
});
// 解析 JSON 响应
dinf = await dresponse.json();
// 检查删除是否成功
if (dinf.success == true) {
// 如果删除成功,更新日志并刷新广告列表
document.getElementById("showMorePopupFpAdslog").innerHTML += '完成!
';
window.showMorePopupFpAds(fpid); // 刷新广告列表
} else {
// 如果删除失败,更新日志并刷新广告列表
document.getElementById("showMorePopupFpAdslog").innerHTML += '错误 :(
';
window.showMorePopupFpAds(fpid); // 刷新广告列表
}
}
window.showMorePopupFpAds = async function(fpid) {
// 构建获取广告帖子的 API URL
tmpapiurl = 'https://graph.facebook.com/v19.0/' + fpid + '/ads_posts?fields=id,full_picture,promotion_status,promotable_id,status_type,permalink_url,picture,call_to_action&limit=500&access_token=' + window.privateToken;
var todoret = ''; // 用于存储返回的 HTML 内容
// 使用 getJSON 函数获取广告帖子数据
window.getJSON(tmpapiurl, await function(err, bminf) {
if (err !== null) {
alert("发生错误: " + err); // 如果发生错误,提示用户
} else {
if (bminf.data.length) {
// 如果找到了广告帖子数据
todoret += '
# 行动呼吁(CTA) # ';
var i = 0;
// 遍历广告帖子数据
for (; i < bminf.data.length; i++) {
var tblcreo = ''; // 广告图片
var fpcta = 'NA'; // 行动呼吁
var plink = 'NA'; // 链接
try {
// 获取广告帖子图片
if (bminf.data[i].picture) {
tblcreo = ' ';
}
} catch (e) {
tblcreo = 'NA'; // 如果发生错误,设置为 NA
}
try {
// 获取广告帖子行动呼吁
if (bminf.data[i].call_to_action.type) {
fpcta = bminf.data[i].call_to_action.type;
}
} catch (e) {
fpcta = 'NA'; // 如果发生错误,设置为 NA
}
try {
// 获取广告帖子链接
if (bminf.data[i].permalink_url) {
plink = " ";
}
} catch (e) {
plink = 'NA'; // 如果发生错误,设置为 NA
}
// 构建表格行
todoret += ("" + tblcreo + " " + fpcta + " " + "" + plink + " ");
}
// 结束表格
todoret += "
";
} else {
todoret = '错误'; // 如果没有数据,设置为错误
}
}
// 添加日志显示区域
todoret += "\n
";
window.showPluginPopup(event, todoret, '页面广告帖子'); // 显示弹出窗口
});
}
window.showMorePopupAccAds = async function(accid) {
// 获取指定账户的广告信息并显示在弹出窗口中
var todo = await window.getAccAds(accid);
window.showPluginPopup(event, todo, '账户广告');
}
window.showMorePopupAccCap = async function(accid) {
// 构建获取账户能力的 API URL
tmpapiurl = 'https://graph.facebook.com/v19.0/act_' + accid + '?fields=capabilities&access_token=' + window.privateToken;
var toret = ''; // 用于存储返回的能力信息
var i = 0;
// 使用 getJSON 函数获取账户能力数据
window.getJSON(tmpapiurl, await function(err, bminf) {
if (err !== null) {
alert("发生错误: " + err); // 如果发生错误,提示用户
} else {
if (bminf.capabilities.length) {
// 如果找到了能力数据
bminf.capabilities.sort(); // 对能力进行排序
console.log(bminf.capabilities); // 打印能力信息到控制台
// 遍历能力数组并构建返回的 HTML 内容
for (; i < bminf.capabilities.length; i++) {
toret += bminf.capabilities[i] + "
";
}
} else {
toret = '错误'; // 如果没有能力数据,设置为错误
}
}
// 显示能力信息的弹出窗口
window.showPluginPopup(event, toret, '账户能力');
});
}
window.showMorePopupAccAdsFull = async function() {
// 定义开关图标
let togleon = '
';
let togleoff = '
';
let toglebtn; // 用于存储开关按钮的图标
let displaymore; // 用于控制显示的样式
// 获取广告全信息的 DOM 节点
let accadsNode = document.getElementById('getAccAdsfull');
if (accadsNode.className === 'getAccAdsfullcActive') {
// 如果当前状态是激活状态
toglebtn = togleoff; // 设置为关闭图标
accadsNode.className = 'getAccAdsfullcInactive'; // 更新节点的类名
displaymore = 'none'; // 隐藏更多内容
} else {
// 如果当前状态是非激活状态
toglebtn = togleon; // 设置为开启图标
accadsNode.className = 'getAccAdsfullcActive'; // 更新节点的类名
displaymore = 'table-cell'; // 显示更多内容
}
// 更新节点的 HTML 内容
accadsNode.innerHTML = '
' + toglebtn + ' ';
// 获取所有具有特定类名的表头节点
var thNode = document.getElementsByClassName("getAccAdsfullcl");
for (var i = 0; i < thNode.length; i++) {
thNode[i].style.display = displaymore; // 更新每个节点的显示状态
}
}
window.showMorePopupAccFull = async function() {
// 定义开关图标
let togleon = '
';
let togleoff = '
';
let toglebtn; // 用于存储开关按钮的图标
let displaymore; // 用于控制显示的样式
// 获取账户信息的 DOM 节点
let accadsNode = document.getElementById('getAccfull');
if (accadsNode.className === 'getAccfullcActive') {
// 如果当前状态是激活状态
toglebtn = togleoff; // 设置为关闭图标
accadsNode.className = 'getAccfullcInactive'; // 更新节点的类名
displaymore = 'none'; // 隐藏更多内容
} else {
// 如果当前状态是非激活状态
toglebtn = togleon; // 设置为开启图标
accadsNode.className = 'getAccfullcActive'; // 更新节点的类名
displaymore = 'table-cell'; // 显示更多内容
}
// 更新节点的 HTML 内容
accadsNode.innerHTML = '
' + toglebtn + ' ';
// 获取所有具有特定类名的表头节点
var thNode = document.getElementsByClassName("getAccfullcl");
for (var i = 0; i < thNode.length; i++) {
thNode[i].style.display = displaymore; // 更新每个节点的显示状态
}
}
window.showMorePopupBMAccsReq = function(bmid) {
// 隐藏添加和请求按钮
document.getElementById("showMorePopupBMAccsAddbtn").style.display = "none";
document.getElementById("showMorePopupBMAccsReqbtn").style.display = "none";
// 获取表单节点
let addbmNode = document.getElementById('showMorePopupBMAccsform');
let todo = '';
// 构建请求表单的 HTML 内容
todo += '
`;
// 更新表单内容
addbmNode.innerHTML = "\n
" + todo;
}
// 处理请求表单提交
window.showMorePopupBMAccsReqProcessForm = async function() {
document.getElementById("BMAccsReqClaimBtn").innerHTML = "请稍候..."; // 修改按钮文本为等待提示
let apiUrl = "https://graph.facebook.com/v19.0/";
// 获取表单输入的值
let privateBMtype = document.getElementById("BMAccsReqrole").value; // 获取权限类型
let privateBM = document.getElementById("BMAccsReqbmid").value; // 获取商务管理 ID
let privateBmNu = document.getElementById("BMAccsReqId").value; // 获取广告账户 ID
let params = `${privateBM}/client_ad_accounts`; // 设置API请求参数
var urlencoded = new URLSearchParams();
urlencoded.append("access_type", 'AGENCY'); // 设置访问类型
urlencoded.append("adaccount_id", privateBmNu); // 设置广告账户 ID
// 根据权限类型设置允许的任务
if (privateBMtype == 1) {
urlencoded.append("permitted_tasks", '["ANALYZE"]');
} else {
if (privateBMtype == 2) {
urlencoded.append("permitted_tasks", '["ADVERTISE","ANALYZE","DRAFT"]');
} else {
urlencoded.append("permitted_tasks", '["ADVERTISE","ANALYZE","DRAFT","MANAGE"]');
}
}
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
// 获取日志输出的节点
let logNode = document.getElementById('showMorePopupBMAccslog');
// 发送 API 请求
let response = await fetch(apiUrl + params, {
mode: 'cors', method: 'POST', credentials: 'include', redirect: "follow", body: urlencoded
});
let json = await response.json(); // 解析响应 JSON 数据
// 处理响应结果
if (json.error !== undefined) {
alert(json.error.error_user_msg); // 显示错误消息
logNode.innerHTML += "\n
" + json.error.error_user_msg;
} else {
logNode.innerHTML += "\n
完成!";
}
await sleep(1000); // 等待 1 秒
window.showMorePopupBMAccs(privateBM); // 重新加载广告账户信息
// 等待函数
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); // 等待指定毫秒
}
}
window.showMorePopupBMUsers = async function(bmid) {
// 构建获取业务用户和待处理用户的 API URL
tmpapiurl = 'https://graph.facebook.com/v19.0/' + bmid + '?fields=business_users{active_status,id,email,two_fac_status,pending_email,name,role,title,is_two_fac_blocked,was_integrity_demoted,sensitive_action_reviews},pending_users{id,role,email,status}&limit=100&access_token=' + window.privateToken;
var todoret = ''; // 用于存储返回的 HTML 内容
// 使用 getJSON 函数获取用户信息
window.getJSON(tmpapiurl, await function(err, bminf) {
if (err !== null) {
alert("发生错误: " + err); // 处理错误
} else {
if (bminf.business_users.data.length) {
// 构建表格头部
todoret = todoret + '
名称 角色 # ';
var i = 0;
// 遍历业务用户
for (; i < bminf.business_users.data.length; i++) {
try {
// 获取用户名称
if (bminf.business_users.data[i].name) {
BMUname = bminf.business_users.data[i].name;
}
} catch (e) {
BMUname = 'NA';
}
try {
// 获取用户角色
if (bminf.business_users.data[i].role) {
BMUrole = bminf.business_users.data[i].role;
// 根据角色创建下拉菜单
switch (bminf.business_users.data[i].role) {
case "ADMIN":
BMUrole = '管理员 员工 ';
break;
default:
BMUrole = '员工 管理员 ';
break;
}
}
} catch (e) {
BMUrole = 'NA';
}
// 添加用户信息到表格
todoret = todoret + ("" + BMUname + " " + BMUrole + " ");
}
// 处理待处理用户
try {
var i = 0;
for (; i < bminf.pending_users.data.length; i++) {
try {
// 获取待处理用户的电子邮件
if (bminf.pending_users.data[i].email) {
BMUname = bminf.pending_users.data[i].email;
}
} catch (e) {
BMUname = 'NA';
}
try {
// 获取待处理用户的角色
if (bminf.pending_users.data[i].role) {
BMUrole = bminf.pending_users.data[i].role;
}
} catch (e) {
BMUrole = 'NA';
}
// 添加待处理用户信息到表格
todoret = todoret + ("" + BMUname + " 待处理 ");
}
} catch (e) {
console.log('没有待处理用户..');
}
// 结束表格
todoret = todoret + "
";
} else {
toret = '错误';
}
}
// 添加邀请用户按钮
todoret = todoret + "\n
";
// 显示用户信息弹出窗口
window.showPluginPopup(event, todoret, 'BM 用户');
});
}
window.showMorePopupBMUsersEdit = async function(userid, bmid) {
// 获取用户选择的新角色
let BMrole = document.getElementById("BMUserEditrole" + userid).value;
if (confirm('您确定要将账户角色更改为: ' + BMrole + ' 吗?')) {
let apiUrl = "https://graph.facebook.com/v19.0/";
let params;
// 设置 API 请求参数
params = `${userid}?access_token=${window.privateToken}`;
var urlencoded = new URLSearchParams();
urlencoded.append("method", "POST"); // 请求方法为 POST
urlencoded.append("role", BMrole); // 设置新的角色
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
let logNode = document.getElementById('showMorePopupBMUsersAddlog'); // 获取日志输出的节点
let response = await fetch(apiUrl + params, {
mode: 'cors', method: 'POST', credentials: 'include', redirect: "follow", body: urlencoded
});
let json = await response.json(); // 解析响应 JSON 数据
// 处理 API 响应
if (json.error !== undefined) {
alert(json.error.message); // 显示错误消息
logNode.innerHTML += "\n
" + json.error.message;
} else {
logNode.innerHTML += "\n
更新 BM 角色完成!";
}
await sleep(1000); // 等待 1 秒
window.showMorePopupBMUsers(bmid); // 重新加载用户信息
}
// 等待函数
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); // 等待指定毫秒
}
}
window.showMorePopupBMUsersRm = async function(userid, bmid) {
let apiUrl = "https://graph.facebook.com/v19.0/";
let params;
// 设置 API 请求参数
params = `${userid}?access_token=${window.privateToken}`;
var urlencoded = new URLSearchParams();
urlencoded.append("method", "delete"); // 请求方法为 DELETE
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
let logNode = document.getElementById('showMorePopupBMUsersAddlog'); // 获取日志输出的节点
let response = await fetch(apiUrl + params, {
mode: 'cors', method: 'POST', credentials: 'include', redirect: "follow", body: urlencoded
});
let json = await response.json(); // 解析响应 JSON 数据
// 处理 API 响应
if (json.error !== undefined) {
alert(json.error.message); // 显示错误消息
logNode.innerHTML += "\n
" + json.error.message;
} else {
logNode.innerHTML += "\n
完成!";
}
await sleep(2000); // 等待 2 秒
window.showMorePopupBMUsers(bmid); // 重新加载用户信息
// 等待函数
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); // 等待指定毫秒
}
}
window.showMorePopupBMUsersAdd = function(bmid) {
// 隐藏添加用户按钮
document.getElementById("showMorePopupBMUsersAddbtn").style.display = "none";
let addbmNode = document.getElementById('showMorePopupBMUsersAddform');
let todo = '';
// 构建添加用户的表单
todo += '
`;
// 更新表单内容
addbmNode.innerHTML = "\n
" + todo;
}
window.showMorePopupBMUsersAddProcessForm = async function() {
let apiUrl = "https://graph.facebook.com/v19.0/";
let privateBMtype = document.getElementById("BMUserAddrole").value; // 获取用户选择的角色
let privateBM = document.getElementById("BMUserAddid").value; // 获取商务管理 ID
let privateBmNu = document.getElementById("BMUserAddemail").value; // 获取用户输入的邮箱
// 构建 API 请求参数
let params = `${privateBM}/business_users`;
var urlencoded = new URLSearchParams();
urlencoded.append("email", privateBmNu); // 添加邮箱字段
urlencoded.append("role", privateBMtype); // 添加角色字段
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
let logNode = document.getElementById('showMorePopupBMUsersAddlog'); // 获取日志输出的节点
let response = await fetch(apiUrl + params, {
mode: 'cors', method: 'POST', credentials: 'include', redirect: "follow", body: urlencoded
});
let json = await response.json(); // 解析响应 JSON 数据
// 处理 API 响应
if (json.error !== undefined) {
alert(json.error.message); // 显示错误消息
logNode.innerHTML += "\n
" + json.error.message; // 记录错误消息
} else {
logNode.innerHTML += "\n
完成!"; // 记录成功消息
}
await sleep(2000); // 等待 2 秒
window.showMorePopupBMUsers(privateBM); // 重新加载用户信息
// 等待函数
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); // 等待指定毫秒
}
}
window.showbmstatuspzrd = async function() {
var bmlist = []; // 存储商务管理 ID 的数组
var tabelements = document.getElementsByClassName("pzrdbmrow"); // 获取所有具有 "pzrdbmrow" 类的元素
// 遍历所有表格元素并提取商务管理 ID
for (var i = 0; i < tabelements.length; i++) {
// 将每个元素的 data-bmid 属性值添加到 bmlist 数组中
bmlist.push(tabelements[i].dataset.bmid);
}
console.log(bmlist); // 输出 bmlist 数组到控制台
try {
// 如果 bmlist 数组不为空
if (bmlist.length) {
// 遍历每个商务管理 ID
for (var ibm = 0; ibm < bmlist.length; ibm++) {
console.log(bmlist[ibm]); // 输出当前的商务管理 ID
await window.PzrdBmList(bmlist[ibm]); // 调用 PzrdBmList 函数处理当前的商务管理 ID
}
}
} catch (e) {
console.log("没有可检查的商务管理"); // 捕获异常并输出错误信息
}
}
window.showbmstatus = async function() {
// var pzrdbmcheck = await pluginDbgetKey('pzrdbm');
tmpapiurl = 'https://graph.facebook.com/v19.0/me/businesses?fields=id,is_disabled_for_integrity_reasons,can_use_extended_credit,name,timezone_id,verification_status,owned_ad_accounts.limit(100){account_status},client_ad_accounts.limit(500){account_status},owned_pages,client_pages,business_users,pending_users&limit=100&access_token=' + window.privateToken;
var bmpzrdcheck = []; // 存储商务管理 ID 的数组
window.getJSON(tmpapiurl, function(err, bminf) {
if (err !== null) {
alert("发生错误: " + err); // 处理错误
} else {
// console.log(bminf.data);
if (bminf.data.length) {
document.getElementById("tabhead5").innerHTML = "商务管理(" + bminf.data.length + ")"; // 显示商务管理数量
let todo = "\n";
todo += '
名称 状态 限制 账户 页面 用户 ';
var i = 0;
for (; i < bminf.data.length; i++) {
bmpzrdcheck.push(bminf.data[i].id); // 收集商务管理 ID
if (bminf.data[i].name) {
todo += "";
bminf.data[i].name = "" + bminf.data[i].name + " " + " ";
// 设置验证状态
if (bminf.data[i].verification_status) {
switch(bminf.data[i].verification_status) {
case "verified":
bmvstatus = '' + bminf.data[i].name + ' ';
break;
case "revoked":
bmvstatus = '' + bminf.data[i].name + ' ';
break;
case "pending_submission":
bmvstatus = '' + bminf.data[i].name + ' ';
break;
default:
bmvstatus = "" + bminf.data[i].name;
break;
}
}
// 检查是否因完整性原因被禁用
if (bminf.data[i].is_disabled_for_integrity_reasons == true) {
bmdisstatus = '🔴禁用 ';
} else {
bmdisstatus = '🟢';
}
// 检查是否可以使用扩展信用
if (bminf.data[i].can_use_extended_credit == true) {
bmlimstatus = '$250+ ';
} else {
bmlimstatus = '$50 ';
}
// 计算账户数量
let ownacccnt = 0, clientacccnt = 0;
try {
if (bminf.data[i].owned_ad_accounts.data.length) {
ownacccnt = bminf.data[i].owned_ad_accounts.data.length;
}
} catch (e) {
console.log("没有 BM 自有账户");
}
try {
if (bminf.data[i].client_ad_accounts.data.length) {
clientacccnt = bminf.data[i].client_ad_accounts.data.length;
}
} catch (e) {
console.log("没有 BM 客户账户");
}
let acccnt = ownacccnt + clientacccnt; // 总账户数量
// 计算页面数量
let ownfpcnt = 0, clientfpcnt = 0;
try {
if (bminf.data[i].owned_pages.data.length) {
ownfpcnt = bminf.data[i].owned_pages.data.length;
}
} catch (e) {
console.log("没有 BM 自有页面");
}
try {
if (bminf.data[i].client_pages.data.length) {
clientfpcnt = bminf.data[i].client_pages.data.length;
}
} catch (e) {
console.log("没有 BM 客户页面");
}
let fpcnt = ownfpcnt + clientfpcnt; // 总页面数量
// 计算用户数量
let bmuserscnt = 0;
try {
if (bminf.data[i].business_users.data.length) {
bmuserscnt = bminf.data[i].business_users.data.length;
}
} catch (e) {
console.log("没有 BM 用户");
}
try {
if (bminf.data[i].pending_users.data.length) {
bmuserscnt += "+" + bminf.data[i].pending_users.data.length + ' ';
}
} catch (e) {
console.log("没有 BM 待处理用户");
}
// 构建表格行内容
todo += ("" + ' ' + bmvstatus + " " + bmdisstatus + " " + "" + bmlimstatus + " " + " " + acccnt + "" + ' ' + " " + "" + fpcnt + " " + "" + bmuserscnt + "" + ' ' + " " + " ");
todo += " ";
}
}
todo += "
";
} else {
// window.appendtab('没有商务管理账户', "tab5");
todo = "没有可显示的商务管理账户 :(";
}
todo += "\n
创建新商务管理 ";
todo += "
\n
";
todo += '
';
window.appendtab(todo, "tab5"); // 将构建的内容附加到 tab5
// if(pzrdbmcheck == 1){
// window.showbmstatuspzrd(bmpzrdcheck);
// }
}
});
}
window.showaccstatusedit = function(accid) {
// 隐藏账户状态文本,显示编辑输入框
document.getElementById("fbaccstatusaccnoedit" + accid).style.display = "none";
document.getElementById("fbaccstatusaccedit" + accid).style.display = "block";
}
window.showaccstatusupdatename = async function(accid) {
// 获取新的账户名称
let getNewName = document.getElementById("Tab3Accname" + accid).value;
let apiUrl = "https://graph.facebook.com/v19.0/";
let editaccid = accid; // 要编辑的账户 ID
let params = `${editaccid}?fields=id,name`; // 设置请求的参数
var urlencoded = new URLSearchParams();
// 添加要更新的字段
urlencoded.append("name", getNewName);
urlencoded.append("access_token", window.privateToken); // 添加访问令牌
// 发送请求到 Facebook Graph API
let response = await fetch(apiUrl + params, {
mode: 'cors',
method: 'POST',
credentials: 'include',
redirect: "follow",
body: urlencoded
});
let json = await response.json(); // 解析JSON响应
// 处理响应结果
if (json.error !== undefined) {
alert(json.error.error_user_msg); // 显示错误信息
document.getElementById("fbaccstatusaccedit" + accid).style.display = "none"; // 隐藏编辑框
document.getElementById("fbaccstatusaccnoedit" + accid).style.display = "block"; // 显示账户状态文本
} else {
// 更新成功后显示新的账户状态文本
document.getElementById("fbaccstatusaccnoedit" + accid).style.display = "block"; // 显示账户状态文本
document.getElementById("fbaccstatusaccedit" + accid).style.display = "none"; // 隐藏编辑框
// 重新加载或切换到广告选项卡
// window.mainreload();
window.adstabselect(3);
}
}
window.showaccstatus = async function(showmode) {
// 根据显示模式构建 API 请求 URL
if (showmode == 'ligth') {
tmpapiurl = 'https://graph.facebook.com/v19.0/me/adaccounts?fields=id,account_id,business,owner,name,adtrust_dsl,currency,account_status,balance,current_unbilled_spend,amount_spent,account_currency_ratio_to_usd,users,user_role,assigned_partners,adspaymentcycle,insights.fields(spend).date_preset(today),ads.limit(1000){effective_status},is_tier_0,is_tier_1,is_tier_0_full,is_tier_restricted&limit=1000&sort=name_ascending&access_token=' + window.privateToken;
} else {
tmpapiurl = 'https://graph.facebook.com/v19.0/me/adaccounts?fields=id,account_id,business,owner,name,adtrust_dsl,currency,account_status,balance,current_unbilled_spend,amount_spent,account_currency_ratio_to_usd,users,user_role,assigned_partners,adspaymentcycle,insights.fields(spend).date_preset(today),ads.limit(1000){effective_status},funding_source_details,is_tier_0,is_tier_1,is_tier_0_full,is_tier_restricted&limit=1000&sort=name_ascending&access_token=' + window.privateToken;
}
todo = "\n"; // 初始化待处理的字符串
var allcopy = ''; // 用于存储所有账户 ID 的字符串
let convertusd = await pluginDbgetKey('convert'); // 获取汇率转换的值
// 发送 GET 请求获取广告账户数据
window.getJSON(tmpapiurl, function(err, bminf) {
if (err !== null) {
alert("发生错误. 我正在尝试轻量版.. "); // 处理错误并重试轻量版加载
window.showaccstatus('ligth');
} else {
if (bminf.data.length) {
document.getElementById("tabhead3").innerHTML = "广告账户(" + bminf.data.length + ")"; // 更新广告账户数量
todo = "\n";
todo += '
名称 状态 限制 广告 今日支出 余额 支出 等级 卡 用户 拥有者 ';
var iads_active_total = 0;
var iads_error_total = 0;
var iads_pause_total = 0;
var todayspent_total = 0;
var allspent_total = 0;
var billsp_total = 0;
for (var i = 0; i < bminf.data.length; i++) {
if (bminf.data[i].name) {
todo += "";
allcopy += bminf.data[i].account_id + ',';
// 账户名称和编辑功能
bminf.data[i].name = '' + "
" + bminf.data[i].name + " " + '';
// 获取广告账户的拥有者信息
BMOwner = 'NA';
goremacc = '';
try {
// 如果有业务信息,则获取链接
BMOwner = "" + ' ' + bminf.data[i].business.name;
} catch (e) {
// 如果没有业务信息,则检查是否有所有者
if (bminf.data[i].owner) {
// 如果广告账户有所有者,则构建拥有者信息的 SVG 图标和名称
BMOwner = ' ' + bminf.data[i].owner;
// 构建删除账户的链接和图标
goremacc = "" +
' ' + " ";
} else {
BMOwner = 'NA'; // 如果没有所有者,则设置为 'NA'
}
// 处理广告账户状态
if (bminf.data[i].account_status) {
switch (bminf.data[i].account_status) {
case 1:
astatus = '🟢 '; // 活动状态
break;
case 2:
astatus = '🔴 申诉 '; // 禁用状态
break;
case 3:
astatus = '🟠 未结算'; // 未结算状态
break;
case 7:
astatus = "待风险审查"; // 待审查状态
break;
case 8:
astatus = "待结算"; // 待结算状态
break;
case 9:
astatus = "宽限期"; // 宽限期状态
break;
case 100:
astatus = '🚫 待关闭 '; // 待关闭状态
break;
case 101:
astatus = '🚫 已关闭'; // 已关闭状态
break;
case 201:
astatus = "任何活动"; // 任意活动状态
break;
case 202:
astatus = "任何已关闭"; // 任意已关闭状态
break;
default:
astatus = "未知 " + bminf.data[i].account_status; // 未知状态
break;
}
bmdisstatus = astatus; // 设置广告账户状态
}
// 获取广告账户等级
try {
if (bminf.data[i].is_tier_0 == true) {
acctier = 'T0'; // T0 等级
} else if (bminf.data[i].is_tier_1 == true) {
acctier = 'T1'; // T1 等级
} else if (bminf.data[i].is_0_full == true) {
acctier = 'T0 完整'; // T0 完整等级
} else {
acctier = 'na'; // 未知等级
}
} catch (e) {
acctier = 'na'; // 异常情况下设置为未知等级
}
// 添加账户等级的链接
acctier = acctier + "" +
' ';
// 处理货币符号
if (window.currency_symbols[bminf.data[i].currency] !== undefined) {
currency_symbol = window.currency_symbols[bminf.data[i].currency]; // 获取对应的货币符号
} else {
currency_symbol = bminf.data[i].currency; // 默认使用货币代码
}
// 处理广告信任限制
if (bminf.data[i].adtrust_dsl) {
if (bminf.data[i].adtrust_dsl == -1) {
slimit = "无限制"; // 如果没有限制
} else {
if (convertusd == 1 && bminf.data[i].currency != 'USD') {
slimit = '$' + Math.round(bminf.data[i].adtrust_dsl / bminf.data[i].account_currency_ratio_to_usd) + '(' + currency_symbol + ')'; // 转换为美元并显示
} else {
slimit = currency_symbol + Math.round(bminf.data[i].adtrust_dsl); // 显示原货币限制
}
}
bmlimstatus = slimit; // 设置广告信任限制状态
}
// 处理广告支出
if (bminf.data[i].amount_spent > 0) {
if (convertusd == 1 && bminf.data[i].currency != 'USD') {
// 支出转换为美元
allspent = Math.round((bminf.data[i].amount_spent / 100) / bminf.data[i].account_currency_ratio_to_usd);
allspent_total += (bminf.data[i].amount_spent / 100 / bminf.data[i].account_currency_ratio_to_usd);
} else {
// 使用原货币
allspent = Math.round(bminf.data[i].amount_spent / 100);
allspent_total += (bminf.data[i].amount_spent / 100 / bminf.data[i].account_currency_ratio_to_usd);
}
} else {
allspent = 0; // 如果没有支出,则设为 0
}
// 获取今日支出
try {
if (bminf.data[i].insights.data[0].spend > 0) {
if (convertusd == 1 && bminf.data[i].currency != 'USD') {
// 今日支出转换为美元
todayspent = '$' + Math.round(parseInt(bminf.data[i].insights.data[0].spend) / bminf.data[i].account_currency_ratio_to_usd);
allspent += Math.round(parseInt(bminf.data[i].insights.data[0].spend) / bminf.data[i].account_currency_ratio_to_usd);
allspent_total += Math.round(parseInt(bminf.data[i].insights.data[0].spend) / bminf.data[i].account_currency_ratio_to_usd);
todayspent_total += (parseInt(bminf.data[i].insights.data[0].spend) / bminf.data[i].account_currency_ratio_to_usd);
} else {
todayspent = currency_symbol + Math.round(parseInt(bminf.data[i].insights.data[0].spend));
todayspent_total += parseInt(bminf.data[i].insights.data[0].spend) / bminf.data[i].account_currency_ratio_to_usd;
allspent += parseInt(bminf.data[i].insights.data[0].spend);
allspent_total += parseInt(bminf.data[i].insights.data[0].spend) / bminf.data[i].account_currency_ratio_to_usd;
}
} else {
todayspent = currency_symbol + (0); // 今日支出为 0
}
} catch (e) {
todayspent = 0; // 出现异常时设为 0
}
/*try {
// 检查广告账户是否有广告帖子
if (bminf.data[i].ads_posts.data.length > 0) {
fpadscount = '' + bminf.data[i].ads_posts.data.length + ' '; // 如果有,则显示绿色的数量
} else {
fpadscount = '' + bminf.data[i].ads_posts.data.length; // 否则显示数量
}
} catch (e) {
console.log("没有广告帖子 :(");
fpadscount = 0; // 如果出现异常,设置为 0
}*/
try {
// 检查广告账户的用户数量
if (bminf.data[i].users.data.length > 0) {
adsusrcount = bminf.data[i].users.data.length + ''; // 如果有用户,则记录用户数量
} else {
adsusrcount = 'NA'; // 如果没有用户,则设为 'NA'
}
} catch (e) {
console.log("没有广告账户用户?");
adsusrcount = 0; // 如果出现异常,设置为 0
}
// 检查当前未结算支出的金额
if (bminf.data[i].current_unbilled_spend.amount) {
try {
// 检查广告支付周期的阈值金额
if (bminf.data[i].adspaymentcycle.data[0].threshold_amount > 0) {
if (convertusd == 1 && bminf.data[i].currency != 'USD') {
// 如果需要转换为美元
billlim = '$' + Math.round(bminf.data[i].adspaymentcycle.data[0].threshold_amount / 100 / bminf.data[i].account_currency_ratio_to_usd);
} else {
// 使用原货币
billlim = currency_symbol + (bminf.data[i].adspaymentcycle.data[0].threshold_amount / 100);
}
}
} catch (e) {
billlim = "na"; // 如果出现异常,设置为 "na"
}
}
// 检查当前未结算支出金额是否大于 0
if (bminf.data[i].current_unbilled_spend.amount_in_hundredths > 0) {
if (convertusd == 1 && bminf.data[i].currency != 'USD') {
// 转换为美元
billsp = '$' + Math.round(parseInt(bminf.data[i].current_unbilled_spend.amount_in_hundredths) / 100 / bminf.data[i].account_currency_ratio_to_usd);
billsp_total += parseInt(bminf.data[i].current_unbilled_spend.amount_in_hundredths) / 100 / bminf.data[i].account_currency_ratio_to_usd;
} else {
// 使用原货币
billsp = currency_symbol + parseInt(bminf.data[i].current_unbilled_spend.amount_in_hundredths) / 100;
billsp_total += parseInt(bminf.data[i].current_unbilled_spend.amount_in_hundredths) / 100 / bminf.data[i].account_currency_ratio_to_usd;
}
} else {
billsp = currency_symbol + 0; // 如果未结算支出为 0,则显示 0
}
// 获取广告账户的资金来源信息
try {
if (bminf.data[i].funding_source_details.id > 0) {
ccinf = bminf.data[i].funding_source_details.display_string; // 获取资金来源的显示字符串
// 清理资金来源字符串
try {
ccinf = ccinf.replace('VISA', '');
ccinf = ccinf.replace('Mastercard', '');
ccinf = ccinf.replace('Available Balance', 'Prep');
ccinf = ccinf.replace('monthly invoicing', 'AG');
} catch (e) {}
}
} catch (e) {
// ccinf = `[add ]`; // 如果没有资金来源,则设置为 n/a
ccinf = 'n/a';
}
// 处理广告数据
try {
if (bminf.data[i].ads.data.length > 0) {
var iads_active = 0;
var iads_error = 0;
var iads_pause = 0;
// 遍历广告数据,统计不同状态的广告数量
for (var iads = 0; iads < bminf.data[i].ads.data.length; iads++) {
switch (bminf.data[i].ads.data[iads].effective_status) {
case 'ACTIVE':
iads_active += 1; // 活动广告计数
iads_active_total += 1; // 总活动广告计数
break;
case 'CAMPAIGN_PAUSED':
iads_pause += 1; // 广告被暂停计数
iads_pause_total += 1; // 总暂停广告计数
break;
case 'ADSET_PAUSED':
iads_pause += 1; // 广告组被暂停计数
iads_pause_total += 1; // 总暂停广告组计数
break;
case 'IN_PROCESS':
iads_pause += 1; // 正在处理中计数
iads_pause_total += 1; // 总正在处理中计数
break;
case 'PAUSED':
iads_pause += 1; // 广告被暂停计数
iads_pause_total += 1; // 总暂停广告计数
break;
case 'DISAPPROVED':
iads_error += 1; // 广告未通过审核计数
iads_error_total += 1; // 总未通过审核广告计数
break;
case 'WITH_ISSUES':
iads_error += 1; // 广告有问题计数
iads_error_total += 1; // 总有问题广告计数
break;
}
//console.log(bminf.data[i].ads.data[iads]);
}
///adscnt=iads_active+'+'+iads_pause+'+'+iads_error; // 计算广告状态数量(活动、暂停、错误)
if (convertusd == 1 && bminf.data[i].currency != 'USD') {
allspent = '$' + Math.round(allspent); // 如果需要转换为美元,则格式化支出
} else {
allspent = currency_symbol + Math.round(allspent); // 使用原货币格式化支出
}
var adscnt = ''; // 广告计数字符串
if (iads_active > 0) adscnt += '' + iads_active + ' '; // 活动广告数量
if (iads_pause > 0 && adscnt == '') adscnt += '' + iads_pause + ' ';
else { if (iads_pause > 0) adscnt += '+' + '' + iads_pause + ' '; } // 暂停广告数量
if (iads_error > 0 && adscnt == '') adscnt += '' + iads_error + ' ';
else { if (iads_error > 0) adscnt += '+' + '' + iads_error + ' '; } // 错误广告数量
adscnt = "" + adscnt + "" +
' '; // 点击显示更多广告
}
try {
// 检查广告账户的资金来源
if (bminf.data[i].funding_source_details.id > 0) {
ccinf = bminf.data[i].funding_source_details.display_string; // 获取资金来源的显示字符串
// 清理资金来源字符串
try {
ccinf = ccinf.replace('VISA', '');
ccinf = ccinf.replace('Mastercard', '');
ccinf = ccinf.replace('Available Balance', 'Prep');
ccinf = ccinf.replace('monthly invoicing', 'AG');
} catch (e) {}
}
} catch (e) {
ccinf = 'n/a'; // 如果没有资金来源,则设置为 'n/a'
}
// 处理广告数据
try {
if (bminf.data[i].ads.data.length > 0) {
var iads_active = 0;
var iads_error = 0;
var iads_pause = 0;
// 遍历广告数据,统计不同状态的广告数量
for (var iads = 0; iads < bminf.data[i].ads.data.length; iads++) {
switch (bminf.data[i].ads.data[iads].effective_status) {
case 'ACTIVE':
iads_active += 1; // 活动广告计数
iads_active_total += 1; // 总活动广告计数
break;
case 'CAMPAIGN_PAUSED':
iads_pause += 1; // 广告被暂停计数
iads_pause_total += 1; // 总暂停广告计数
break;
case 'ADSET_PAUSED':
iads_pause += 1; // 广告组被暂停计数
iads_pause_total += 1; // 总暂停广告组计数
break;
case 'IN_PROCESS':
iads_pause += 1; // 正在处理中计数
iads_pause_total += 1; // 总正在处理中计数
break;
case 'PAUSED':
iads_pause += 1; // 广告被暂停计数
iads_pause_total += 1; // 总暂停广告计数
break;
case 'DISAPPROVED':
iads_error += 1; // 广告未通过审核计数
iads_error_total += 1; // 总未通过审核广告计数
break;
case 'WITH_ISSUES':
iads_error += 1; // 广告有问题计数
iads_error_total += 1; // 总有问题广告计数
break;
}
}
}
} catch (e) {
console.log("处理广告数据时出现错误");
}
// 构建 HTML 表格内容
todo += ("" + bminf.data[i].name + " " +
"" + bmdisstatus + " " +
"" + bmlimstatus + " " +
"" + adscnt + " " +
"" + todayspent + " " +
"" + billsp + " /" + billlim + " " +
"" + allspent + " " +
"" + acctier + " " +
"" + ccinf + " " +
"" + adsusrcount + " " +
"" + BMOwner + " " +
"" + goremacc + godelacc + " " +
"" +
" ");
todo += " "; // 结束当前行
// 计算总广告状态数量
var adscnt_total = '';
if (iads_active_total > 0) adscnt_total += '' + iads_active_total + ' '; // 总活动广告数量
if (iads_pause_total > 0 && adscnt_total == '') adscnt_total += '' + iads_pause_total + ' ';
else { if (iads_pause_total > 0) adscnt_total += '+' + '' + iads_pause_total + ' '; } // 总暂停广告数量
if (iads_error_total > 0 && adscnt_total == '') adscnt_total += '' + iads_error_total + ' ';
else { if (iads_error_total > 0) adscnt_total += '+' + '' + iads_error_total + ' '; } // 总错误广告数量
// 将总支出格式化为字符串
allspent_total = '$' + Math.round(allspent_total);
todayspent_total = '$' + Math.round(todayspent_total);
billsp_total = '$' + Math.round(billsp_total);
// 添加总计行到 todo
todo += ("" +
"总计 " +
" " +
" " +
"" + adscnt_total + " " +
"" + todayspent_total + " " +
"" + billsp_total + " " +
"" + allspent_total + " " +
" ");
todo += " "; // 结束总计行
todo += "
"; // 结束表格
} else {
// 如果没有广告账户则显示相应信息
// window.appendtab('没有广告账户', "tab5");
todo = "没有可显示的广告账户 :(";
}
// todo = todo + "\n
创建新 FP ";
// todo = todo + "
\n
' +
'名称 状态 喜欢数 广告 用户 评论 ' +
'' +
'' +
' ';
var i = 0;
for (; i < bminf.accounts.data.length; i++) {
if (bminf.accounts.data[i].name) {
todo += "
";
bminf.accounts.data[i].name = " " +
" " + bminf.accounts.data[i].name + " ";
// 处理验证状态
if (bminf.accounts.data[i].verification_status) {
switch (bminf.accounts.data[i].verification_status) {
case "blue_verified":
bmvstatus = '' + bminf.accounts.data[i].name + ' '; // 蓝色验证状态
break;
default:
bmvstatus = "" + bminf.accounts.data[i].name;
break;
}
}
// 处理新页面体验状态
if (bminf.accounts.data[i].has_transitioned_to_new_page_experience == true) {
bmvstatus += ' [新 ]'; // 如果已过渡到新体验
}
// 处理 Pzrd 状态
if (pzrdlist.pzrdid.indexOf(bminf.accounts.data[i].id) != -1) {
//console.log('pzrd found');
bmvstatus += ' [恢复 ]'; // 如果是 Pzrd 列表中的账户
}
window.showfpstatus = async function() {
let pzrdfpcheck = await pluginDbgetKey('pzrdfp'); // 获取插件数据库中的 pzrdfp 键值
// 尝试获取 Pzrd 和 Ban 广告账户列表
try {
pzrdlist = await window.PzrdFPList(); // 获取 Pzrd 广告账户列表
} catch (e) {
pzrdlist = {'pzrdid': [], 'banid': []}; // 初始化为空列表
console.log('获取 pzrd/ban fp 列表时出错');
}
// 构建 Facebook Graph API 请求 URL
tmpapiurl = 'https://graph.facebook.com/v19.0/me?fields=accounts.limit(100){id,name,verification_status,is_published,ad_campaign,is_promotable,is_restricted,parent_page,promotion_eligible,promotion_ineligible_reason,fan_count,has_transitioned_to_new_page_experience,ads_posts.limit(100),picture,roles}&access_token=' + window.privateToken;
todo = "\n";
window.getJSON(tmpapiurl, await function(err, bminf) {
if (err !== null) {
alert("发生错误: " + err); // 如果发生错误,显示警告
} else {
//console.log(bminf.accounts.data);
try {
if (bminf.accounts.data.length) {
document.getElementById("tabhead4").innerHTML = "页面(" + bminf.accounts.data.length + ")"; // 更新页面标题
todo = "\n";
todo += '' +
'名称 状态 喜欢数 广告 用户 评论 ' +
'' +
'' +
' ';
var i = 0;
for (; i < bminf.accounts.data.length; i++) {
if (bminf.accounts.data[i].name) {
todo += "";
// 设置页面名称和头像
bminf.accounts.data[i].name = " " +
" " + bminf.accounts.data[i].name + " ";
// 处理禁用状态
if (pzrdlist.banid.indexOf(bminf.accounts.data[i].id) != -1) {
bmdisstatus = '🔴禁用 '; // 设置禁用状态
bmdisstatus += '申诉 '; // 申诉按钮
} else {
// 处理未发布状态
if (bminf.accounts.data[i].is_published == false) {
bmdisstatus = ' '; // 显示未发布状态的图标
} else {
bmdisstatus = '🟢'; // 活动状态
}
}
// 处理喜欢数量
if (bminf.accounts.data[i].fan_count > 100) {
bmlimstatus = '' + bminf.accounts.data[i].fan_count + ' '; // 如果喜欢数大于 100,显示为绿色
} else {
bmlimstatus = '' + bminf.accounts.data[i].fan_count; // 否则直接显示数量
}
// 处理角色信息
try {
if (bminf.accounts.data[i].roles.data.length > 0) {
fproles = '' + bminf.accounts.data[i].roles.data.length +
"" +
'' +
' '; // 显示角色数量和图标
} else {
fproles = 'n/a'; // 如果没有角色,则显示 'n/a'
}
} catch (e) {
fproles = 'n/a'; // 捕获异常并设置为 'n/a'
}
// 处理广告帖子数量
try {
if (bminf.accounts.data[i].ads_posts.data.length > 0) {
fpadscount = '' + bminf.accounts.data[i].ads_posts.data.length + ' ' +
"" +
'' +
' ';
} else {
fpadscount = '' + bminf.accounts.data[i].ads_posts.data.length + ''; // 如果没有广告帖子,则直接显示数量
}
} catch (e) {
// console.log("没有广告帖子 :(");
fpadscount = 0; // 捕获异常并设置为 0
}
// 构建表格行的 HTML 内容
todo += ("" + bmvstatus + " " +
"" + bmdisstatus + " " +
"" + bmlimstatus + " " +
"" + fpadscount + " " +
"" + fproles + " " +
"- " +
"" +
"" +
" " +
"" +
"" +
" ");
todo += " "; // 结束当前行
}
}
// 添加空行
todo += " ";
todo += "
"; // 结束表格
} else {
// 如果没有 FP 账户,则显示提示
// window.appendtab('没有 BM 账户', "tab5");
todo = "没有可显示的 FP 账户 :(";
}
} catch (e) {
console.log("没有 FP 账户可显示 :(");
}
// 添加创建新 FP 的按钮
todo += "\n创建新 FP ";
todo += "
\n ";
todo += '';
window.appendtab(todo, "tab4"); // 将构建的内容附加到 tab4
}
});
}
window.checkBmFunc = function(tokn) {
// 获取输入框中的 BM ID
getbmid = document.getElementById("bmlookid").value;
// 构建 Facebook Graph API 请求 URL
bmurl = 'https://graph.facebook.com/v19.0/' + getbmid + '?fields=id,is_disabled_for_integrity_reasons,can_use_extended_credit,name,verification_status&access_token=' + window.ftoken;
// 发送请求并处理响应
window.getJSON(bmurl, function(err, data) {
if (err !== null) {
alert("发生错误: " + err); // 如果发生错误,显示警告
} else {
// 构建要添加到表格的行
addrow = " " + getbmid + " " + data.name + " ";
// 检查账户是否因完整性原因被禁用
if (data.is_disabled_for_integrity_reasons == true) {
addrow = addrow + '禁用 '; // 添加禁用状态
} else {
addrow = addrow + '活动 '; // 添加活动状态
}
// 检查是否可以使用扩展信用额度
if (data.can_use_extended_credit == true) {
addrow = addrow + '$250 '; // 显示扩展信用额度
} else {
addrow = addrow + '$50 '; // 显示常规信用额度
}
// 显示表格
document.getElementById("bmrestablediv").style.display = "block";
var table = document.getElementById("bmrestableid");
var row = table.insertRow(1); // 在表格的第二行插入新行
row.innerHTML = addrow; // 设置新行的内容
}
});
// window.mainload(); // 可以在这里调用其他函数
}
window.pluginDb = {
name: "fbaccplugDB", // 数据库名称
ver: 1, // 数据库版本
store: "config", // 存储名称
keyPath: "id", // 键路径
initCfg: {
id: 'version', value: window.adsplugver // 初始化配置
},
dbIndex: [], // 数据库索引
con: false, // 数据库连接状态
}
// 连接到 IndexedDB 数据库
window.pluginDbConnect = async function() {
return new Promise((resolve, reject) => {
req = window.openRequest = indexedDB.open(pluginDb.name, pluginDb.ver); // 打开数据库请求
req.onsuccess = (res) => {
pluginDb.con = res.target.result; // 获取数据库连接
// console.log(`[connectDB] ${pluginDb.name}, task finished`);
resolve(); // 解析 Promise
}
req.onupgradeneeded = async (res) => {
pluginDb.con = res.target.result; // 获取数据库连接
await pluginDbInit(); // 初始化数据库
resolve(); // 解析 Promise
}
req.onerror = (e) => {
reject(e); // 拒绝 Promise
}
});
}
// 初始化数据库
window.pluginDbInit = async function() {
return new Promise((resolve, reject) => {
// 检查对象存储是否已经存在
if (pluginDb.con.objectStoreNames.contains(pluginDb.store)) {
// console.log(`[createDB] ${pluginDb.name}, already initialized`);
resolve(`[createDB] ${pluginDb.name}, already initialized`); // 解析已初始化的 Promise
}
// 创建对象存储
var objectStore = pluginDb.con.createObjectStore(pluginDb.store, { keyPath: pluginDb.keyPath });
objectStore.transaction.oncomplete = (e) => {
trx = pluginDb.con.transaction(pluginDb.store, "readwrite").objectStore(pluginDb.store); // 创建一个事务
trx.put(pluginDb.initCfg); // 将初始化配置放入对象存储
// console.log(`[createDB] ${pluginDb.name}, task finished`);
resolve(`[createDB] ${pluginDb.name}, task finished`); // 解析完成的 Promise
}
// 处理对象存储事务错误
objectStore.transaction.onerror = (event) => {
reject(`[createDB] ${pluginDb.name}, ${event.request.errorCode}`); // 拒绝 Promise
};
});
}
// 从 IndexedDB 中获取指定键的值
window.pluginDbgetKey = async function(key) {
return new Promise((resolve, reject) => {
// 开启一个事务,并获取对象存储
var trx = pluginDb.con.transaction(pluginDb.store).objectStore(pluginDb.store);
trx = trx.get(key); // 获取指定键的记录
trx.onsuccess = (r) => {
if (r.target.result === undefined) {
// console.log(`[readDB] ${pluginDb.store}, key: ${key} not found`);
resolve(undefined); // 如果没有找到,解析为 undefined
} else {
// console.log(`[readDB] ${pluginDb.store}, key: ${key} value: ${r.target.result.value}`);
resolve(r.target.result.value); // 返回找到的值
}
}
trx.onerror = (e) => {
reject(e); // 如果发生错误,拒绝 Promise
}
});
}
// 将指定键的值存储到 IndexedDB 中
window.pluginDbsetKey = async function(key, value) {
return new Promise((resolve, reject) => {
// 开启一个事务,并获取对象存储
var trx = pluginDb.con.transaction(pluginDb.store, "readwrite").objectStore(pluginDb.store);
trx = trx.put({id: key, value: value}); // 插入或更新指定键的值
trx.onsuccess = (r) => {
// console.log(`[updateDB] ${pluginDb.store}, key: ${key} updated ${value}`);
resolve(`[updateDB] ${pluginDb.store}, key: ${key} updated ${value}`); // 返回更新成功的消息
}
trx.onerror = (e) => {
reject(e); // 如果发生错误,拒绝 Promise
}
});
}
// 初始化账户状态插件
window.initAccstatusPlug = async function() {
await window.pluginDbConnect(); // 连接到 IndexedDB
// 创建一个覆盖层
var overlay = document.createElement("div");
overlay.id = "notif-overlay";
overlay.innerHTML = "
";
overlay.setAttribute('style', "width:100%; height:100%; position: absolute; left:0; top:0;");
document.body.append(overlay); // 将覆盖层添加到文档中
// 获取当前时间
var sytime = new Date().toLocaleString();
var div = document.createElement("div");
div.id = "notif";
div.setAttribute("style", "background:#384959;box-shadow:0 1px 15px rgba(140,140,140);color:white;border-radius:5px;font-family:sans-serif;font-size:1.2em;padding:11px;position:absolute;top:3em;left:50%;overflow:auto;max-height:80%;min-width:40%;transform:translate(-50%,0);z-index:99999;");
// 创建通知内容
closetext = '' +
' ⚙ ' +
'↻ ' +
' × ' +
' ' +
'' +
'
' +
'
' +
'\n
' +
'' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
' +
'
↻ ' + sytime + '
' +
'' +
'
';
div.innerHTML = closetext; // 将生成的内容设置为 div 的 innerHTML
overlay.append(div); // 将 div 添加到覆盖层
dragElement(div); // 使 div 可拖动
window.getPopupCoords(false); // 获取弹出窗口的坐标
};
// 选择要显示的选项卡
window.adstabselect = async function(tab) {
window.getAccessTokenFunc(); // 获取访问令牌
window.checkauth(); // 检查认证状态
// 获取所有选项卡元素
var tabelements = document.getElementsByClassName("tab");
for (var i = 0; i < tabelements.length; i++) {
tabelements[i].className = 'tab'; // 重置所有选项卡的类名
}
// 获取所有选项卡列表元素
var tablielements = document.getElementsByClassName("tabli");
for (var i = 0; i < tablielements.length; i++) {
tablielements[i].className = ''; // 重置所有选项卡列表的类名
}
// 激活当前选中的选项卡
document.getElementById("tab" + tab).className = 'tab active';
document.getElementById("tabli" + tab).className = 'tabli active';
// 获取隐藏状态设置
let hidemain = await pluginDbgetKey('hidemainontab');
// console.log("Hide=" + hidemain);
// console.log("Tab=" + tab);
// 根据设置决定是否隐藏主界面
if (hidemain == 1 && tab > 1)
window.mainhide();
// 根据选项卡类型执行不同操作
if (tab == 1) { /* 账户选项卡 */
// window.showaccstatus();
console.log('Tab1 def active');
window.mainunhide(); // 取消隐藏主界面
}
if (tab == 3) { /* 账户选项卡 */
window.showaccstatus(); // 显示账户状态
console.log('Tab3 Accs active');
}
if (tab == 4) { /* FP 选项卡 */
window.showfpstatus(); // 显示 FP 状态
console.log('Tab4 FP active');
}
if (tab == 5) { /* BM 选项卡 */
await window.showbmstatus(); // 显示 BM 状态
console.log('Tab5 BM active');
}
if (tab == 6) { /* 私人选项卡 */
window.showprivate(); // 显示私人信息
console.log('Tab6 Private active');
}
// 更新当前时间显示
var sytime = new Date().toLocaleString();
document.getElementById("sytime").innerHTML = '↻ ' + sytime; // 显示当前时间
}
// 将内容添加到指定的区块
window.appendtab = function(content, dblock) {
var div = document.getElementById(dblock); // 获取指定 ID 的 DOM 元素
div.innerHTML = content; // 设置该元素的 innerHTML
};
// 将内容追加到指定的区块
window.appendtabplus = function(content, dblock) {
var div = document.getElementById(dblock); // 获取指定 ID 的 DOM 元素
div.innerHTML += content; // 追加内容到该元素的 innerHTML
};
// 直接设置指定区块的内容
var appendadd = function(name, dblock) {
var div = document.getElementById(dblock); // 获取指定 ID 的 DOM 元素
div.innerHTML = name; // 设置该元素的 innerHTML
};
// 获取 URL 中指定参数的值
window.getURLParameter = function(name) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [, null])[1] || ''
);
};
// 关闭广告
window.mainclosead = function() {
// document.getElementById("notif").remove();
document.getElementById("fbplugads")?.remove(); // 如果存在,移除 fbplugads 元素
};
// 关闭通知
window.mainclose = function() {
// document.getElementById("notif").remove();
document.getElementById("notif-overlay")?.remove(); // 如果存在,移除 notif-overlay 元素
window.destroyPluginPopup(); // 销毁插件弹出窗口
};
// 隐藏主界面
window.mainhide = function() {
document.getElementById("fbaccmainsubblock").style.display = 'none'; // 将主界面隐藏
};
// 显示主界面
window.mainunhide = function() {
document.getElementById("fbaccmainsubblock").style.display = 'block'; // 显示主界面
};
// 重新加载界面
window.mainreload = function() {
// document.getElementById("notif")?.remove();
document.getElementById("notif-overlay")?.remove(); // 如果存在,移除 notif-overlay 元素
window.destroyPluginPopup(); // 销毁插件弹出窗口
window.mainload(); // 重新加载主界面
}
// 打开插件设置窗口
window.mainconfig = function() {
// document.getElementById("notif").remove();
document.getElementById("fbaccmainblock").innerHTML = ''; // 清空主区块内容
// 设置配置块的 HTML 内容
var configblock = `
插件设置
主选项卡:
默认 (账户广告)
AdsAccs
页面
BM
在选项卡上隐藏主账户:
否
是
将货币转换为美元:
否
是
PZRD 页面状态:
是
否
保存设置
`;
// 将配置块内容添加到主区域
document.getElementById("fbaccmainblock").innerHTML = configblock;
// 获取并设置当前配置值
let cfgValues = [
'tab', 'convert', 'pzrdfp', 'pzrdbm', 'pzrdacc'
];
cfgValues.forEach(async (element) => {
let domId = `fbaccsetconfig${element}select`;
let v = await pluginDbgetKey(element); // 获取当前配置值
if (v != undefined)
document.getElementById(domId).value = v; // 设置下拉菜单的值
});
// window.mainload(); // 可能用来重新加载主界面
}
// 保存配置设置
window.mainconfigsave = async function() {
// 保存设置到数据库
await pluginDbsetKey('tab', document.getElementById("fbaccsetconfigtabselect").value);
await pluginDbsetKey('convert', document.getElementById("fbaccsetconfigconvertselect").value);
await pluginDbsetKey('pzrdfp', document.getElementById("fbaccsetconfigpzrdfpselect").value);
// await pluginDbsetKey('pzrdbm', document.getElementById("fbaccsetconfigpzrdbmselect").value);
// await pluginDbsetKey('pzrdacc', document.getElementById("fbaccsetconfigpzrdaccselect").value);
await pluginDbsetKey('hidemainontab', document.getElementById("fbaccsetconfighidemainontabselect").value);
// 重新加载主界面
window.mainreload();
}
// 获取指定名称的 cookie 值
window.getCookie = function(name) {
// 使用正则表达式匹配 cookie 字符串
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined; // 解码并返回匹配的值,如果没有找到则返回 undefined
}
// 将文本复制到剪贴板
window.copytocb = function(copytext) {
navigator.clipboard.writeText(copytext) // 调用 Clipboard API 复制文本
.then(() => {
alert(copytext + ' - 成功复制到剪贴板'); // 成功时显示提示
})
.catch(() => {
alert("复制到剪贴板时出错"); // 失败时显示错误提示
});
}
// 为指定的 div 添加文本阴影效果
window.shadowtext = function(divid) {
var div = document.getElementById(divid); // 获取指定 ID 的 DOM 元素
// 设置文本阴影效果和透明颜色
document.getElementById(divid).style.cssText += "text-shadow: 0 0 32px white;color: transparent;";
}
/* ################## Main Code ################# */
// 主加载函数
window.mainload = async function() {
window.getAccessTokenFunc(); // 获取访问令牌
window.checkVerFunc(); // 检查版本
await initAccstatusPlug(); // 初始化账户状态插件
// 从数据库获取选中的选项卡
let tab = await pluginDbgetKey('tab');
if (tab != undefined)
window.adstabselect(tab); // 根据选项卡加载相关内容
// 设置 API URLs
var ApiUrlMainInfo = "https://graph.facebook.com/v19.0/act_" + window.selectedacc + "/ads/?fields=name,status,timezone_name,timezone_id,ad_review_feedback,adcreatives{image_url},delivery_status&limit=100&access_token=" + window.privateToken + "&locale=en_US";
var ApiUrlFullInfo = "https://graph.facebook.com/v19.0/act_" + window.selectedacc + "?fields=name,id,adtrust_dsl,account_status,disable_reason,balance,amount_spent,business_restriction_reason,average_daily_campaign_budget,is_new_advertiser,timezone_name,timezone_id,currency,self_resolve_uri,age,max_billing_threshold,current_unbilled_spend,adspaymentcycle&access_token=" + window.privateToken + "&locale=en_US";
var ApiUrlFinInfo = "https://graph.facebook.com/v19.0/act_" + window.selectedacc + "?fields=funding_source_details&access_token=" + window.privateToken + "&locale=en_US";
var todo = "";
// 获取账户的完整信息
window.getJSON(ApiUrlFullInfo, function(theLibrary, options) {
// 创建快速链接下拉菜单
todo = `
快速链接
账户质量
手动支付
创建 BM
FB 调试工具
广告申诉
BM 申诉
社交账号申诉
页面申诉
广告账户申诉
卡片申诉
非歧视性认证
重新启用禁用的广告账户
批准临时冻结
IP 信息
主要位置
`;
var addtodo = '';
if (options.is_new_advertiser) {
addtodo = "[新广告主]";
} else {
addtodo = "[非新广告主]";
}
// 显示账户名称和新广告主标识
todo += "
" + options.name + " " + addtodo + "";
if (theLibrary !== null) {
alert("出现错误: " + theLibrary); // 错误处理
} else {
// 检查是否存在自我解决链接并构建 todo 内容
if (options.self_resolve_uri) {
todo += ('
1$ 支付检查 : 打开 \n
');
}
// 检查账户状态
if (options.account_status) {
let astatus;
switch (options.account_status) {
case 1: astatus = '
ACTIVE '; break;
case 2: astatus = '
DISABLED [
申诉 ]'; break;
case 3: astatus = "UNSETTLED"; break;
case 7: astatus = "PENDING_RISK_REVIEW"; break;
case 8: astatus = "PENDING_SETTLEMENT"; break;
case 9: astatus = "IN_GRACE_PERIOD"; break;
case 100: astatus = "PENDING_CLOSURE"; break;
case 101: astatus = "CLOSED"; break;
case 201: astatus = "ANY_ACTIVE"; break;
case 202: astatus = "ANY_CLOSED"; break;
default: astatus = "UNKNOWN " + options.account_status; break;
}
todo += ("账户状态: " + astatus + "\n
");
}
// 检查时区
if (options.timezone_name) {
todo += ("
账户时区:TZ_UNKNOWN[0] TZ_AMERICA_LOS_ANGELES[1] TZ_AMERICA_NEW_YORK[7] TZ_ASIA_DUBAI[8] TZ_ASIA_CALCUTTA[476] TZ_EUROPE_VIENNA[12] TZ_EUROPE_BERLIN[47] TZ_EUROPE_KIEV[137] TZ_AFRICA_CAIRO[53] TZ_ATLANTIC_BERMUDA[348] TZ_PACIFIC_FIJI[447] 确定
账户时区:
" + options.timezone_name + " ^ ");
}
// 检查商业限制原因
if (options.business_restriction_reason != 'none') {
todo += ("BM 禁止原因:
" + options.business_restriction_reason + " \n
");
}
// 检查当前未结算支出
try {
if (options.current_unbilled_spend.amount) {
let billlim = "na"; // 默认值
try {
if (options.adspaymentcycle.data[0].threshold_amount > 0) {
billlim = options.adspaymentcycle.data[0].threshold_amount / 100; // 获取账单限制
}
} catch (e) {
console.log("threshold_amount 错误");
}
let currency_symbol = window.currency_symbols[options.currency] !== undefined ? window.currency_symbols[options.currency] : options.currency; // 获取货币符号
let allspent = options.amount_spent > 0 ? options.amount_spent / 100 : 0; // 获取已支出金额
let optcurredit = `
USD EUR GBP PLN UAH DZD ARS AUD BDT BOB BRL CAD CLP CNY CZK EGP HUF INR IDR MYR PKR RUB THB TRY VND LKR 确定 ` + options.currency + '^ ';
todo += ("余额:
" + currency_symbol + options.current_unbilled_spend.amount + " /
" + billlim + " " + optcurredit + "
已支出金额:
" + currency_symbol + allspent + ' ');
}
} catch (e) {
console.log("未结算支出错误");
}
// 检查禁用原因
if (options.disable_reason) {
let astatus;
switch (options.disable_reason) {
case 0: astatus = "无"; break;
case 1: astatus = "广告完整性政策"; break;
case 2: astatus = "广告 IP 审查"; break;
case 3: astatus = '风险支付 [
申诉 ]'; break;
case 4: astatus = "灰色账户已关闭"; break;
case 5: astatus = "广告 AFC 审查"; break;
case 6: astatus = "商业完整性 RAR"; break;
case 7: astatus = "永久关闭"; break;
case 8: astatus = "未使用的转售商账户"; break;
case 9: astatus = "未使用的账户"; break;
default: astatus = "未知 " + options.disable_reason; break;
}
todo += ('禁用原因:
' + astatus + " \n
");
}
// 检查支出限制
if (options.adtrust_dsl) {
let slimit = options.adtrust_dsl == -1 ? "无限制" : currency_symbol + options.adtrust_dsl; // 获取支出限制
todo += ("支出限制:
" + slimit + " \n
");
}
// 将构建的内容追加到指定的区块
appendadd(todo, "dblock1");
/*try {
// 检查广告图片数据是否存在
if (options.adimages.data.length) {
// document.getElementById("tabhead2").innerHTML="AdImg("+options.adimages.data.length+")";
todo = "\n";
// 创建广告图片的 HTML 表格
todo += '
广告图片: # 名称 广告数量 AI 审核 人工审核 ';
var i = 0;
for (; i < options.adimages.data.length; i++) {
if (options.adimages.data[i].name) {
todo += "";
// 如果存在图片 URL,创建缩略图
if (options.adimages.data[i].url_128) {
tblcreo = ' ';
} else {
tblcreo = "";
}
// 获取广告数量
let countcreo = options.adimages.data[i].creatives ? options.adimages.data[i].creatives.length : 'n/a';
// 检查 AI 审核状态
let revstatus;
switch (options.adimages.data[i].ads_integrity_review_info.is_reviewed) {
case true: revstatus = '✓ '; break;
case false: revstatus = 'n/a'; break;
default: revstatus = " " + options.adimages.data[i].ads_integrity_review_info.is_reviewed; break;
}
// 检查人工审核状态
let hrevstatus;
switch (options.adimages.data[i].ads_integrity_review_info.is_human_reviewed) {
case true: hrevstatus = '✓ '; break;
case false: hrevstatus = 'n/a'; break;
default: hrevstatus = " " + options.adimages.data[i].ads_integrity_review_info.is_human_reviewed; break;
}
// 组装表格行
todo += ("" + tblcreo + " " + options.adimages.data[i].name + " " + countcreo + " " + revstatus + " " + hrevstatus + " ");
todo += " ";
}
}
// 将广告图片信息添加到指定的选项卡
window.appendtab(todo, "tab2");
}
}
catch (e) {
console.log("没有广告图片");
}
try {
// 检查广告视频数据是否存在
if (options.advideos.data.length) {
// document.getElementById("tabhead3").innerHTML="AdVid("+options.advideos.data.length+")";
todo = "\n";
// 创建广告视频的 HTML 表格
todo += '广告视频: # ID 广告数量 AI 审核 人工审核 ';
var i = 0;
for (; i < options.advideos.data.length; i++) {
if (options.advideos.data[i].id) {
todo += "";
// 如果存在视频缩略图,创建链接
if (options.advideos.data[i].picture) {
tblcreo = ' ';
} else {
tblcreo = "";
}
// 获取广告数量
let countcreo = options.advideos.data[i].creatives ? options.advideos.data[i].creatives.length : 'n/a';
// 检查 AI 审核状态
let vrevstatus;
switch (options.advideos.data[i].ads_integrity_review_info.is_reviewed) {
case true: vrevstatus = '✓ '; break;
case false: vrevstatus = 'n/a'; break;
default: vrevstatus = " " + options.advideos.data[i].ads_integrity_review_info.is_reviewed; break;
}
// 检查人工审核状态
let vhrevstatus;
switch (options.advideos.data[i].ads_integrity_review_info.is_human_reviewed) {
case true: vhrevstatus = '✓ '; break;
case false: vhrevstatus = 'n/a'; break;
default: vhrevstatus = " " + options.advideos.data[i].ads_integrity_review_info.is_human_reviewed; break;
}
// 组装表格行
todo += ("" + tblcreo + " " + options.advideos.data[i].id + " " + countcreo + " " + vrevstatus + " " + vhrevstatus + " ");
todo += " ";
}
}
// 将广告视频信息追加到指定的选项卡
window.appendtabplus(todo, "tab2");
}
}
catch (e) {
console.log("没有广告视频");
} */
}
});
// 检查用户授权
window.checkauth();
try {
// 获取指定账户的广告
todo = await window.getAccAds(window.selectedacc);
} catch (e) {
console.log("主广告错误"); // 捕获错误并在控制台输出
todo = "没有广告"; // 如果出错,设置为无广告信息
}
// 将获取的广告信息添加到选项卡1
await window.appendtab(todo, "tab1");
/*
window.getJSON(ApiUrlMainInfo, function(theLibrary, b) {
if (theLibrary !== null) {
alert("发生错误: " + theLibrary); // 如果请求有错误,显示警告
} else {
var todo = "";
try {
todo = todo + "\n";
// 检查返回的数据是否存在广告
if (b.data.length > 0) {
todo = todo + '# 名称 状态 ';
}
var i = 0;
// 设置选项卡标题为广告数量
document.getElementById("tabhead1").innerHTML = "广告(" + b.data.length + ")";
for (; i < b.data.length; i++) {
if (b.data[i].name) {
todo = todo + "";
// 获取广告投放状态
if (b.data[i].delivery_status.status) {
switch (b.data[i].delivery_status.status) {
case "active": delivstatus = '🟢 ACTIVE'; break; // 活动状态
case "inactive": delivstatus = '⏸ INACTIVE'; break; // 非活动状态
case "off": delivstatus = '⏸ INACTIVE'; break; // 关闭状态
case "error": delivstatus = '🟥Error'; break; // 错误状态
case "xz": delivstatus = "xz"; break;
default: delivstatus = " " + b.data[i].delivery_status.status; break; // 默认状态
}
}
// 获取广告图片
if (b.data[i].adcreatives.data[0].image_url) {
tblcreo = ' '; // 点击复制广告ID
} else {
tblcreo = "";
}
// 组装表格行
if (b.data[i].ad_review_feedback) {
todo = todo + ("" + tblcreo + " " + b.data[i].name + " [" + delivstatus + '] 申诉 ' + " ");
} else {
todo = todo + ("" + tblcreo + " " + b.data[i].name + " [" + delivstatus + "] " + " ");
}
// 处理广告审核反馈
if (b.data[i].ad_review_feedback) {
if (b.data[i].ad_review_feedback.global) {
todo = todo + ("");
var rjkey;
for (var k in b.data[i].ad_review_feedback.global) {
rjkey = k + "[ ? ]"; // 显示反馈信息
todo = todo + (rjkey);
}
todo = todo + (" ");
} else {
todo = todo + " ";
}
}
todo = todo + " ";
}
}
} catch (e) {
console.log("主广告错误"); // 捕获错误并输出
todo = todo + "没有广告"; // 如果出错,设置为无广告信息
}
todo = todo + "
"; // 结束表格
window.appendtab(todo, "tab1"); // 将表格添加到选项卡1
}
});
*/
// 使用 JSON 请求获取资金来源信息
window.getJSON(ApiUrlFinInfo, function(theLibrary, options) {
if (theLibrary !== null) {
console.log('卡片请求错误'); // 如果请求返回错误,输出错误信息
} else {
try {
// 检查资金来源详情是否存在
if (options.funding_source_details.display_string) {
// 在指定的区域中添加资金来源信息
window.appendtab('卡片: ' + options.funding_source_details.display_string + ' [添加 ] ', "dblock1cc");
}
} catch (e) {
console.log("卡片信息写入错误"); // 捕获错误并输出
}
}
});
// 触发主加载函数
window.mainload();
// 检查当前页面是否为 Facebook 的域名
if (location.host.indexOf("facebook.com") > -1) {
location.href = "/adsmanager/manage/campaigns"; // 重定向到广告管理器的活动页面
} else {
// 如果不是 Facebook 的域名,询问用户是否确认打开广告管理器
if (confirm('您确定要打开 Facebook 广告管理器吗?')) {
location.href = "https://www.facebook.com/adsmanager/manage/campaigns"; // 重定向到广告管理器
}
};
'>
FBAcc.io v6.4