Skip to content

Commit

Permalink
Merge pull request #274 from freelawproject/35-advertise-recap-email
Browse files Browse the repository at this point in the history
feat(recap email): Add advertisement banners for RECAP Email
  • Loading branch information
mlissner authored Nov 19, 2022
2 parents 2ea2547 + e6edfc7 commit 9853c4e
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 7 deletions.
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
- Add banners to advertise RECAP Email ([#309](https://github.com/freelawproject/recap/issues/309))

Changes:
- None
Expand Down
18 changes: 16 additions & 2 deletions src/assets/css/style-ios.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,18 @@ footer #version {
color: #aaa;
}

.recap-email-banner-full{
font-family: helvetica, arial, serif;
font-size: 13px;
background: #fff;
padding: 6px;
margin: 1em 0em;
border: 1px solid #aaa;
}

.recap-banner,
.recap-popup {
.recap-popup,
.recap-email-banner {
font-family: helvetica, arial, serif;
font-size: 13px;
background: #fff;
Expand All @@ -179,11 +189,15 @@ footer #version {
.recap-banner {
max-width: 450px;
}
.recap-email-banner{
max-width: 525px;
}
.recap-inline {
padding: 0 0 0 4px;
}
.recap-banner img,
.recap-inline img {
.recap-inline img,
.recap-email-banner img{
margin: 0 0 -2px 0;
width: 16px;
height: 16px;
Expand Down
24 changes: 22 additions & 2 deletions src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,23 @@ footer #version {
color: #aaa;
}

.recap-email-banner-full{
font-family: helvetica, arial, serif;
font-size: 13px;
background: #fff;
padding: 6px;
margin: 1em 0em;
border: 1px solid #aaa;
}

.recap-email-banner-full a{
font-family: helvetica, arial, serif;
font-size: 13px;
}

.recap-banner,
.recap-popup {
.recap-popup,
.recap-email-banner {
font-family: helvetica, arial, serif;
font-size: 13px;
background: #fff;
Expand All @@ -167,11 +182,16 @@ footer #version {
.recap-banner {
max-width: 450px;
}
.recap-email-banner{
max-width: 525px;
}
.recap-inline {
padding: 0 0 0 4px;
}
.recap-banner img,
.recap-inline img {
.recap-inline img,
.recap-email-banner img,
.recap-email-banner-full img{
margin: 0 0 -2px 0;
width: 16px;
height: 16px;
Expand Down
27 changes: 26 additions & 1 deletion src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ let pacer_doc_id = PACER.getDocumentIdFromForm(url, document) ||
PACER.getDocumentIdFromUrl(url);
let links = document.body.getElementsByTagName('a');

function handleRedactionConfirmation(mutationRecords, msg){
getTabIdForContentScript().then(msg => {
setFilingState(msg)
});
}

// seed the content_delegate with the tabId by using the message
// returned from the background worker
function addRecapInformation(msg){
Expand All @@ -21,8 +27,11 @@ function addRecapInformation(msg){

let content_delegate = new ContentDelegate(tabId,
url, path, court, pacer_case_id, pacer_doc_id, links);

if (PACER.hasPacerCookie(document.cookie)) {
// If this is a docket query page, add RECAP Email advertisement banner.
content_delegate.addRecapEmailAdvertisement();

// If this is a docket query page, ask RECAP whether it has the docket page.
content_delegate.handleDocketQueryUrl();

Expand Down Expand Up @@ -53,6 +62,22 @@ function addRecapInformation(msg){
content_delegate.attachRecapLinkToEligibleDocs();
} else {
console.info(`RECAP: Taking no actions because not logged in: ${url}`);
let redactionConfirmation = document.getElementById('redactionConfirmation');

let emailInput = document.getElementById('loginForm:loginName')
let passwordInput = document.getElementById('loginForm:password')

if (emailInput && passwordInput && redactionConfirmation){
removeFilingState(msg)
}

if (redactionConfirmation){
let redactionObserver = new MutationObserver(mutationRecords => handleRedactionConfirmation(mutationRecords));
redactionObserver.observe(redactionConfirmation, {
attributes: true,
attributeOldValue: true,
});
}
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/content_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,27 @@ ContentDelegate.prototype.findAndStorePacerDocIds = function () {
});
};

// If this is a docket query page, add RECAP email advertisement.
ContentDelegate.prototype.addRecapEmailAdvertisement = async function () {
if (!(PACER.isBlankQueryReportUrl(this.url) || PACER.isManageAccountPage(this.url))) { return; };
let form;

if (!PACER.hasFilingCookie(document.cookie)){ return; };

if (PACER.isBlankQueryReportUrl(this.url)){
form = document.querySelector('form');
if (!document.querySelector('.recap-email-banner')){
form.appendChild(recapEmailBanner());
}
}else{
form = document.querySelector('#popupForm');
if(!document.querySelector('.recap-email-banner-full')){
form.after(recapEmailBanner('recap-email-banner-full'));
}
}

};

// If this is a docket query page, ask RECAP whether it has the docket page.
ContentDelegate.prototype.handleDocketQueryUrl = function () {
if (!PACER.isDocketQueryUrl(this.url)) { return; };
Expand Down
38 changes: 37 additions & 1 deletion src/pacer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,31 @@ let PACER = {
return !!url.match(/\/(DktRpt|HistDocQry)\.pl\?\d+$/);
},

// Returns true if the URL is for the manage account page.
isManageAccountPage: function(url){
// matches URLs related to the manage Manage My Account page in PACER. The url is:
// https://pacer.psc.uscourts.gov/pscof/manage/maint.jsf
return /pacer./.test(url) && /manage/.test(url)
},

// Returns true if the URL is for the iQuery page.
isBlankQueryReportUrl: function(url){
// The URL for the query form used in CM/ECF to seach cases is:
//
// https://ecf.mied.uscourts.gov/cgi-bin/iquery.pl
//
// and the URL for list of posibles reports related to a case that is found with
// the query form is:
//
// https://ecf.mied.uscourts.gov/cgi-bin/iquery.pl?900473201618068-L_1_0-1
//
// This function checks if the URL has a query string and is related to the iQuery form.
// It will return true only when the url match the format of the first example and it will
// exclude pages that include the iquery word but has a query string like the last example.

return /iquery.pl/.test(url) && !/[?&]/.test(url)
},

// Returns the URL with the case id as a query parameter. This function makes
// sure every URL related to the Docket report has the same format
formatDocketQueryUrl: function(url, case_id){
Expand All @@ -105,8 +130,9 @@ let PACER = {
// the same URL but, for those URL like the last example, it will append the query string
// separator and the case id to make sure every URL has the format expected by the
// ContentDelegate class
if (!/DktRpt.pl/.test(url)){ return url }

return /[?&]/.test(url) && /DktRpt.pl/.test(url)? url : `${url}?${case_id}`
return /[?&]/.test(url) ? url : `${url}?${case_id}`
},


Expand Down Expand Up @@ -197,6 +223,8 @@ let PACER = {
let bigFile = document.getElementById('file_too_big')
let buttonText = inputs.length ? inputs[inputs.length - 1].value.includes('Download') : false
let mainContent = document.getElementById("cmecfMainContent");
// End this function early if we're on a management PACER page
if (!mainContent){ return false }
let bottomNote = mainContent.lastChild.textContent.includes('view each document individually')
let pageCheck = PACER.isDocumentUrl(url) && (
!!buttonText || !!bigFile || !!bottomNote);
Expand Down Expand Up @@ -400,6 +428,14 @@ let PACER = {
return !!(pacerCookie && !pacerCookie.match(/unvalidated/));
},

// Given document.cookie, returns true if the user has filing rights.
hasFilingCookie: function (cookieString){
let filingCookie = cookieString.split('; ')
.find((row) => row.startsWith('isFilingAccount'))
?.split('=')[1];
return !!filingCookie.match(/true/);
},

// Returns true if the given court identifier is for an appellate court.
isAppellateCourt: function (court) {
return PACER.APPELLATE_COURTS.includes(court);
Expand Down
26 changes: 26 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ const saveCaseIdinTabStorage = async (object, case_id) => {
})
}

// Save a cookie in document.cookie to let the extension know that the user has filing rights
const setFilingState = () => {
document.cookie = "isFilingAccount=true;path=/;domain=.uscourts.gov";
}

// Reset the value of the cookie related to the filing rights of a user
const removeFilingState = () => {
document.cookie = "isFilingAccount=false;path=/;domain=.uscourts.gov";
}

// Default settings for any jquery $.ajax call.
$.ajaxSetup({
// The dataType parameter is a security measure requested by Opera code
Expand Down Expand Up @@ -278,3 +288,19 @@ const recapBanner = (result) => {
div.appendChild(small);
return div;
};

const recapEmailBanner = (css_class = 'recap-email-banner') => {
const div = document.createElement('div');
div.setAttribute('class', css_class);

const anchor = document.createElement('a');
anchor.target = '_blank';
anchor.href = `https://www.courtlistener.com/help/recap/email/`

const img = document.createElement('img');
img.src = chrome.extension.getURL('assets/images/icon-16.png');

anchor.innerHTML = `${img.outerHTML} Use @recap.email to automatically contribute all your cases to RECAP.`;
div.appendChild(anchor);
return div
}

0 comments on commit 9853c4e

Please sign in to comment.