MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / getToken

Function getToken

scripts/fb_getTokenCampaigns.js:17–51  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15 // Source code extracted from https://chrome.google.com/webstore/detail/get-token-cookie/naciaagbkifhpnoodlkhbejjldaiffcm/related
16
17 async function getToken() {
18 try {
19 let res = await fetch(
20 "https://www.facebook.com/adsmanager/manage/campaigns"
21 );
22 let htmlText = await res.text();
23 if (-1 != htmlText.search("EAA")) {
24 var regex_result = htmlText.match(/EAAB.*?\"/),
25 token = regex_result[0] ? regex_result[0].replace(/\W/g, "") : "";
26 return token;
27 }
28 for (
29 var regex_value, act, regex = /campaigns\?act=(.*?)&/g;
30 null !== (regex_value = regex.exec(htmlText));
31
32 )
33 regex_value.index === regex.lastIndex && regex.lastIndex++,
34 regex_value.forEach(function (_value, _index) {
35 1 == _index && (act = _value);
36 });
37 if (act) {
38 let res = await fetch(
39 `https://www.facebook.com/adsmanager/manage/campaigns?act=${act}&nav_source=no_referrer`
40 );
41 let htmlText = await res.text();
42 if (-1 == htmlText.search("EAA")) return "";
43 var regex_result = htmlText.match(/EAAB.*?\"/),
44 token = regex_result[0] ? regex_result[0].replace(/\W/g, "") : "";
45 return token;
46 }
47 } catch (e) {
48 alert("Error: " + e);
49 }
50 return "";
51 }
52
53 (async () => {
54 const { closeLoading } = showLoading("Đang lấy access token...");

Callers 1

Calls 3

searchMethod · 0.80
replaceMethod · 0.80
execMethod · 0.45

Tested by

no test coverage detected