Skip to content

Commit 700751a

Browse files
committed
Better feature API
1 parent 9d25060 commit 700751a

5 files changed

Lines changed: 24 additions & 13 deletions

File tree

api/blocklive-detection/blocklive-detect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default async function () {
2+
if (document.querySelector(".ste-bl-together-bg")) return;
23
let alertedBefore = await ScratchTools.storage.get("steBlAlert");
34
await ScratchTools.storage.set({ key: "steBlAlert", value: false });
45
await ScratchTools.waitForElement("script.blocklive-ext");

api/feature.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,6 @@ class Feature {
7777
}
7878
}
7979
}
80-
this.getSettings = function (key) {
81-
var settings = {};
82-
this.data.options?.forEach(function (el) {
83-
if (ScratchTools.Storage[el.id]) {
84-
settings[el.id] = ScratchTools.Storage[el.id];
85-
}
86-
});
87-
if (key) {
88-
return settings[key];
89-
} else {
90-
return settings;
91-
}
92-
};
9380
this.tab = {
9481
path: window.location.pathname,
9582
scratch: document.querySelector("#app") ? 3 : 2,

api/feature/auth.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export default function () {
2+
let auth = {
3+
fetch: async function () {
4+
let data = await (
5+
await fetch("https://scratch.mit.edu/session/", {
6+
headers: {
7+
"x-requested-with": "XMLHttpRequest",
8+
},
9+
})
10+
).json();
11+
return data;
12+
},
13+
csrf: function() {
14+
return ScratchTools.cookies.get("scratchcsrftoken")
15+
},
16+
cookies: ScratchTools.cookies,
17+
};
18+
return auth
19+
}

api/feature/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { default as self } from "./self.js";
22
import { default as traps } from "./traps.js";
3+
import { default as auth } from "./auth.js";
34

45
export default function (data) {
56
var feature = new Feature(data);
67
feature.self = self(data.id);
78
feature.traps = traps()
9+
feature.auth = auth()
810
return feature;
911
}

api/feature/self.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export default function (id) {
44
id,
55
data: feature,
66
enabled: true,
7+
waitForElement: ScratchTools.waitForElement,
8+
waitForElements: ScratchTools.waitForElements,
79
hideOnDisable: function(element) {
810
ScratchTools.managedElements.push({
911
element,

0 commit comments

Comments
 (0)