Created
September 26, 2017 00:56
-
-
Save bennettscience/46c1d68fef9039e4dc98be5240494d0d to your computer and use it in GitHub Desktop.
Proof of concept for a lite-style revision history in Google Docs
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
function revisionHistoryLite() { | |
var doc = DocumentApp.getActiveDocument(); | |
var eds = doc.getEditors(); | |
var original = doc.getBody().getParagraphs(); | |
var revs = Drive.Revisions.list(doc.getId()) | |
var editsList = []; | |
for(var i=0; i<revs.items.length; i++) { | |
var revision = revs.items[i]; | |
editsList.push([revision.id, revision.kind, revision.modifiedDate, revision.lastModifyingUser.emailAddress]); | |
if(revision.lastModifyingUser.emailAddress == "bbennett@elkhart.k12.in.us") { | |
var revUrl = Drive.Revisions.get(doc.getId(), revision.id).exportLinks["text/plain"] + "&access_token=" + ScriptApp.getOAuthToken(); | |
// revUrl returns https://docs.google.com/feeds/download/documents/export/Export?id=docIdString&revision=1&exportFormat=txt | |
var revString = UrlFetchApp.fetch(revUrl).getContentText(); | |
// Logger.log(revString); // Contains full HTTP markup | |
// Append the body contents to a temporary document for further processing | |
// var tempDoc = DocumentApp.create("Temp").getBody(); | |
// | |
// tempDoc.appendParagraph(revString); | |
// Test the string for sameness in the doc | |
// Ran into problems here testing a paragraph element as a string. Need to break it | |
// into sections and capture the offsets at some point. | |
for(var p=0; p<original.length; p++) { | |
if(original[p].getText() == revString) { | |
original[p].editAsText().setForegroundColor("#0000ff"); | |
} | |
if(original[p].getText() == revString) { | |
Logger.log(original[p].getText()); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment