Current situation
I'm developing a bookmarklet by using a stub as the actual bookmark that sources JavaScript code in a file on GitHub. I test the bookmarklet on a webpage and then I make changes to the JavaScript code in a text editor, push it to the GitHub file with git on the command line, and then run the bookmarklet again on the web page.
Problems with current situation
This approach seems tedious to me. Every time I make a change to the JS code in the text editor I have to save in the text editor and write 3 commands (git add, git commit, git push) to update the changes in the GitHub file (and then click the bookmarklet again).
What's more frustrating is that it seems like Chrome takes a very long time to recognize the changes in a recently changed GitHub file. I test this by making a simple alert("message"); command, changing the message value, pushing the changed code to GitHub (successfully), and seeing if the bookmarklet stub sources the recently changed file (it doesn't).
I avoid caching by appending a random number to the GitHub file URL sourced by the stub - stub shown below:
javascript:(function(){
var script=document.createElement('script');
script.type='text/javascript';
script.src='https://rawgit.com/username/repo_name/master/bookmarklet.js?v='+(Math.random()*1000);
document.body.appendChild(script);})();
Question
Is there a better way to develop bookmarklets where you can quickly see changes in bookmarklet code when the bookmarklet is used? Or can anyone see any problems in what I'm doing?
Thanks!
Related
I'm working on a very simple tool for a company, it's an aide to help visualize rail cuts.
I use a simple HTML page to build a display and then use JS to perform the simulated cuts and visualize them.
I have the file shared with some people via a shared drive. People in the US seem to be able to use the file without issue.
Someone in Europe tried to use the file and was able to open the file, but nothing happens upon trying to run the page's script, and when f12 is pressed, they receive the message in the title (their system is in Japanese locale I believe, so it is roughly translated).
They do not have this problem if they save the file locally and run it from there, only when using it from the shared folder.
Running the file content through https://validator.w3.org/ yields no problems or errors.
It works for me and most others I have asked to try the tool.
Let me know if additional info is needed. I'd like to try avoid sharing code if possible because the company will get mad if I share the proprietary code I made but I can if I need to.
Is there a simple way to start programs on mac from html?
I made an html page with a text field and a number of buttons. The intention is that when a code (numbers) is entered, it is copied to the clipboard. Via the buttons (each of which must open an application) the desired app opens and paste the code into the application (search or something ...). I already made this in AppleScript, but the layout is not that nice. That is why I wanted to work with HTML / CSS. Is there a simple way to run programs on mac starting from html/ Javascript?
I'm not sure if this is what you're looking for, but on Macs you can define custom URL schemes that will launch script applications to handle data. See:
Launch Scripts from Webpage
Which is an AppleScript-specific discussion of this:
How To Create Your Own URL Scheme
I'm also not sure of what you are looking for exactly, however, if it is vanilla JS, you can open the HTML file in the browser, which will also let you use the JavaScript as long as it is imported properly.
To open the HTML file in the browser, you can go to the file in the Finder then right-click and select "Open with Chrome". If you prefer to use a different browser, you can open it with whatever browser you want.
I'm working on internal project that generates an applescript based on a web form.
I can generate the correct script, but I'd like the option for somebody to click "run script" from the browser and have it do its thing, rather than copying and pasting the generated script into osx's script editor.
http://www.macosxautomation.com/applescript/linktrigger/
I've read through above but honestly it's not detailed enough for me to make useful sense of. Has anybody had luck with this?
You can create a link to Script Editor like this:
Link
In the example above the action parameter is set to create a new document and the script parameter defines the script copied to the new script document. After clicking the link a couple of confirmations are asked.
Apple uses this method in its Mac Automation Scripting Guide where you can test how it works.
Executing a script directly from a browser would be a massive security risk.
The method you linked would require that the script is already saved on user's computer as an application bundle.
I'm testing a new text editor, GitHub's Atom Editor, I'm writing HTML, so I want to open .html files in browser just like in Sublime Text 2/3 then I installed a package called run-in-browser.
I cannot get it to work, it will open one of my .html files, any other .html file doesn't open. Then, I changed to another package called open-in-browser. It seems to have the same issue!
I've had a bit of a play with the open-in-browser package, by creating a very simple test case I have created two files, test1.html and test2.html, by using the Ctrl-Alt-Q keyboard shortcut I am able to get both files to open up in Chrome:
All of this said I strongly recommend taking a look at Live Reload and the associated Atom Package, it takes a little bit of time to get everything setup but once it is done you will never need to open new tabs or hit the reload button.
I use Google Chrome Dev Tools to troubleshoot or debug JavaScript. I add break points and use watches, but a lot of the times it's convenient to just insert console.log(value) here and there in the script.
The problem is that when the page has to be refreshed in order to see the JS changes (and the console.log() calls), then the console.log() calls have been removed when the page reloads. Obviously this is because I didn't edit the actual source file itself.
Is it possible to maintain edits to JS files and still reload the page?
There are a lot of cases where I'm looking at other people's JS, learning and understanding it, so editing the source code is not even a possibility. Other times, when working on my own code, I might be debugging JS code on a live server, to editing my source to put in random console.log()'s is not desirable.
I know that Dev Tools has an auto save feature where the changes you make can save the actual source files (as long as the files are on a filesystem that is available to your computer). But that doesn't help in my case.
There is 'workspace' feature in DevTools.
It allows you to map the source files on your disk to the scripts of your page.
So when you apply your changes to the page's javascript they also will be saved to the disk.
If your web server serves these files from this folder then you will get the changed files after reload.