opiumisbest 1.0.1 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.svg +50 -27
  2. package/package.json +1 -1
  3. package/sw.js +29 -34
package/index.svg CHANGED
@@ -12,37 +12,60 @@
12
12
  <link rel="dns-prefetch" href="https://cdn.jsdelivr.net" />
13
13
 
14
14
  <script>
15
- (async () => {
16
- const reverseStr = (str) => str.split("").reverse().join("");
17
-
18
- const encodedMirrors = "=8SZnFmcvR3cvQXZiJXZoN1Zu9GVvg2ZvQXZu5ibkNWLi5ic2lGblR2cq9yL6MHc0RHas8SZnFmcvR3cvQXZiJXZoN1Zu9GVvg2ZvQXZu5ic2lGblR2cq5SesR3chZmbpdWay92LvozcwRHdoxyLldWYy9Gdz9CdlJmclh2Un52bU9Can9Cdl5mLyZXasVGZzpmLlJ3bjd2LvozcwRHdoxyLldWYy9Gdz9CdlJmclh2Un52bU9Can9Cdl5mLyZXasVGZzpmLmN2ZulGdzVGdv8iOzBHd0hGLvU2ZhJ3b0N3L0VmYyVGaTdmbvR1Lod2L0VmbuIndpxWZkNnaukHb0NXYm9yL6MHc0RHa";
19
- const mirrors = atob(reverseStr(encodedMirrors)).split(",");
20
-
21
- const hourlyCacheKey = Math.floor(Date.now() / 3600000);
22
- const controller = new AbortController();
15
+ !function() {
16
+ var reverse = function(str) {
17
+ return str.split('').reverse().join('');
18
+ };
23
19
 
24
- try {
25
- const { base, txt } = await Promise.any(
26
- mirrors.map(async (baseUrl) => {
27
- const res = await fetch(`${baseUrl}loader.js?${hourlyCacheKey}`, {
28
- cache: "no-store",
29
- signal: controller.signal
30
- });
31
- if (!res.ok) throw new Error("fetch failed");
32
- return { base: baseUrl, txt: await res.text() };
33
- })
34
- );
20
+ var allowedHosts = ['localhost', '127.0.0.1', 'ngrok-free'];
21
+ var isLocalOrAllowed = allowedHosts.includes(location.hostname) ||
22
+ allowedHosts.includes(location.hostname.split('.').at(-2) || location.hostname);
35
23
 
36
- controller.abort();
37
- window.assetsBase = base;
24
+ if (isLocalOrAllowed) {
25
+ var scriptEl = document.createElement('script');
26
+ scriptEl.src = '/stuff/loader.js';
27
+ scriptEl.onload = function() {
28
+ scriptEl.remove();
29
+ };
30
+ document.head.appendChild(scriptEl);
31
+ } else {
32
+ var encodedList = "=8SZnFmcvR3cvQXZiJXZoN1Zu9GVvg2ZvQXZu5ibkNWLi5ic2lGblR2cq9yL6MHc0RHas8SZnFmcvR3cvQXZiJXZoN1Zu9GVvg2ZvQXZu5ic2lGblR2cq5SesR3chZmbpdWay92LvozcwRHdoxyLldWYy9Gdz9CdlJmclh2Un52bU9Can9Cdl5mLyZXasVGZzpmLlJ3bjd2LvozcwRHdoxyLldWYy9Gdz9CdlJmclh2Un52bU9Can9Cdl5mLyZXasVGZzpmLmN2ZulGdzVGdv8iOzBHd0hGLvU2ZhJ3b0N3L0VmYyVGaTdmbvR1Lod2L0VmbuIndpxWZkNnaukHb0NXYm9yL6MHc0RHas8SZnFmcvR3cvQXZiJXZoN1Zu9GVvg2ZvQXZu5ic2lGblR2cq5CbpRnbhVXcv8iOzBHd0hGLvU2ZhJ3b0N3L0VmYyVGaTdmbvR1Lod2L0VmbuIndpxWZkNnau4GZj9yL6MHc0RHa";
33
+ var baseUrls = atob(reverse(encodedList)).split(',');
34
+ var currentHour = Math.floor(Date.now() / 3600000);
35
+ var abortController = new AbortController();
36
+ var scriptLoaded = false;
38
37
 
39
- const script = document.createElement("script");
40
- script.textContent = txt;
41
- document.head.appendChild(script);
42
- } catch {
43
- alert("failed to fetch opium assets, contact us on Discord for more assistance");
38
+ Promise.any(
39
+ baseUrls.map(function(base) {
40
+ return fetch(base + 'loader.js' + '?' + currentHour, {
41
+ cache: 'no-store',
42
+ signal: abortController.signal
43
+ })
44
+ .then(function(response) {
45
+ if (!response.ok) {
46
+ throw new Error('bad status');
47
+ }
48
+ return response.text().then(function(text) {
49
+ return { base: base, txt: text };
50
+ });
51
+ });
52
+ })
53
+ )
54
+ .then(function(result) {
55
+ scriptLoaded = true;
56
+ abortController.abort();
57
+ window.assetsBase = result.base;
58
+ var scriptEl = document.createElement('script');
59
+ scriptEl.textContent = result.txt;
60
+ document.head.appendChild(scriptEl);
61
+ })
62
+ .catch(function() {
63
+ if (!scriptLoaded) {
64
+ alert(atob(reverse("=U2YuFGdzl2czFGIlJ3btBicvZGIkJ3bjNXaEBibvByc1BCdjFGdu92Ygwyc0V2czFGItVXaw9GIoNGdlZGIvRHIkVGbpFmZ")));
65
+ }
66
+ });
44
67
  }
45
- })();
68
+ }();
46
69
  </script>
47
70
  </head>
48
71
  <body style="background:#000">
package/package.json CHANGED
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "opiumisbest",
3
- "version": "1.0.1"
3
+ "version": "1.1.1"
4
4
  }
