Created
September 17, 2020 21:51
-
-
Save nikolay-n/52cebd5272425b4767375162a5f98ac1 to your computer and use it in GitHub Desktop.
Userscript to persist "Add N more rows at bottom" value in Google Spreadsheets
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
// ==UserScript== | |
// @name GoogleDocsExtensions | |
// @description Adds some features to Google Docs | |
// @match https://docs.google.com/spreadsheets/d/* | |
// ==/UserScript== | |
var storage = window.localStorage; | |
var oldHref = document.location.href; | |
var bodyList = document.querySelector("body"); | |
var currentHref = null; | |
var currentRowsInput = null; | |
var observer = new MutationObserver(function() { | |
if (oldHref != document.location.href) { | |
oldHref = document.location.href; | |
} | |
checkRowsInput(); | |
}); | |
var config = { | |
childList: true, | |
subtree: true | |
}; | |
observer.observe(bodyList, config); | |
function checkRowsInput(){ | |
var rowsInput = document.querySelector('.addRowsInput'); | |
if (!rowsInput) return; | |
if(rowsInput != currentRowsInput){ | |
currentRowsInput = rowsInput; | |
if(!rowsInput.getAttribute("isSetChangeHandler")){ | |
rowsInput.setAttribute("isSetChangeHandler", true); | |
rowsInput.addEventListener("change", function(){ | |
storage.setItem(oldHref, rowsInput.value); | |
}) | |
} | |
if(currentHref != oldHref){ | |
var rowsValue = storage.getItem(oldHref); | |
if(rowsValue){ | |
rowsInput.value = rowsValue; | |
} | |
currentHref = oldHref; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Used in Safari with https://github.com/quoid/userscripts extension