-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtime.js
More file actions
54 lines (54 loc) · 1.57 KB
/
Copy pathtime.js
File metadata and controls
54 lines (54 loc) · 1.57 KB
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
const cookiedata = {};
document.cookie.split("; ").forEach(elem => {
const arr = elem.split("=");
cookiedata[arr[0]] = decodeURIComponent(arr[1]);
});
console.log(cookiedata);
/**
* @param {Date} date
* @param {string} text
*/
function format(date, text) {
const replaceData = {
"ALL": "toLocaleString",
"YE": "getFullYear",
"MO": date.getMonth() + 1,
"DA": "getDate",
"HO": "getHours",
"MI": "getMinutes",
"SE": "getSeconds",
"MS": "getMilliseconds",
"UALL": "toString",
"UYE": "getUTCFullYear",
"UMO": date.getUTCMonth() + 1,
"UDA": "getUTCDate",
"UHO": "getUTCHours",
"UMI": "getUTCMinutes",
"USE": "getUTCSeconds",
"UMS": "getUTCMilliseconds",
"%": "%",
};
Object.keys(replaceData).forEach(target => {
const value = replaceData[target];
target = "%" + target;
if (typeof value === "string") {
text = text.replaceAll(target, date[value]());
} else {
text = text.replaceAll(target, value(date));
}
});
return text;
}
chrome.storage.local.get(async function (value) {
const terget = value.terget;
const date = new Date();
const data = format(date, value.data);
fetch(`https://scratch.mit.edu/site-api/users/all/${(await (await fetch("https://scratch.mit.edu/session/", { "headers": { "x-requested-with": "XMLHttpRequest" } })).json()).user.username}/`, {//意見もらったんで少し改造
"headers": {
"x-csrftoken": cookiedata.scratchcsrftoken,
"x-requested-with": "XMLHttpRequest"
},
"body": `{"${terget}":"${data}"}`,
"method": "PUT",
});
});