package/sw.js CHANGED
@@ -1,42 +1,37 @@
1
- const host = location.hostname;
2
- const isDev = ["localhost", "127.0.0.1"].includes(host) || host.endsWith("ngrok-free");
1
+ const devHosts = ["localhost", "127.0.0.1", "ngrok-free"];
2
+ const devMode = devHosts.includes(location.hostname) || devHosts.includes(location.hostname.split(".").at(-2) || location.hostname);
3
3
 
4
- const cdns = [
5
- "https://cdn.jsdelivr.net/gh/TongSherbet/storage/",
6
- "https://quantil.jsdelivr.net/gh/TongSherbet/storage/",
7
- "https://fastly.jsdelivr.net/gh/TongSherbet/storage/",
8
- "https://testingcf.jsdelivr.net/gh/TongSherbet/storage/",
9
- "https://gcore.jsdelivr.net/gh/TongSherbet/storage/",
10
- "https://originfastly.jsdelivr.net/gh/TongSherbet/storage/",
11
- "https://jsdelivr.b-cdn.net/gh/TongSherbet/storage/"
4
+ const cdnList = [
5
+ "https://cdn.jsdelivr.net/gh/TongSherbet/storage/",
6
+ "https://quantil.jsdelivr.net/gh/TongSherbet/storage/",
7
+ "https://fastly.jsdelivr.net/gh/TongSherbet/storage/",
8
+ "https://testingcf.jsdelivr.net/gh/TongSherbet/storage/",
9
+ "https://gcore.jsdelivr.net/gh/TongSherbet/storage/",
10
+ "https://originfastly.jsdelivr.net/gh/TongSherbet/storage/",
11
+ "https://jsdelivr.b-cdn.net/gh/TongSherbet/storage/"
12
12
  ];
13
13
 
14
- let activeCdn = null;
14
+ let assetsBase = null;
15
15
 
16
- function getScriptUrl(path) {
17
- if (isDev) {
18
- return `${location.protocol}//${location.hostname}:${location.port}/stuff/${path}`;
19
- }
20
- return (activeCdn || cdns[0]) + path;
16
+ function getAsset(path) {
17
+ if (devMode) return `${location.protocol}//${location.hostname}:${location.port}/stuff/${path}`;
18
+ return (assetsBase || cdnList[0]) + path;
21
19
  }
22
20
 
23
- if (isDev) {
24
- importScripts(getScriptUrl("sw.js"));
21
+ if (devMode) {
22
+ importScripts(getAsset("sw.js"));
25
23
  } else {
26
- let lastError;
27
- for (const cdn of cdns) {
28
- try {
29
- activeCdn = cdn;
30
- importScripts(`${cdn}sw.js`);
31
- lastError = null;
32
- break;
33
- } catch (err) {
34
- lastError = err;
35
- activeCdn = null;
24
+ let lastErr;
25
+ for (const base of cdnList) {
26
+ assetsBase = base;
27
+ try {
28
+ importScripts(base + "sw.js");
29
+ lastErr = null;
30
+ break;
31
+ } catch (e) {
32
+ lastErr = e;
33
+ assetsBase = null;
34
+ }
36
35
  }
37
- }
38
-
39
- if (lastError) {
40
- throw lastError;
41
- }
42
- }
36
+ if (lastErr) throw lastErr;
37
+ }