PageSourceSearch

https://www.societe.com/js/apx.cache.js?20261001181331

js societe.com collected 2026-10-02 02:29:38 UTC 6,996 bytes, 234 lines download raw bytes

1// -------- APP LOCAL STORAGE HANDLER --------
2const cache = {
3  _fetch: (url, settings) => {
4    if (settings.method) cache.updateCount++;
5    return fetch(url, settings);
6  },
7
8  _getKey: (k) => {
9    if (!sessionStorage.hasOwnProperty(k)) {
10      return false;
11    }
12    cache[k] = JSON.parse(sessionStorage.getItem(k));
13    return true;
14  },
15  _setKey: (obj) => {
16    if (!obj.data) {
17      return false;
18    }
19    sessionStorage.setItem(obj.name, JSON.stringify(obj.data));
20    cache[obj.name] = obj.data;
21    return true;
22  },
23  _delKey: (k) => {
24    if (!sessionStorage.hasOwnProperty(k)) {
25      return false;
26    }
27    sessionStorage.removeItem(k);
28    return true;
29  },
30  _updateCacheLastUpdate: (k, date) => {
31    if (date === undefined) {
32      date = new Date().getTime();
33    }
34    let key_cache = k + "_lastupdate";
35    cache._setKey({ name: key_cache, data: date });
36  },
37
38  _fetchUserList: async (refresh = false) => {
39    if (cache.userListPromise) await cache.userListPromise; // wait last fetch is done.
40    cache.userListPromise = (async () => {
41      if (cache.lastFetchUserList === cache.updateCount && cache._getKey("userFollowList")) {
42        return true;
43      }
44
45      let response, json;
46      try {
47        response = await fetch(`${origin_surveillance_api}/listes`, {
48          credentials: "include",
49          signal: AbortSignal.timeout(1000),
50        });
51        json = await response.json();
52      } catch (error) {
53        console.log(error);
54      }
55
56      cache._updateCacheLastUpdate("userFollowList");
57      cache._refreshUserList(json);
58      cache._fetchUserInfo();
59      if (refresh) window.location.reload();
60      cache.lastFetchUserList = cache.updateCount;
61      return true;
62    })(); // lance le fetch et renvoie la promise
63    return await cache.userListPromise;
64  },
65
66  _storeRemoveList: (id) => {
67    cache["removeList"] = sessionStorage.getItem("removeList");
68    cache["removeList"].push(id);
69
70    return true;
71  },
72
73  _getCardUsing: () => {
74    let using = { error: Error("Bad cache/storage state") };
75
76    let userFollowList = cache._getKey("userFollowList");
77    let userInfos = cache._getKey("userInfos");
78
79    if (userFollowList && userInfos) {
80      using = { abonnement: cache["userInfos"].abonnement };
81
82      if (cache["userInfos"].quota) {
83        using.quota = parseInt(cache["userInfos"].quota);
84        using.alertes = parseInt(cache["userInfos"].alertes);
85        using.suivis = parseInt(cache["userInfos"].suivis);
86      }
87
88      using.percent = parseInt((using.alertes / using.quota) * 100);
89      if (using.percent > 100) {
90        using.quota_exceeded = true;
91        //using.percent = 100;
92      }
93    } else {
94      console.warn(`_getCardUsing() failed: userFollowList:${userFollowList} userInfos:${userInfos}`);
95    }
96    return using;
97  },
98
99  _refreshUserList: (json) => {
100    if (json?.error) {
101      console.log(json.error);
102    }
103    cache._setKey({ name: "userFollowList", data: json?.error ? [] : json });
104  },
105
106  _fetchUserInfo: async () => {
107    if (cache.userInfoPromise) {
108      await cache.userInfoPromise; // wait last fetch is done.
109    }
110    cache.userInfoPromise = (async () => {
111      if (cache.lastFetchUserInfo === cache.updateCount && cache._getKey("userInfos")) {
112        return true;
113      }
114      let response, json;
115
116      try {
117        response = await fetch(`${origin_surveillance_api}/user/infos`, {
118          credentials: "include",
119          signal: AbortSignal.timeout(1000),
120        });
121        json = await response.json();
122      } catch (error) {
123        console.log(error);
124        return null;
125      }
126
127      cache._setKey({ name: "userInfos", data: json?.error ? null : json });
128      cache.lastFetchUserInfo = cache.updateCount;
129      return true;
130    })(); // lance le fetch et renvoie la promise
131    return await cache.userInfoPromise;
132  },
133
134  _checkCacheExpired: async (k) => {
135    let response = await fetch(`${origin_surveillance_api}/listes/lastupdate`, {
136      credentials: "include",
137    });
138
139    let json = await response.json();
140    let lastupdate = json.lastupdate ? new Date(json.lastupdate).getTime() : new Date().getTime();
141    let cache_expiration_time = new Date().getTime() - 60 * 30 * 1000;
142    let key_cache = "userFollowList_lastupdate";
143    let expire = cache._getKey(key_cache);
144    if (expire) {
145      if (cache[key_cache] < lastupdate || cache[key_cache] < cache_expiration_time) {
146        console.log("Cache expired for " + key_cache);
147        cache._updateCacheLastUpdate(k, lastupdate);
148        cache._delKey(k);
149        cache.updateCount++; // invalidate all page scope cache
150        await cache._fetchUserInfo();
151      }
152    } else {
153      cache._updateCacheLastUpdate(k, lastupdate);
154      cache._delKey(k);
155    }
156  },
157
158  _updateQuota: (quota, suivis, alertes, abonnement) => {
159    let exists = cache._getKey("userInfos");
160    if (exists) {
161      cache["userInfos"].suivis = parseInt(suivis);
162      cache["userInfos"].alertes = parseInt(alertes);
163      cache["userInfos"].quota = parseInt(quota);
164      cache["userInfos"].abonnement = abonnement;
165      // console.log("_updateQuota(...) / cache['userInfos']: " + JSON.stringify(cache['userInfos']))
166      cache._setKey({ name: "userInfos", data: cache["userInfos"] });
167      const components = document.querySelectorAll("so-follow-card-using");
168      for (component of components) component.quotaRefresh();
169    } else {
170      console.warn(`_updateQuota failed: exists: ${exists}`);
171    }
172  },
173
174  updateCount: 0,
175};
176
177async function initFollowStorage() {
178  let exists = cache._getKey("userInfos");
179  if (exists) {
180    await cache._checkCacheExpired("userFollowList");
181    let exists = cache._getKey("userFollowList");
182    if (!exists) {
183      await cache._fetchUserList();
184    }
185  }
186
187  window.dispatchEvent(new CustomEvent("initFollowStorageFinished"));
188}
189
190async function initUserInfos() {
191  let exists = cache._getKey("userInfos");
192  if (!exists) {
193    await cache._fetchUserInfo();
194  }
195}
196
197function clearUserInfos() {
198  let exists = cache._getKey("userInfos");
199  if (exists) {
200    cache._delKey("userFollowList");
201    cache._delKey("userInfos");
202  }
203}
204
205// -------- CLEAN FOLLOW SESSION KEYS
206(function () {
207  const userInfos = cache._getKey("userInfos"),
208    usrokl = cache._getKey("usrokl");
209
210  if (!usrokl && !userInfos) {
211    return;
212  }
213
214  _getCookieValue = (name) =>
215    decodeURIComponent(document.cookie)
216      .split("; ")
217      .find((row) => row.startsWith(name + "="))
218      ?.split("=")[1] || null;
219
220  const okl = _getCookieValue("okl") || _getCookieValue("dev-okl");
221  !!okl && !cache["usrokl"] && cache._setKey({ name: "usrokl", data: okl });
222
223  if (!okl) {
224    cache._delKey("usrokl");
225    return clearUserInfos();
226  }
227})();
228// -------- TMP CLEAN CMP KEYS
229(function () {
230  if (!!sessionStorage) {
231    localStorage.hasOwnProperty("didomi_token") && localStorage.removeItem("didomi_token");
232    localStorage.hasOwnProperty("euconsent-v2") && localStorage.removeItem("euconsent-v2");
233  }
234})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.