Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (50 loc) · 1.69 KB
/
Copy pathscript.js
File metadata and controls
51 lines (50 loc) · 1.69 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
import info from "./info.json" with {type: "json"};
const a = document.querySelector(".btn-t");
const b = document.querySelector(".btn-g");
const c = document.querySelector(".btn-p");
const d = document.querySelector(".stuts");
//d.textContent = JSON.stringify(info) ;
function uniqid(length) {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
for (let i = 0; i < length; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
a.onclick = function (){
const url = 'https://twitter.com/i/oauth2/authorize';
const param = new URLSearchParams({
'response_type': 'code',
'client_id': 'client_id',
'redirect_uri': 'https://ashopra.github.io/3bd-alla/',
'scope': 'tweet.read users.read offline.access',
'state': uniqid(16),
'code_challenge': uniqid(64),
'code_challenge_method': 'plain'
});
location.href = url + '?' + param;
};
//https://3bda11a.000webhostapp.com/api/
b.onclick = function (){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://3bda11a.000webhostapp.com/api/twitter.php/me', true);
xhr.onreadystatechange = function () {
try {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
var data = JSON.stringify(xhr.responseText);
d.textContent = xhr.responseText;
// Do something with the data
}/* else {
throw new Error('XMLHttpRequest failed with status ' + xhr.status);
}*/
}
} catch (error) {
d.textContent = error;
}
};
xhr.send();
//d.textContent = 'GET';
};
c.onclick = function (){d.textContent = 'POST';};