uda / Hasadna Participation

// ==UserScript==
// @name        Hasadna Participation
// @namespace   http://www.hasadna.org.il/
// @version     0.4.1
// @description Submit your attendance at coding meetings semi-automatically
// @match       https://docs.google.com/*forms/d/1pMXeSh8sMAUBWMdSoGAoG55MmJAm0QJuU1ZlxDVTZbc/viewform*
// @author      uda
// @license     MIT; http://opensource.org/licenses/MIT
// @copyright   2014, Yehuda Deutsch <yeh@uda.co.il>
// ==/UserScript==

var usw = (typeof this.unsafeWindow !== 'undefined') ? this.unsafeWindow : window;
var doc = usw.document;
var localData = {fname:'',lname:'',pname:'',note:''};

var loadData = function() {
	localData = JSON.parse(usw.localStorage.getItem('hasadna_att_settings'));
};

var populateForm = function(focus) {
    document.querySelector("#entry_1519029560").value = localData.fname;
    document.querySelector("#entry_1863337503").value = localData.lname;
    document.querySelector("#entry_515986865").value = localData.pname;
    document.querySelector("#entry_246285601").value = localData.note;
    
    if (focus === undefined && focus) {
        document.querySelector("#entry_246285601").focus();
    }
};

if ('localStorage' in usw && usw.localStorage) {
    document.querySelector("#ss-submit").onclick = function() {
        usw.localStorage.setItem('hasadna_att_settings', JSON.stringify({
            fname: doc.querySelector('#entry_1519029560').value,
            lname: doc.querySelector('#entry_1863337503').value,
            pname: doc.querySelector('#entry_515986865').value,
            note: doc.querySelector('#entry_246285601').value,
        }));
        usw.localStorage.setItem('hasadna_isSetup', true);
    };
    
	var isSetup = usw.localStorage.getItem('hasadna_isSetup');
    if (!isSetup) {
        return;
    }
    
    loadData();
    populateForm();
    if (usw.confirm('האם לאשר השתתפות במפגש פיתוח?')) {
        document.querySelector("#ss-submit").click();
    }
}