Made it a little better
This commit is contained in:
parent
aa0f9a9252
commit
f3873bb48c
11
README.md
Normal file
11
README.md
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
# 4chads
|
||||||
|
|
||||||
|
4chads is a browser addon / user script that seeks to make the experience browsing 4chan better, even though that is a hard mission.
|
||||||
|
|
||||||
|
Features to come
|
||||||
|
|
||||||
|
- [] JSON Index/Catalog view, supporting new sorting metods etc.
|
||||||
|
- [] Image hovering
|
||||||
|
- [] Thread monitoring
|
||||||
|
- [] Coustom board titleing
|
||||||
|
- [] Filtering
|
||||||
@ -7,7 +7,6 @@
|
|||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin: 2px;
|
margin: 2px;
|
||||||
left: calc(67px - .3px * var(width));
|
|
||||||
}
|
}
|
||||||
.teaser p {
|
.teaser p {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
@ -19,3 +18,7 @@
|
|||||||
box-shadow: 0 0 5px rgba(0, 0, 0, .25);
|
box-shadow: 0 0 5px rgba(0, 0, 0, .25);
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.Top {
|
||||||
|
top: 0;
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import './Catalog.css';
|
import './Catalog.css';
|
||||||
|
// Api types from the 4chan api docs
|
||||||
interface Thread {
|
interface Thread {
|
||||||
no: number;
|
no: number;
|
||||||
replies: number;
|
replies: number;
|
||||||
@ -21,13 +22,13 @@ interface Page {
|
|||||||
interface CatalogProps {
|
interface CatalogProps {
|
||||||
boardID: string;
|
boardID: string;
|
||||||
}
|
}
|
||||||
|
// Fetches the catalog data from the 4chan api
|
||||||
const fetchCatalog = async (boardID: string): Promise<Page[]> => {
|
const fetchCatalog = async (boardID: string): Promise<Page[]> => {
|
||||||
const response = await fetch(`https://a.4cdn.org/${boardID}/catalog.json`);
|
const response = await fetch(`https://a.4cdn.org/${boardID}/catalog.json`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
// Creates the json index for the catalog.
|
||||||
const createThreadElement = (thread: Thread, boardID: string) => {
|
const createThreadElement = (thread: Thread, boardID: string) => {
|
||||||
const { no, replies, images, com, sub, tim, ext, tn_h, tn_w } = thread;
|
const { no, replies, images, com, sub, tim, ext, tn_h, tn_w } = thread;
|
||||||
const threadURL = `https://boards.4channel.org/${boardID}/thread/${no}`;
|
const threadURL = `https://boards.4channel.org/${boardID}/thread/${no}`;
|
||||||
@ -43,21 +44,24 @@ const createThreadElement = (thread: Thread, boardID: string) => {
|
|||||||
<b>I: {images} </b>
|
<b>I: {images} </b>
|
||||||
</div>
|
</div>
|
||||||
<div className="teaser">
|
<div className="teaser">
|
||||||
<b dangerouslySetInnerHTML={{ __html: sub }} />
|
<b dangerouslySetInnerHTML={{ __html: sub ? sub + ':' : ''}} />
|
||||||
|
{sub && sub.length > 0 ? <br /> : null}
|
||||||
<span dangerouslySetInnerHTML={{ __html: com }} />
|
<span dangerouslySetInnerHTML={{ __html: com }} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
// Renders the catalog
|
||||||
const Catalog: React.FC<CatalogProps> = ({ boardID }) => {
|
const Catalog: React.FC<CatalogProps> = ({ boardID }) => {
|
||||||
const [catalog, setCatalog] = useState<Page[]>([]);
|
const [catalog, setCatalog] = useState<Page[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async () => {
|
|
||||||
|
const fetchCatalogData = async () => {
|
||||||
const catalogData = await fetchCatalog(boardID);
|
const catalogData = await fetchCatalog(boardID);
|
||||||
setCatalog(catalogData);
|
setCatalog(catalogData);
|
||||||
})();
|
};
|
||||||
|
|
||||||
|
fetchCatalogData();
|
||||||
}, [boardID]);
|
}, [boardID]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
15
src/Site/Header.tsx
Normal file
15
src/Site/Header.tsx
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
interface TopBarProps {
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TopBar: React.FC<TopBarProps> = ({ text }) => {
|
||||||
|
return (
|
||||||
|
<div className='Top' style={{ height: '1px', backgroundColor: 'black' }}>
|
||||||
|
<p>{text}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TopBar;
|
||||||
37
src/main.tsx
37
src/main.tsx
@ -1,13 +1,32 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import ReactDOM from 'react-dom/client';
|
import ReactDOM from 'react-dom/client';
|
||||||
import Catalog from './Catalog';
|
|
||||||
import './index.css';
|
import './index.css';
|
||||||
|
import { render } from 'react-dom';
|
||||||
|
|
||||||
document.onchange = () => {
|
// Importing components
|
||||||
const target = document.querySelector('#threads');
|
import Catalog from './Site/Catalog';
|
||||||
let currentUrl = window.location.href;
|
import Header from './Site/Header';
|
||||||
let BoardID = currentUrl.split('/')[3];
|
|
||||||
if (target) {
|
const root = document.createElement('div');
|
||||||
ReactDOM.createRoot(target).render(<Catalog boardID={BoardID} />);
|
root.id = '4chuds';
|
||||||
}
|
document.body.appendChild(root);
|
||||||
};
|
|
||||||
|
let currentUrl = window.location.href;
|
||||||
|
let BoardID = currentUrl.split('/')[3];
|
||||||
|
|
||||||
|
//if (currentUrl == 'https://boards.4channel.org' || 'https://boards.4channel.org/') {
|
||||||
|
render(
|
||||||
|
<div>
|
||||||
|
<Header text='Hello, World!' />
|
||||||
|
<Catalog boardID={BoardID}/>
|
||||||
|
</div>,
|
||||||
|
document.querySelector('#threads')
|
||||||
|
);
|
||||||
|
//}
|
||||||
|
|
||||||
|
if (currentUrl === 'https://boards.4channel.org' || 'https://boards.4channel.org/') {
|
||||||
|
render(<Catalog boardID={BoardID} />, document.getElementById('id'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//render(<Header text='Hello, World!' />, document.createElement('div'));
|
||||||
Loading…
x
Reference in New Issue
Block a user