JSFiddle - React, Tailwind, and code Playground
by Michel Plungjan
HTML
<span id="results"></span>
JavaScript
/*
Updated versions can be found at https://github.com/mikeymckay/google-spreadsheet-javascript
*/var GoogleSpreadsheet, GoogleUrl;
GoogleUrl = (function() {
function GoogleUrl(sourceIdentifier) {
this.sourceIdentifier = sourceIdentifier;
if (this.sourceIdentifier.match(/http(s)*:/)) {
this.url = this.sourceIdentifier;
try {
this.key = this.url.match(/key=(.*?)&/)[1];
} catch (error) {
this.key = this.url.match(/(cells|list)\/(.*?)\//)[2];
}
} else {
this.key = this.sourceIdentifier;
}
this.jsonCellsUrl = "//spreadsheets.google.com/feeds/cells/" + this.key + "/od6/public/basic?alt=json-in-script";
this.jsonListUrl = "//spreadsheets.google.com/feeds/list/" + this.key + "/od6/public/basic?alt=json-in-script";
this.jsonUrl = this.jsonCellsUrl;
}
return GoogleUrl;
})();
GoogleSpreadsheet = (function() {
function GoogleSpreadsheet() {}
GoogleSpreadsheet.prototype.load = function(callback) {
var intervalId, jsonUrl, safetyCounter, url, waitUntilLoaded;
url = this.googleUrl.jsonCellsUrl + "&callback=GoogleSpreadsheet.callbackCells";
$('body').append("<script src='" + url + "'/>");
jsonUrl = this.jsonUrl;
safetyCounter = 0;
waitUntilLoaded = function() {
var result;
result = GoogleSpreadsheet.find({
jsonUrl: jsonUrl
});
if (safetyCounter++ > 20 || ((result != null) && (result.data != null))) {
clearInterval(intervalId);
return callback(result);
}
};
intervalId = setInterval(waitUntilLoaded, 200);
if (typeof result != "undefined" && result !== null) {
return result;
}
};
GoogleSpreadsheet.prototype.url = function(url) {
return this.googleUrl(new GoogleUrl(url));
};
GoogleSpreadsheet.prototype.googleUrl = function(googleUrl) {
if (typeof googleUrl === "string") {
throw "Invalid url, expecting object not string";
}
this.url = googleUrl.url;
this.key =...