Is there an example of how to add Replace to Google Docs - google-apps-script

Is there an example anywhere of how to use the Document apps-script API to add a button to the Google Docs menu, when it is clicked bring up a web page from my web app that prompts the user for 2 strings, then on OK it does a search & replace on the open document?
I don't need to add search/replace per-se. I just figure this is the simplest example of writing an Add-In to Google Docs that edits the open document.
thanks - dave

As it stands, this is not possible. I think this issue (which you might like to star so that you can receive updates in the thread) best describes it. Summary in post #7:
This feature request is to add the same script functionality to a
document as there is in a spreadsheet. ie menu items etc.

A recent video by google (see their blogs) hints that this will be soon available.
In the meantime u can ask for the document url from your published script interface.
If you make a googledrive.com client app you can even use the new goglepicker to select the doc.

Related

Put the URL (prepended with the text "Parent_") for a particular Google Doc into that Google Doc's own header and footer

Overview
Essentially I want to be able to migrate my Google Docs to a regular website while maintaining the links I had created between my Google Docs.
A proposed solution
What do you think about having a Google Apps Script put the URL (prepended with the text "Parent_") for a particular Google Doc into that Google Doc's own header and footer, once and only once, when that Google Doc is initially created? (I almost never use headers and footers therefore it seems like it might be reasonable to use them as if they were akin to fields in a database).
For example,
Create a Google Doc.
Let's say, that Google Doc, has the following URL https://docs.google.com/document/d/1XwCyQ2MAIJgcLwfmR9-_JQq97H9iVLbGXNbpbzq1-Oo/
Put Parent_https://docs.google.com/document/d/1XwCyQ2MAIJgcLwfmR9-_JQq97H9iVLbGXNbpbzq1-Oo/ into the header and footer.
That way when a Google Doc is exported as an HTML document, it will contain 2 instances of the following string: Parent_https://docs.google.com/document/d/1XwCyQ2MAIJgcLwfmR9-_JQq97H9iVLbGXNbpbzq1-Oo/ into the header and footer
Then, with a simple find/replace (RegEx) the HTML files could be relinked.
To be safe, I might run a Google Apps Script once a week to confirm that each Google Doc contained two instances of "Parent_" followed by the URL.
Finally, what if, say, once a week I were to export my Google Doc's as HTML files, upload them to a regular website, and run, say, a Python script to ensure that every Google Doc that contained "URL001" that was not prepended with "Parent_" actually linked to "Parent_URL001"
Fundamentally, it's a kludge. I know that. But I'm trying to circumvent, what is effectively, a "soft lock-in" feature in Google Docs for those who create hyperlinks between Google Docs.
My problem described in detail
Frequently I link one Google Doc to another Google Doc. As a result, I have created something that is similar to a wiki. For example let’s suppose I had created two Google Docs: Google Doc #1 and Google Doc #2.
Subsequently let’s suppose I had created a link (a hyperlink) in Google Doc #1 to Google Doc #2. Of course that's an extremely simple example. Let’s make it more complex. Imagine I had created a couple of thousand Google Docs with many links (hyperlinks) between them.
Of course backing up those Google Docs would be trivial either by using Google Takeout or rsync. However, what would happen if I wanted to move those Google Docs to a regular website? Then the myriad hyperlinks I had created would fail to point to the documents on my regular website.
That is, on my regular website, if I were to click on the link on the page which contained the contents which had been contained in Google Doc #1 (https://my_regular_website.com/google_doc_001) then instead of opening a link on my regular website to the page which contained the contents which had been contained in Google Doc #2 (https://my_regular_website.com/google_doc_002) , the link would point to the original Google Doc #2 (https://drive.google.com/drive/folders/google_**doc_002**)
Why not use Notion or at least a wiki?
I like using Google Docs as a word processor. Sometimes I use Google Docs to write essays. Sometimes I use Google Docs to create documentation. Sometimes I use Google Docs to collaborate with others (instead of emailing). Furthermore, I often use Google Docs’ outline format, styles, and voice typing.
As far as I know, neither Notion nor any wiki have all of the features listed above.

Chrome Extension or Gmail Contextual Gadget?

I've been looking into adding an "extension" for gmail, this is for an application at work, basically we want to somehow integrate some options (buttons), somewhere contextual to the email that's being viewed currently.
Our users, will then be able to install extension, and the extension will establish the authorisation aspect (not sure how this is done yet) with our application.
I've so far looked into two options, not sure if I'm on the right track:
Chrome extension, that then uses gmail.js (some third party library on github), and use some jquery to search the DOM to insert a button into the reply/delete toolbar.
I understand that this would be more straight forward but would have issues with it breaking if page layout changes, or class names changes. And would also require uses to be using chrome (which is something we are fine about)
Create a gmail contextual gadget add-on, that sits at the bottom of the email, although, I'm not sure if this contextual gadget will appear at the end of the main thread of an email or inside each individual email and will require expanding?
Also correct me if I'm wrong, but are gmail contextual gadgets limited to users with Google Apps subscription in their company? I.e. we have to subscribe to google apps in our domain and deploy it on the google apps marketplace, and similarly also have the users who want to install this gadget to also be using google apps?
Thank for everyones help in advance.

flashcards by using google spreadsheet

