Google Gadget, Javascript (Or Other) Way To Port Collected Data - javascript

I am working on a Google Gadget that will collect some data through Google API's. What I am getting stuck on is how to collect the data and then save it somewhere to be processed later. The final idea being that I would run the gadget on my own computer it would collect the data and then save it to somewhere on my own computer. (I guess I want to emphasize that this is, for now, a small personal project and does not necessarily need fancy server scripts, I want to be able to run this all on my PC running XP).
Is there a pure Javascript way to save a file on a computer?
Can I use other languages besides XML, HTML, and Javascript to add functionality to my Google Gadget?
Edit: The goal of this is to be able to log how many of my contacts are signed into gchat over a period of time. I decided on a Gadget because that was the only way I could figure out how to access that information. Any other ways to approach this idea are welcome!

No, Javascript alone cannot save a file automatically. And be careful, javascript is affected by the no cross domain rule. If you're hosting the project on your own computer, why bother writing a complex Google Gadget?
I suggest a simple PHP script, and MySQL, if you like, to store the data. By itself, PHP should be more than enough to run most tasks. If you would like me to add in more info about this, please tell me what type of task.

In increasing order of flexibility:
The options object is almost certainly the easiest approach - not really designed for that kind of usage but I suspect it would be fine for your use case.
On windows you could use system.filesystem to get hold of the WScript FileSystemObject which you can then use to create files and write to them.
Also see the Google desktop API blog for embedding an SQLite database in your gadget (looks pretty easy).

Related

Any way to create an application with the local web page as an interface?

A few days ago I decided to make my own "interface" to make it easier to organize (and work with) some of my personal files. You know when a lot of related data, pictures and links are right in front of you and you can change them in a couple of clicks, this is very convenient.
I started by studying HTML, CSS and JS, because I thought that the changes made to the local page would be saved somewhere on my PC so I can just run Index.html and do whatever I want. But they didn't. Refreshing the page erased all changes.
Using browser localstorage does not suit me, because if I change the browser, the data will be lost. I wanted it to just open with Index.html and work fine even if I change my browser or move the site folder to another computer.
Then I decided to learn more about server-side languages (such as PHP or Node.js) because they are directly related to databases, so I was hoping to save changes through them. But these languages required me to really open the server, with ip and port tracking. And I just wanted to open a local page through one file, without any ports or connections via the console. So this method scared me off quickly.
So is there an easy way to make a local page like this? Maybe I have not studied well one of the above methods and it has this opportunity?
Or the best I can hope for is a simple application that will use that local page as an interface to interact with data? I accidentally heard about this possibility a long time ago. Then I will ask you to give at least a hint as to which language to choose for this.
I don't understand well everything that lies outside of vanilla HTML, CSS and JS, so a complete study of a complex language like Java or Python will be too difficult for me, and the goal is not worth such a lot of effort.
I hope I understand correcly what you are trying to do.
If your goal is to make an application to manage your files, I think the simplest solution will be, as you said, to look into NodeJS and the File system api which will let you interact with your files through javascript code.
Your program will have to be in two part that will have to interact:
the "front" html page
the "back" nodejs script
The downside is that you'll have to go deeper into your study of the language to learn how to create the interactions you want between your html file and your NodeJS application.
However, there is no need to open your server to the web to make it work. The NodeJS application can be set to listen to requests from only the computer that runs it (localhost).
I obviously can't get too much into details without knowing precisely what you want to do but you'll probably have to learn to make a local server with node (search "nodejs http" or "nodejs express"), then make requests to it via the html page's scripts (search "ajax request").
What you need to look into are (web based) content management systems. like strapi or "grand old dame" WordPress.

How to store and make changes to a database within a Chrome Extension?

I'm currently working on a Chrome Extension which searches for specific content within webpages.
Now, my idea is to build a Database based on the correctness of this search result (which would be verified by the users), so it can be more accurate in these searches as the database grows. Kind of like a Machine Learning process I guess.
I'm fairly new to programming and I would like your advice on what are the best possible ways to do this.
Currently I just have JS/HTML/CSS, and it seems to me that I'm gonna need some other language.
A single CSV that the Extension could read/write would be enough for this, I think. Or something with SQL.
Thanks in advance!
You have to compose and post a CRUD command to a web server page (a server you own or you controll)
That page can be written in php, asp.net..
Web server page receive the CRUD command and run the relevant statement on your database via OBCD driver (or other similar driver)
Normally the web server page then responds, as a result of your post, with a message (text, xml, json) that makes you understand if the command has been successfully executed or not.
EDIT 04/30/2021 16:24 Rome Timezone
you say:
which would be verified by the users
what did you mean exactly?
more users together contributes to make the shared database better ?
or every single user contribute by itself to make his own database better ?
if one then my previous answer could be a good start point.
if two, forget my previos answer a think to build a indexedDB within your extension.
Read a csv or txt file through XMLHttpRequest is not a problem, but how do you thing to write the same file with the same tool (XHR) ?
You could think about a Google public spreadsheet.
"Google Sheets" allows you through an "endpoint url" and a set of API to insert new rows\records and to read the entire content of the spreadsheet
or (if I remember correctly) part of its content.
I state that it's now 2 years or maybe more since I got interested in Google Sheets.
Based on the information in my possession, perhaps outdated,
I can tell you that "Google Sheets" it is a path that I DO NOT advise you to follow.
First, because spreadsheet url being public would allow an attacker to pollute your DB by inserting many rows\records
by simply typing a url in the browser's address bar or creating a simple bot that inserts thousands of lines in a while.
Second, because that set of API do not allow you to implement very sophisticated queries (certainly not at the database level).
If you are really interested in Google Sheets I suggest you check what I have just stated.
If you have to "waste" energy to learn something new
I would suggest you to give priority to SQL and then to a server-side programming language (php, asp.net, node.js)
However, a free space hosting service with php and mySQL support is not too difficult to find.

