Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit a83480f

Browse files
committed
Initial commit
0 parents  commit a83480f

File tree

9 files changed

+227
-0
lines changed

9 files changed

+227
-0
lines changed

apiList.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"userId": "User ID",
3+
"id": "Channel ID",
4+
"token": "Username",
5+
"suspended": "Suspended",
6+
"vodsEnabled": "VODs Enabled",
7+
"createdAt": "Created at",
8+
"isLSEnabled": "Lightstream",
9+
"xuid": "XUID",
10+
"email": "Email"
11+
}

content.js

Whitespace-only changes.

img/icon.png

1.43 KB
Loading

lib/jquery-3.4.1.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/mustache.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifest.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name" : "catToys",
3+
"version": "0.1",
4+
"manifest_version": 2,
5+
"content_scripts": [
6+
{
7+
"matches": ["<all_urls>"],
8+
"js": ["content.js"]
9+
}
10+
],
11+
"browser_action": {
12+
"default_icon": "img/icon.png",
13+
"default_popup": "popup.html",
14+
"default_title": "catToys"
15+
}
16+
}

popup.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
7+
<link rel="stylesheet" href="styles.css">
8+
<script src="lib/jquery-3.4.1.min.js"></script>
9+
<script src="lib/mustache.min.js"></script>
10+
<title>catToys</title>
11+
</head>
12+
<body>
13+
<h1 id="app-name">catToys<a id="app-version"></a></h1>
14+
<div class="flex-container feature-container">
15+
<div>
16+
<div class="flex-container"><p class="feature-name">API Runner</p></div>
17+
<div class="flex-container" id="search-box">
18+
<input type="text" autofocus="True" id="api-search-box" placeholder="Username or CID">
19+
</div>
20+
</div>
21+
<div>
22+
<script type="text/template" id="table-template">
23+
<tr>
24+
<td>{{name}}</td>
25+
<td class="td-right">{{status}}</td>
26+
</tr>
27+
</script>
28+
<table id="generated">
29+
</table>
30+
</div>
31+
</div>
32+
<script src="popup.js"></script>
33+
</body>
34+
</html>

popup.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
//Version
2+
var scriptVersion = 'alpha-v0.1';
3+
document.getElementById('app-version').innerHTML = scriptVersion;
4+
//API
5+
var apiUrl = 'https://mixer.com/api/v1/channels/';
6+
7+
function buildUrl(name) {
8+
console.log('Building URL')
9+
var url = apiUrl + name;
10+
return url
11+
}
12+
13+
function Get(url) {
14+
console.log('Creating API dump for ' + url)
15+
//Return response as String
16+
var Httpreq = new XMLHttpRequest();
17+
Httpreq.open("GET", url, false);
18+
Httpreq.send(null);
19+
var response = Httpreq.responseText
20+
var statusCode = JSON.parse(response)['statusCode']
21+
console.log('Status Code ' + statusCode)
22+
if (statusCode == 404) {
23+
alert("User not found, API returned 404");
24+
}
25+
else {
26+
return response.toString();
27+
}
28+
}
29+
30+
function parseLightstream(channelId) {
31+
console.log('Parsing Lighstream')
32+
videoUrl = apiUrl + channelId.toString() + '/videoSettings';
33+
var rawData = JSON.parse(Get(videoUrl));
34+
var lightstream = rawData['isLSEnabled'];
35+
console.log(lightstream, rawData);
36+
return lightstream;
37+
}
38+
39+
function parseApi(keys, rawData) {
40+
console.log('Parsing API dump')
41+
var allKeys = JSON.parse(Get(keys + '.json'));
42+
var apiName;
43+
for (apiName in allKeys) {
44+
//Parse String as JSON
45+
var status = rawData[apiName];
46+
var humanApiName = allKeys[apiName];
47+
//Formatting date
48+
if (apiName == 'createdAt') {
49+
status = status.substr(0,10);
50+
}
51+
if (apiName == 'isLSEnabled') {
52+
status = parseLightstream(rawData['id']);
53+
}
54+
buildTable(humanApiName, status);
55+
}
56+
}
57+
58+
function buildTable(name, status) {
59+
var template = $("#table-template").html();
60+
var tableRow = Mustache.render(template, {name: name, status: status});
61+
$("table").append(tableRow);
62+
}
63+
64+
function resetHtml(htmlTag) {
65+
document.getElementById(htmlTag).innerHTML = '';
66+
console.log('Clearing old HTML');
67+
}
68+
69+
function apiRunner() {
70+
var input = document.getElementById("api-search-box").value;
71+
if (input.length <= 2) {
72+
alert("Enter username or CID");
73+
}
74+
else {
75+
resetHtml('generated');
76+
var url = buildUrl(input);
77+
var rawData = JSON.parse(Get(url));
78+
var keys = 'apiList'
79+
parseApi(keys, rawData);
80+
}
81+
}
82+
83+
// Get the input field
84+
var input = document.getElementById("api-search-box");
85+
// Execute a function when the user releases a key on the keyboard
86+
input.addEventListener("keyup", function(event) {
87+
// Number 13 is the "Enter" key on the keyboard
88+
if (event.keyCode === 13) {
89+
// Cancel the default action, if needed
90+
event.preventDefault();
91+
// Trigger the button element with a click
92+
apiRunner();
93+
}
94+
});

styles.css

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
@import url('https://fonts.googleapis.com/css?family=Poppins&display=swap');
2+
3+
/*
4+
General
5+
*/
6+
body {
7+
width: 225px;
8+
height: 325px;
9+
font-family: 'Poppins', sans-serif;
10+
}
11+
div {
12+
padding: 5px;
13+
}
14+
.flex-container {
15+
display: flex;
16+
flex-direction: column;
17+
}
18+
19+
/*
20+
Header
21+
*/
22+
#app-version {
23+
display: flex;
24+
justify-content: center;
25+
align-items: center;
26+
background-color: #858585;
27+
color: white;
28+
font-size: 0.65rem;
29+
padding: 0px 7px;
30+
margin: 0px 0px;
31+
border-radius: 5px;
32+
}
33+
#app-name {
34+
display: flex;
35+
justify-content: center;
36+
align-items: center;
37+
font-size: 2.5em;
38+
margin: auto;
39+
}
40+
#search-box {
41+
margin: auto;
42+
width: 80%;
43+
margin: auto;
44+
text-align: center;
45+
}
46+
47+
/*
48+
Feature
49+
*/
50+
.feature-name {
51+
margin: auto;
52+
display: flex;
53+
justify-content: center;
54+
align-items: center;
55+
}
56+
.feature-container {
57+
margin: auto;
58+
}
59+
60+
/*
61+
ApiRunner
62+
*/
63+
.td_right {
64+
text-align: center;
65+
min-height: 40px;
66+
}
67+
button {
68+
text-align: center;
69+
}

0 commit comments

Comments
 (0)