-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
1,587 additions
and
785 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<!doctype html> | ||
<script src="offscreen.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.