Detect local changes of JavaScript code - javascript

I have a website (game in JS). I would like to know if it's possible to detect if some client has edited and saved JavaScript file locally. My idea was to send the entire (or probably just part, it doesn't matter right now) .js file as POST parameter, so that PHP could compare it with .js file on server.
I've searched for local modifications, mutationobserver etc. but I haven't found the way.
Also, can JS file read itself?

Related

Using javascript with a local html file to delete itself?

I coded a local html file that kind of works like windows notepad would, using localStorage with JavaScript to auto save. To make new notes, I have just been saving the open file as another .html file and naming it something new for the note. But I have found this to be really annoying, because when I want to delete the note, I have to actually go into my Files app, find the .html file for the note, and delete it.
I know how to use event listeners and whatever, but is there a line of code I can use to delete the file or even just ask the user for confirmation to delete the file? I basically need a way for a local html file to be able to delete itself using JavaScript. Everything I have managed to find online says that you need Node.js and it has to be on a server, but I wanted to ask anyway, because I wonder if permissions are different when the file is stored locally and not on a server.
No.
You can't use browser JavaScript to manipulate the real local filesystem. (You could access a sandboxed one, but not the real filesystem.)

Is it possible to pull data from a CSV file locally automatically?

I am attempting to put data from a CSV file and put it into a String variable in an HTML file. The HTML and CSV file are under the same local directory on my computer. In Java and C++, I know it is possible to read and write to a text file. So, when using JavaScript, PHP, jQuery, or anything else, is it possible to set the string in my HTML file equal to the data from a local CSV file? I need a way to read the CSV text into a Javascript variable string.
I have a program currently that parses CSV formatted text, but I need the text to be pulled from a CSV file. I have read numerous posts saying that this is not possible because of security reasons - is this the case? All of the answers that I have seen require the user to select the file the want to pull from. I just want it to automatically be pulled from a specific CSV file always.
I'm sorry to have to disappoint you, but all the other comments where right. An app running in a browser is strictly not allowed to access the local file system without any user interaction. For the formerly mentioned security reasons. There is no way around, though.
Everyone was right - it is impossible to do it the way I was trying. However, I decided to host a local server on my PC using Python, and it worked like a charm! Credit to: https://youtu.be/1OK4TJfCzdY .

File Upload/Manipulation/Download without use of a server: Is it possible?

I am looking to make a website that does three things:
The user can upload an image to the website (without a server)
-For this problem, I have found resources like Dropzone, but all seem to mandate sending the image to a server.
The uploaded file is manipulated on the client side
-For this problem, I need the uploaded file to be accessible from my JS/HTML code and I need some way for me to manipulate the file. I currently have my website with the pre-set file embedded in it, which I can then access and manipulate with JS, so the manipulation itself isn't much of the issue, but rather just accessing the file.
The user can then download the manipulated file (again, without a server)
-For this problem, I know that how to make a download button for files that have a web address (which are on a server), but is there a way to have a download button for the file that was just manipulated? I found this question here that seems to be a good starting point, but I am not sure if I completely understand the implementation of it.
Basically, I have the website framework in place (using HTML/CSS, Javascript) and I am just looking to see if this is possible to do without the use of a server, even if I have to use some other libraries. If any insight or links to potentially useful articles/libraries could be given on any one of these three points, I would much appreciate it.
Note: If this is not possible without a server, please let me know because then I will have to completely redesign everything and this whole question is trivial.
The user can upload an image to the website (without a server)
A website is typically hosted on a server. I think you mean the image is uploaded, but not stored anywhere.
The uploaded file is manipulated on the client side
There are lots of cool JS libraries to handle this, for something light you can try out https://fengyuanchen.github.io/cropperjs/
The user can then download the manipulated file (again, without a server)
So if I am understanding you are asking for an image upload -> edit -> image download. This is very possible and common. However, you will need somewhere to cache the uploaded image for the client.
If you are asking if you can upload an image directly to the DOM, you can not. You need to upload the image to the location where your files are being hosted. Imagine having an absolute path to C:/MyComputer/MyImage, it would obviously not work on any other machine than your machine.
If you need some examples on how to handle the upload image to temp location -> edit -> download let me know

Altering a server file through javascript code

So I have a setup of a tablet connected to a Raspberry Pi computer. I want to be able to have a webpage hosted on the Pi change the contents of a file also hosted on the Pi (which will be used in a python script that i have written). I tried having the file inside a hidden iframe, but while my javascript ran, it didn't ever actually change the contents.
How can i set up communication between the webpage and the server files? I know nothing about jQuery in the slightest, but if i have to use it, I will.
While you can actually do something with files in HTML5, you must know that Javascript is a client-side script. In other words JS 'runs' on the persons browser and not really your server.
Languages like PHP actually run on your server, and therefor are able to achieve what you want.
I'm not THE Javascript expert, and you might even be able to modify a server file with JS but it will be 'hacky' and have a poor implementation and you might need to run a sort of API on your server that actually does the changing..
Save yourself the trouble of doing it like that and pick the right language for the job. I would suggest PHP. Its fairly easy to set that up and run the website. PHP has enough ways to create, view and modify files on the server itself: http://php.net/manual/en/book.filesystem.php

Save files into selected directory (javascript)

Hello! My question is about javascript.
I want to
1. ask a user to select a directory
2. then write my bunch of files to it (probably with creating sub-directories) without interaction with user
How can I do this? And can I?
I am new in javascript and I hope for your help.
PS.
I've heard about ability to ask a user to select a path by save file dialog and then save data to selected file, but i want to ask a user once for selecting a directory and then create a bunch of files in it without bothering a user for each one.
Javascript alone doesn't have any way to access the local computer's file system for WRITE purposes. Period.
However, Downloadify, by Doug Neiner, was built for this purpose and uses a combination of Javascript and the Flash library.
It needs Flash 10 to work.
Alternately, you can install apache onto the computer (or better yet, a full stack like XAMPP or WAMP/MAMP/LAMP) and use PHP (with javascript/ajax) to write files onto the local file system. However, this means that the website must also be hosted locally. Probably your best bet is Downloadify
Resources:
https://github.com/dcneiner/Downloadify
How to create xml file with jquery
Save content using Jquery? Write to file
Saving to server-side file using AJAX

Categories

Resources