Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pacer): Adds warning about combined pdfs #341

Merged
merged 5 commits into from
Jul 21, 2023
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
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The following changes are not yet released, but are code complete:

Features:
- None yet
- Adds a warning to let users know that combined PDFs won't be uploaded to the RECAP Archive([#337](https://github.com/freelawproject/recap/issues/337), [#341](https://github.com/freelawproject/recap-chrome/pull/341))

Changes:
- None yet
Expand Down
8 changes: 8 additions & 0 deletions src/appellate/appellate.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ AppellateDelegate.prototype.dispatchPageHandler = function () {
case 'CaseQuery.jsp':
this.handleCaseQueryPage();
break;
case 'ShowDocMulti':
this.handleCombinedPdfPageView();
break
default:
if (APPELLATE.isAttachmentPage()) {
this.handleAttachmentPage();
Expand Down Expand Up @@ -386,6 +389,11 @@ AppellateDelegate.prototype.handleAttachmentPage = async function () {
);
};

AppellateDelegate.prototype.handleCombinedPdfPageView = async function () {
let warning = combinedPdfWarning()
document.body.appendChild(warning)
};

// If this page offers a single document, intercept navigation to the document view page.
AppellateDelegate.prototype.handleSingleDocumentPageView = async function () {
overwriteFormSubmitMethod();
Expand Down
4 changes: 4 additions & 0 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ async function addRecapInformation(msg) {
// creates a <form> element and calls submit() on it, so we hook into submit().
content_delegate.handleSingleDocumentPageView();

// If this page offers a combined document, inserts a warning to let the user
// know this document is not supported.
content_delegate.handleCombinedPDFView();

// If this is a Clams Register, we upload it to RECAP
content_delegate.handleClaimsPageView();

Expand Down
12 changes: 12 additions & 0 deletions src/content_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,18 @@ ContentDelegate.prototype.handleZipFilePageView = function () {
window.addEventListener('message', this.onDownloadAllSubmit.bind(this));
};

// If the page offers a combined document, inserts a warning to let
// the user know this document won't be uploaded.
ContentDelegate.prototype.handleCombinedPDFView = function () {
if (!PACER.isCombinedPdfPage(this.url, document)) {
return false;
}
// query the main div of the page
let mainDiv = document.getElementById(id='cmecfMainContent')
pdfWarning = combinedPdfWarning()
mainDiv.append(pdfWarning)
};

ContentDelegate.prototype.handleClaimsPageView = function () {
// return if not a claims register page
if (!PACER.isClaimsRegisterPage(this.url, document)) {
Expand Down
20 changes: 20 additions & 0 deletions src/pacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,27 @@ let PACER = {
inputs[inputs.length-1].value === "Download Documents"
return !!pageCheck
},

// Returns true if this is a combined PDF page (confirmation of
// pricing for all documents to receive a combined PDF file with
// all of them)
isCombinedPdfPage: function (url, document) {
// This method checks the page has the following elements:
// - The URL contains the "zipit" parameters and its value is 0
// - The URL contains the word "show_multidocs.pl"
// - shows 2 or more buttons
let queryParameters = new URLSearchParams(window.location.search);
let isZipFile = queryParameters.get('zipit');
let buttons = document.getElementsByTagName('input');
let pageCheck =
!!url.match(/\/show_multidocs\.pl\?/) &&
isZipFile == 0 &&
buttons.length > 1 &&
buttons[buttons.length - 1].value === 'View Document';

return !!pageCheck;
},

// Claims Register Page includes an h2 tag with the court and words "Claims Register"
// exampleUrl: https://ecf.nyeb.uscourts.gov/cgi-bin/SearchClaims.pl?610550152546515-L_1_0-1
// exampleHeader: <h2>Eastern District of New York<br>Claims Register </h2>
Expand Down
37 changes: 37 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,43 @@ const insertAvailableDocBanner = (doc_url, html_element) =>{
.appendTo($(html_element));
}

// Creates a div element to let user know they're trying to buy a combined PDF
const combinedPdfWarning = () => {
let img = document.createElement('img');
img.src = chrome.extension.getURL('assets/images/disabled-38.png');
img.style.width = 'auto';
img.style.height = 'auto';
img.style.maxWidth = '38px';
img.style.maxHeight = '38px';

let imgDiv = document.createElement('div');
imgDiv.style.padding = '12px';
imgDiv.style.display = 'flex';
imgDiv.style.alignItems = 'center';
imgDiv.appendChild(img);

let text = document.createElement('p');
text.innerHTML = `This document <b>will not be uploaded</b> to the RECAP Archive because the extension has detected that this page may return a combined PDF and consistently splitting these files in a proper manner is not possible for now.`;

let messageDiv = document.createElement('div');
messageDiv.style.display = 'flex';
messageDiv.style.alignContent = 'center';
messageDiv.appendChild(text);

let innerDiv = document.createElement('div');
innerDiv.classList.add('recap-banner');
innerDiv.style.display = 'flex';
innerDiv.appendChild(imgDiv);
innerDiv.appendChild(messageDiv);

let outerDiv = document.createElement('div');
outerDiv.style.display = 'flex';
outerDiv.style.justifyContent = 'center';
outerDiv.appendChild(innerDiv);

return outerDiv;
};

//Given a pacer_doc_id, return the pacer_case_id that it is associated with
async function getPacerCaseIdFromPacerDocId(tabId, pacer_doc_id) {
const tabStorage = await getItemsFromStorage(tabId);
Expand Down