Skip to content

Commit

Permalink
feat: migrate to Manifest V3
Browse files Browse the repository at this point in the history
  • Loading branch information
m4tx committed Oct 24, 2024
1 parent 45a8dbb commit 8664448
Show file tree
Hide file tree
Showing 7 changed files with 1,587 additions and 785 deletions.
6 changes: 3 additions & 3 deletions ext/js/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

browser.runtime.sendMessage({ action: 'enablePageAction' });

const BANNER_URL = browser.extension.getURL('images/satori_banner.png');
const TCS_LOGO_URL = browser.extension.getURL('images/tcslogo.svg');
const ALT_TCS_LOGO_URL = browser.extension.getURL('images/alttcslogo.png');
const BANNER_URL = browser.runtime.getURL('images/satori_banner.png');
const TCS_LOGO_URL = browser.runtime.getURL('images/tcslogo.svg');
const ALT_TCS_LOGO_URL = browser.runtime.getURL('images/alttcslogo.png');

let storage = browser.storage.sync || browser.storage.local;

Expand Down
2 changes: 2 additions & 0 deletions ext/js/offscreen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!doctype html>
<script src="offscreen.js"></script>
48 changes: 48 additions & 0 deletions ext/js/offscreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
importScripts(
"../vendor/browser-polyfill.js",
"config.js",
"../vendor/bower/jquery.min.js"
);

browser.runtime.onMessage.addListener(handleMessages);

async function handleMessages(message) {
if (message.target !== 'offscreen') {
return false;
}

if (message.type === 'parseProblemList') {
parseProblemList(message.data);
} else {
console.warn(`Unexpected message type received: '${message.type}'.`);
return false;
}
}

function parseProblemList(htmlText) {
const jqueryHandles = $.parseHTML(htmlText);

return Object.fromEntries(
jqueryHandles.flatMap((el) =>
[
...$(el).find('#content table.results tr:not(:first-of-type)'),
].map((tr) => [
$(tr).find('td:nth-child(1)').text(),
{
title: $(tr).find('td:nth-child(2)').text(),
href: $(tr).find('td:nth-child(2) a').attr('href'),
pdfHref: $(tr).find('td:nth-child(3) a').attr('href'),
submitHref: $(tr).find('td:nth-child(5) a').attr('href'),
},
]),
),
);
}

function sendToBackground(type, data) {
browser.runtime.sendMessage({
type,
target: 'background',
data
});
}
3 changes: 3 additions & 0 deletions ext/js/results.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
let problemStatus = tr.find('td:last').text();

let url = document.location.href;
console.log("XD");
const contestID = getContestID(url);
console.log("XD2");


/**
* Get submit extension if possible
Expand Down
Loading

0 comments on commit 8664448

Please sign in to comment.