get other site's elements

Is there a way to use a not local site as a source for my own? For example get a price from an e-shop everytime my site refreshes.
Is it possible to use something similar to this but somehow from a custom source?
document.getElementsByClassName('price')[0]
Not directly inside a browser, at least not without great effort. Browsers take great pains to try to isolate sites from each other to prevent attacks called CSRF.
If you are running a system like nodejs or php to build your system, you can run a cron process to go fetch the price you need and embed it into your source.
I usually use python when I want to scrape a site, but most common programming languages will have libraries to import data from a url.

Is there any way to automatically synchronize html5 localstorage between computers

I have a simple offline html5/javascript single-html-file web application that I store in my dropbox. It's a sort of time tracking tool I wrote, and it saves the application data to local storage. Since its for my own use, I like the convenience of an offline app.
But I have several computers, and I've been trying to come up with any sort of hacky way to synchronize this app's data (which is currently using local storage) between my various machines.
It seems that chrome allows synchronization of data, but only for chrome extensions. I also thought I could perhaps have the web page automatically save/load its data from a file in a dropbox folder, but there doesn't appear to be a way to automatically sync with a specific file without user prompting.
I suppose the "obvious" solution is to put the page on a server and store the data in a database. But suppose I don't want a solution which requires me to maintain apps on a server - is there another way, however hacky, to cobble together synchronization?
I even looked for a while to see if there was a vendor offering a web database service - where I could, say, post/get a blob of json on demand, and then somehow have my offline app sync with this service, but the same-origin policy seems to invalidate that plan (and besides I couldn't find such a service).
Is there a tricky/sneaky solution to this problem using chrome, or google drive, or dropbox, or some other tool I'm not aware of? Or am I stuck setting up my own server?
I have been working on a Project that basically gives you versioned localStorage with support for conflict resolution if the same resource ends up being edited by two different clients. At this point there are no drivers for server or client (they are async in-memory at the moment for testing purposes) but there is a lot of code and abstraction to make writing your own drivers really easy... I was even thinking of doing a dropbox/google docs driver myself, except I want DynamoDB/MongoDB and Lawnchair done first.
The code is not dependent on jQuery or any other libraries and there's a pretty full features (though ugly) demo for it as are well.
Anyway the URL is https://github.com/forbesmyester/SyncIt
Apparently, I have exactly the same issue and invetigated it thoroghly. The best choice would be remoteStorage, if you could manage to make it work. It allows to use 3rd party server for data storage or run your own instance.

Are client-only web applications possible?

I want to create an internally used web app that can be run with just a copy of the web app and the DB (anything from a text file to MS Access/Excel would work fine). Is this possible? I don't want users to have to setup a SQL server to get the app to work. Having the files necessary to run the web app stored on a shared network drive would be ideal, for example. The problem is that JS can't write to a DB. Is there anything that can use to do this?
Like mentioned, I can assume that Access/Excel are installed, if there's anything that might help there.
It's most certainly possible. W3 has put up the specs for a client side database that can be accessed by JavaScript. The modern browsers have good support for it, and since this is for an internal application, you would have some level of control I believe.
Checkout this slide that shows a live demo of Indexed Database. The full spec can be found here. See this link for browsers that currently support IndexedDB. Here's another set of slides showcasing how to use IndexedDB.
However, with this approach, each user's browser has its own DB locally. If you want a centralized DB, then you will need a server.
You can perform database transactions with JavaScript. This is generally discouraged, because it has terrible security implications. However, in a completely local environment, you are probably not causing any additional security risks. (Because, your database is already on the user's machine.) You can see an example of how to use ADO in JavaScript at How to connect to SQL Server database from JavaScript in the browser? .
Possible, yes, Like Making cars that can float in the sea but could not work on dry roads.
Use winforms or something similar. Use the right tool.
If you insists, Firefox plugins can behave in the way you mentioned, and there is a way to bundle a web application with it's server (check the beginner tutorials for RoR to have an example for something similar with webrick).
If I understand your requirements, you might look into ColdFusion.
For example, you can run a DB query pretty simply, check here, in Adobe

Categories