I am trying to create flashcards by using google spreadsheet.
I tried the way suggested at this page
It produces a panel containing the flashcards but actually it is empty.
I am using the last version of google chrome to produce it.
To me, the flashcards gadget, embedded into google dive, seems too old to work with the current version of google chrome.
My questions are:
Could it be possible?
What could be an alternative way to make flashcards related to your gmail account?
According Google Drive Support the Gadgets in Google Spreadsheets will be deprecated.
http://support.google.com/drive/bin/answer.py?hl=en&topic=15165&answer=2791335.
A good alternative could be http://api.flashcardstogo.com/webapp/
Since gadgets have now been deprecated the makeuseof method no longer works.
Fortunately http://flippity.net/ provides similar functionality using publicly shared (obfuscated) links.
Tip: Create a study topic bookmark folder in your bookmarks containing links to both your google spreadsheet and the flippity generated flashcard. That way you can open both with, right-click + "open all bookmarks". It makes it easier to study and add new cards.

Can I use Google Drive's editor interface embed in a website?

I want to use google drive to store the files, but allow the users of my website to be able to edit them transparently, so that they don't have to go to google drive's website.
Is this possible with the current API? Thus far I have only seen how to create an app for them to install in google drive, or doing something like DrEdit (https://developers.google.com/drive/examples/), which parses the files to JSON and uses the ACE editor, which is definitely not what I want.
EDIT:
I believe it is not possible to do this with Google Drive, I've decided to go with Zoho Docs instead.
Yes it's possible. The biggest consideration is how much formatting you want to support. Eg. if it's plain text, it's very simple. If you want to support character or layout formatting, it becomes more complex.
I don't believe its possible to embed the editor (or even embed a preview!) using an iframe, because if you look at how the google docs page loads, it first redirects you to the login page, and that automatically logs you in if you are already logged in, and redirects you back to the docs editor.
This means that the iframe would have to at least pass through the login page, even if the user doesn't need to enter anything. However, google's login page has the x-frame-option header set to SAMEORIGIN (or deny?), and thus, the browser refuses to display it, and thus you can't actually get logged in!
The only way I've found to enable just preview embedding (not editing), is to publish the document first (via the File->publish to web menu item).

opening html from google drive

I have made a page in html5 with css3. It works fine on local (I dont use any server, just doubleclick in the index to open it).
I want to put it in google drive. I have load all the documents needed, but when I try to open the html, I can only see the text (I mean, it is not being executing, I can see just the source code).
Any suggestion?
Not available any more, https://support.google.com/drive/answer/2881970?hl=en
Host web pages with Google Drive
Note: This feature will not be available after August 31, 2016.
I highly recommend https://www.heroku.com/ and https://www.netlify.com/
EDIT: As of August 2016 Google Drive can no longer be used to host static web pages, so this solution no longer works.
Create a new folder in Drive and share it as "Public on the web."
Upload your content files to this folder.
Right click on your folder and click on Details.
Copy Hosting URL and paste it on your browser.(e.g. https://googledrive.com/host/0B716ywBKT84AcHZfMWgtNk5aeXM)
It will launch index.html if it exist in your folder other wise list all files in your folder.
I don't think it is necessary to "host" the content using the way from the accepted answer. It is too complicated for a normal user with limited developing skills.
Google actually has provided hosting feature without using Drive SDK/API, what you need is just few clicks. Check this out:
http://support.google.com/drive/bin/answer.py?hl=en&answer=2881970
It is the same to the answer of user1557669. However, in step 4, the URL is not correct, it is like:
https://drive.google.com/#folders/...
To get the correct host URL. Right click on the html file (you have to finish 1-3 steps first and put the html in the public shared folder), and select "Details" from the context menu. You will find the hosting URL right close to the bottom of the details panel. It should look like:
https://googledrive.com/host/.../abc.html
Then you can share the link to anyone. Happy sharing.
Now you can use
https://sites.google.com
Build internal project hubs, team sites, public-facing websites, and more—all without designer, programmer, or IT help. With the new Google Sites, building websites is easy. Just drag content where you need it.
While drive allows you to edit plain text and HTML files I don't believe they allow the HTML to actually be displayed. I don't think they want people hosting websites from their drive space.
A lot of the solutions offered here do not seem to work anymore. I'm currently on a chromebook and wanted to view an HTML5 banner. This seems impossible now through Google Drive or other apps (as mentioned in previous comments).
The method I ended up using to view the HTML5 was the following:
Open Google Adwords (create a free account if you dont have one)
Click on Ads in the top panel
Click on "+AD" and choose image ad
Choose "upload an ad"
Drag and drop your zip file into the area
Click on Preview
Voila, you will see your HTML5 banners in their full beauty
There may well an easier way, but this way is pretty good too. Hope it helps and worked well for me.
Create a new folder in Drive and share it as "Public on the web."
Upload your HTML, JS & CSS files to this folder.
Open the HTML file & you will see "Preview" button in the toolbar.
Share the URL that looks like www.googledrive.com/host/... from the preview window and anyone can view your web page.
Found method to see your own html file (from here (scroll down to answer from prac): https://productforums.google.com/forum/#!topic/drive/YY_fou2vo0A)
-- use Get Link to get URL with id=... substring
-- put uc instead of open in URL