Made it a little better

This commit is contained in:
Lalle 2023-03-21 00:07:33 +01:00
parent aa0f9a9252
commit f3873bb48c
No known key found for this signature in database
GPG Key ID: A6583D207A8F6B0D
5 changed files with 70 additions and 18 deletions

11
README.md Normal file
View 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

View File

@ -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;
}

View File

@ -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
View 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;

View File

@ -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'));