Skip to content

Instantly share code, notes, and snippets.

@konrness
Created January 31, 2017 20:51
Show Gist options
  • Save konrness/4dc21c63009a7c15211dc76a57a6700c to your computer and use it in GitHub Desktop.
Save konrness/4dc21c63009a7c15211dc76a57a6700c to your computer and use it in GitHub Desktop.
Generate a log of all cell changes, across all sheets, in a Google Spreadsheet Revision History page.
/**
* This script is intended to be run in the Chrome developer console when viewing a Google Spreadsheet in Revision History mode.
* It will iterate through each sheet in the spreadsheet, looking for changed cells, and will log the cells that changed.
*
* Steps to Use:
* 1) Load Google Spreadsheet, click File -> Revision History
* 2) Select the revision you wish to log in the right column
* 3) Open the Developer Tools console and go to the Console tab.
* 4) Paste the following code into the console.
* 5) Run the function in the console: logChanges();
*
* This will log an output similar to the following:
*
* No changes on sheet: Foo
* No changes on sheet: Bar
* 2 changes on sheet: Baz
* Changed by John Doe. Lorem Ipsum
* Changed by John Doe. Lorem Ipsum
* Done
*
*/
var logChanges = function () {
var mysheets = document.getElementsByClassName("docs-sheet-container-bar")[0].getElementsByClassName("docs-sheet-tab");
var loadSheet = function (mysheets, i) {
var currentSheetTab = mysheets[i];
// switch sheets
currentSheetTab.dispatchEvent(new MouseEvent("mousedown", {'bubbles' : true}));
var frame = document.getElementsByClassName("waffle-revisions-frame")[0];
frame.onload = function() {
// check if there are changes on this shet
var changes = document.getElementsByClassName("waffle-revisions-frame")[0].contentDocument.getElementsByClassName("changed");
if (changes.length == 0) {
console.log("No changes on sheet: " + currentSheetTab.textContent);
} else {
console.log(changes.length + " changes on sheet: " + currentSheetTab.textContent);
for (var v = 0; v < changes.length; v++) {
console.log(" " + changes[v].getAttribute('aria-label'));
};
}
// load next sheet
if (i > 0) {
loadSheet(mysheets, i - 1);
} else {
console.log("Done");
}
}
};
// load last sheet
loadSheet(mysheets, mysheets.length - 1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment