-
Notifications
You must be signed in to change notification settings - Fork 19
/
index.js
67 lines (64 loc) · 2.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
javascript: (function () {
// Author: Ross Jacobs
// Purpose: Use as a browser bookmarklet to bulk delete notion pages in trash
// License: Apache 2.0
async function getSpaceId() {
resp = await fetch("https://www.notion.so/api/v3/loadUserContent", {
credentials: "include",
headers: {
accept: "*/*",
"cache-control": "no-cache",
"content-type": "application/json",
pragma: "no-cache",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
},
referrerPolicy: "same-origin",
body: "{}",
method: "POST",
mode: "cors",
});
json = await resp.json();
spaceId = Object.keys(json.recordMap.space)[0];
return spaceId;
};
async function getBlockIds(spaceId) {
let resp = await fetch("https://www.notion.so/api/v3/search", {
headers: {
accept: "*/*",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"content-type": "application/json",
},
body: `{\"type\":\"BlocksInSpace\",\"spaceId\":\"${spaceId}\",\"limit\":1000,\"filters\":{\"isDeletedOnly\":true,\"excludeTemplates\":false,\"navigableBlockContentOnly\":false,\"requireEditPermissions\":false,\"includePublicPagesWithoutExplicitAccess\":false,\"ancestors\":[],\"createdBy\":[],\"editedBy\":[],\"lastEditedTime\":{},\"createdTime\":{},\"inTeams\":[]},\"sort\":{\"field\":\"relevance\"},\"source\":\"quick_find_input_change\",\"searchExperimentOverrides\":{}}`,
method: "POST",
mode: "cors",
credentials: "include",
});
json = await resp.json();
blockIds = json.results.map((el) => {
return el.id;
});
return blockIds;
}
(async () => {
const spaceId = await getSpaceId();
blockIds = await getBlockIds(spaceId);
for (const blockId of blockIds) {
await fetch("https://www.notion.so/api/v3/deleteBlocks", {
"headers": {
"accept": "*/*",
"accept-language": "en-US,en;q=0.9",
"cache-control": "no-cache",
"content-type": "application/json",
},
"referrer": "https://www.notion.so/qwerk/Lorem-Ipsum-d883cc4e6ea64bd4bcdb85c43cf74946",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": `{\"blocks\":[{\"id\":\"${blockId}\",\"spaceId\":\"${spaceId}\"}],\"permanentlyDelete\":true}`,
"method": "POST",
"mode": "cors",
"credentials": "include"
});
}
})();
})();