Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions public/LHD_Logo_Hookem.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
166 changes: 160 additions & 6 deletions src/entrypoints/episodeList.content/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,167 @@
import { defineContentScript } from '#imports';
import { browser, defineContentScript } from '#imports';
import { formatLectureTitle } from './utils';

const COLORS = {
burntorange: '#bf5700',
white: '#FFFFFF',
black: '#000000',
};

const NAV_LINKS = [
{ name: 'Discord', href: 'https://discord.gg/mybTUaf6jn', icon: 'ph-discord-logo' },
{ name: 'Instagram', href: 'https://www.instagram.com/longhorndevelopers/', icon: 'ph-instagram-logo' },
{ name: 'LinkedIn', href: 'https://www.linkedin.com/company/longhorn-developers/', icon: 'ph-linkedin-logo' },
{ name: 'Github', href: 'https://github.com/Longhorn-Developers/UT-Lectures-Plus', icon: 'ph-github-logo' },
{ name: 'Dark Mode', href: null, icon: 'ph-moon' },
{ name: 'Settings', href: null, icon: 'ph-gear' },
];

function injectStylesheets() {
const link = document.createElement('link');
link.rel = 'stylesheet';
link.href =
'https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..900&family=Space+Grotesk:wght@300..700&family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap';
document.head.appendChild(link);
const phosphor = document.createElement('link');
phosphor.rel = 'stylesheet';
phosphor.href = 'https://unpkg.com/@phosphor-icons/web@2.1.1/src/regular/style.css';
document.head.appendChild(phosphor);
}

function removeElements(...selectors: string[]) {
selectors.forEach(selector => document.querySelector<HTMLElement>(selector)?.remove());
}

function styleCourseBlock() {
const h2List = document.querySelectorAll<HTMLElement>('h2');
if (!h2List) return;
h2List.forEach(h2 => {
Object.assign(h2.style, {
fontSize: '32px',
fontWeight: '500',
fontFamily: "'Space Grotesk'",
color: COLORS.white,
background: COLORS.burntorange,
paddingTop: '15px',
paddingBottom: '15px',
paddingLeft: '20px',
borderRadius: '4px',
});
});
}

function styleHeader() {
const header = document.querySelector<HTMLElement>('h1');
if (!header) return;

header.innerHTML = `UT Lectures<span id="ut-plus">+</span>`;
Object.assign(header.style, {
fontFamily: "'Roboto Flex', sans-serif",
fontSize: '48px',
fontWeight: '700',
marginBottom: '0',
});

const plus = document.querySelector<HTMLElement>('#ut-plus');
if (plus) plus.style.color = COLORS.burntorange;
}

function buildHeaderRow() {
const headerRow = document.querySelector<HTMLElement>('.row');
if (!headerRow) return;

headerRow.style.display = 'flex';
headerRow.style.flexDirection = 'row';

const infoDiv = document.createElement('div');
Object.assign(infoDiv.style, {
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
marginTop: '28px',
paddingRight: '15px',
});

const lhd_phrase = document.createElement('div');
Object.assign(lhd_phrase.style, {
display: 'flex',
flexDirection: 'row',
});

const logo = document.createElement('img');
logo.src = browser.runtime.getURL('/LHD_Logo_Hookem.svg');

const phrase = document.createElement('div');
Object.assign(phrase.style, {
fontFamily: 'Inter',
fontWeight: '700',
fontSize: '16px',
lineHeight: '17px',
width: '224px',
paddingLeft: '8px',
});
phrase.textContent = 'MADE WITH LOVE, BY\nLONGHORN DEVELOPERS';
phrase.style.setProperty('color', COLORS.burntorange, 'important');

lhd_phrase.append(logo, phrase);
infoDiv.appendChild(lhd_phrase);

const nav = document.createElement('nav');
Object.assign(nav.style, {
display: 'flex',
flexDirection: 'row',
gap: '18px',
marginTop: '8px',
marginRight: '20px',
width: '224px',
});

NAV_LINKS.forEach(({ href, icon }) => {
const a = document.createElement('a');
if (href) {
a.href = href;
a.target = '_blank';
} else {
a.style.cursor = 'pointer';
}

const i = document.createElement('i');
i.className = `ph ${icon}`;
i.style.color = COLORS.black;
i.style.fontSize = '24px';

a.appendChild(i);
nav.appendChild(a);
});

infoDiv.appendChild(nav);
headerRow.appendChild(infoDiv);
}

function formatEpisodeTitles() {
document.querySelectorAll<HTMLElement>('.episode_title').forEach(title => {
title.textContent = formatLectureTitle(title.textContent);
});
}

export default defineContentScript({
matches: ['*://*.la.utexas.edu/player'],
async main() {
const episode_titles = document.querySelectorAll<HTMLElement>('.episode_title');
injectStylesheets();
removeElements('h2', 'p', '#lo_logo', 'hr');

episode_titles.forEach(title => {
const initialFormat = title.textContent;
title.textContent = formatLectureTitle(initialFormat);
});
const body = document.querySelector<HTMLElement>('body');
if (body) body.style.padding = '65px 65px 130px 65px';

styleHeader();
styleCourseBlock();
buildHeaderRow();

const faq_link = document.querySelector<HTMLElement>(
'a[href="https://sites.la.utexas.edu/lecturesonline/students/faq"]'
);
if (faq_link) faq_link.style.fontFamily = 'Roboto Flex';

formatEpisodeTitles();
},
});
33 changes: 17 additions & 16 deletions src/entrypoints/episodeList.content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
* Weekday, Month Day, Year Time
* If input string does not have a match, the title is kept the same.
*/
const formatLectureTitle = (title: string): string => {
const match = title?.match(/(?<time>\d+:\d+[ap]m)\s*\((?<month>\d+)\/(?<day>\d+)\/(?<year>\d+)\)/);
function formatLectureTitle(title: string): string | null {
const timeMatch = title.match(/\d+:\d+[ap]m/);
const dateMatch = title.match(/\((\d+)\/(\d+)\/(\d+)\)/);

if (match?.groups) {
const { time, month, day, year } = match.groups;
//time: "3:00pm", month: "01", day: "01", year: "2000"
const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
if (!timeMatch || !dateMatch) return null;

const formatted = date.toLocaleDateString('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
});
const time = timeMatch[0];
const [, month, day, year] = dateMatch;

return `${formatted} ${time}`;
}
const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day));

return title;
};
const parts = new Intl.DateTimeFormat('en-US', {
weekday: 'long',
year: 'numeric',
month: 'long',
day: 'numeric',
}).formatToParts(date);

const get = (type: string) => parts.find(p => p.type === type)?.value ?? '';
return `${get('weekday')} ${get('month')} ${get('day')}, ${get('year')} ${time}`;
}

export { formatLectureTitle };
6 changes: 6 additions & 0 deletions wxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ export default defineConfig({
id: 'ut-lectures-plus@ut.com',
},
},
web_accessible_resources: [
{
resources: ['LHD_Logo_Hookem.svg'],
matches: ['*://*.la.utexas.edu/*'],
},
],
},
});
Loading