Last active
December 15, 2017 09:21
-
-
Save mmodrow/93dbaae65fc5621eb9619d14e6d760c0 to your computer and use it in GitHub Desktop.
Adds load and save feature on the command line for carrying state on https://frontendchecklist.io beyond browser sessions
This file contains hidden or 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 The Front-End Checklist Persistator | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description load and store data put into "The Front-End Checklist" | |
// @author Marc Modrow | |
// @match https://frontendchecklist.io | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
window.mmodrow = window.mmodrow || {}; | |
window.mmodrow.frontendchecklist_io = window.mmodrow.frontendchecklist_io || {}; | |
window.mmodrow.frontendchecklist_io.getState = function(){ | |
var output = {"Checkboxes":{}, "Inputs": {}}; | |
document.querySelectorAll("input[type=checkbox]").forEach(item => output.Checkboxes[item.id] = item.parentNode.parentNode.parentNode.parentNode.dataset.itemCheck === "true"); | |
[...document.querySelectorAll("input[type=text]")].filter(item => item.name !== "EMAIL" && item.tabIndex !== -1).forEach(item => output.Inputs[item.id] = item.value); | |
return output; | |
}; | |
window.mmodrow.frontendchecklist_io.setState = function(input){ | |
input = input || {"Checkboxes":{}, "Inputs": {}}; | |
document.querySelectorAll(".js-uncheck-all").forEach(item => item.click()); | |
Object.entries(input.Inputs).forEach(item => document.getElementById(item[0]).value = item[1]); | |
Object.entries(input.Checkboxes).filter(item => item[1]).forEach(item => document.getElementById(item[0]).click()); | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment