Skip to content

Instantly share code, notes, and snippets.

@policevideorequests
Created January 27, 2015 18:12
Show Gist options
  • Save policevideorequests/f127163338036e66e455 to your computer and use it in GitHub Desktop.
Save policevideorequests/f127163338036e66e455 to your computer and use it in GitHub Desktop.
redact_go_report_for_website.js
// This script is free open source code copyright by Timothy A. Clemans 2015 licensed under GPL
app.addToolButton({cName: "RedactGoReportForWebsite", cLabel: "Redact Go Report for website", cEnable: "event.rc = (app.doc != null);", cExec: "redactForWebsite(this);" });
var redactForWebsite = app.trustedFunction( function(doc){
app.beginPriv();
var ssnRgExp = /\d{3}-\d{2}-\d{4}/; // regular expression for finding social security numbers
var redactionsMade = [];
var allTheWords = ''; // Save all the words so we can search for keywords that indicate whether or not redaction is required and whether or not
// there are attachments that need to be manually redacted
for (var page=0;page<doc.numPages;page++){
for (var i=0;i<doc.getPageNumWords(page);i++) {
allTheWords += doc.getPageNthWord(page,i) + ' ';
}
}
//app.alert(allTheWords);
words_to_remove=[];
for(var page=0;page<doc.numPages;page++){
for (var i=0;i<doc.getPageNumWords(page);i++){
// redact the address building number
if (doc.getPageNthWord(page,i) == 'Address') {
buildingAddressToRedact = doc.getPageNthWord(page,i+1);
var quad=doc.getPageNthWordQuads(page,i+1);
quad[0][0]=quad[0][2]-((quad[0][2]-quad[0][0])/doc.getPageNthWord(page,i+1).length)*(doc.getPageNthWord(page,i+1).length-2);
quad[0][4]=quad[0][0];
doc.addAnnot({type:"Redact",page: page,quads: quad,overlayText: "",alignment: 1,repeat:false});
// remove the address from the narrative
for (p=0;p<doc.numPages;p++) {
for (w=0;w<doc.getPageNumWords(p);w++) {
if (doc.getPageNthWord(p, w) == buildingAddressToRedact) {
var quad=doc.getPageNthWordQuads(p,w);
quad[0][0]=quad[0][2]-((quad[0][2]-quad[0][0])/doc.getPageNthWord(page,i+1).length)*(doc.getPageNthWord(p,w).length-2);
quad[0][4]=quad[0][0];doc.addAnnot({type:"Redact",page: p,quads: quad,overlayText: "",alignment: 1,repeat:false});
}
}
}
}
// redact words starting with V/, S/, and C/ and add the words to list of words to redact
// in case name is elsewhere in report without the V/, S/, or C/ flag
var prependsToCheck = ['V/', 'S/', 'C/'];
currentWord = doc.getPageNthWord(page,i,false).replace(/ /g,'');
if (prependsToCheck.indexOf(currentWord)!=-1) {
words_to_remove.push(doc.getPageNthWord(page,i+1,true).toLowerCase());
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i+1),overlayText: "",alignment: 1,repeat:false});
// check next two words if any are capitalized then redact
var word = doc.getPageNthWord(page,i+2);
if (word[0] === word[0].toUpperCase()) {
words_to_remove.push(word.toLowerCase());
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i+2),overlayText: "",alignment: 1,repeat:false});
}
}
// redact words marked for redaction
else if (words_to_remove.indexOf(doc.getPageNthWord(page,i).toLowerCase())!=-1){
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i),overlayText: "",alignment: 1,repeat:false});
}
// remove social security numbers
else if ((doc.getPageNumWords(page)-i)>3){
var stringToTest =doc.getPageNthWord(page,i, false)+doc.getPageNthWord(page,i+1, false)+doc.getPageNthWord(page,i+2, false);
if(ssnRgExp.test(stringToTest)){
redactionsMade.push('social security number')
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i),overlayText: "",alignment: 1,repeat:false});
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i+1),overlayText: "",alignment: 1,repeat:false});
doc.addAnnot({type:"Redact",page: page,quads: doc.getPageNthWordQuads(page,i+2),overlayText: "",alignment: 1,repeat:false});
}
}
}
};
var n = allTheWords.search(/Attachment/i);
allTheWords;
//doc.applyRedactions({bKeepMarks: false,bShowConfirmation: false,cProgText: ""});
app.endPriv();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment