4

Script to allow copying from a protected Google Doc

 1 year ago
source link: https://gist.github.com/Snarp/6c06f60899ca3f43bdd3d8170885f83f
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Script to allow copying from a protected Google Doc · GitHub

Instantly share code, notes, and snippets.

Script to allow copying from a protected Google Doc

Life saver! Thank you

Hahaha, it works! Thanks!

Is there a way to preserve formatting?

EDIT: So after some digging, I found that If you append the Google Doc URL where it says " /edit " with " /mobilebasic " instead, you are able to preserve the formatting much better when you highlight and copy.

bro this works ty so much life saver man

Hi! i tried using the script but it wasn't working. the middle pages were all missing and blank. Is there any updated script i could use?

Hi! i tried using the script but it wasn't working. the middle pages were all missing and blank. Is there any updated script i could use?

Did you make sure to scroll through the entire document so as to pre-load all the pages before trying the script? (Step 1.)
Otherwise, I'm not sure. Just thought that might help since I had that same issue at first.

Author

Hi! i tried using the script but it wasn't working. the middle pages were all missing and blank. Is there any updated script i could use?

As MikoFrosty says, for this script to catch the whole document without any blanks, you need to manually scroll down very slowly to let everything load, which is pretty slow and annoying; so, as an alternative, you can change the end of the document URL from "/edit" to "/mobilebasic".

As far as I can tell, the mobilebasic interface always loads the whole document automatically. I think it may sometimes drop some complex formatting, but that's probably not going to transfer perfectly regardless.

Hi! i tried using the script but it wasn't working. the middle pages were all missing and blank. Is there any updated script i could use?

Did you make sure to scroll through the entire document so as to pre-load all the pages before trying the script? (Step 1.)
Otherwise, I'm not sure. Just thought that might help since I had that same issue at first.

yep. i've done that. the result is: only the first two pages and last page's texts appeared. the pages in between are still blank.

Hi! i tried using the script but it wasn't working. the middle pages were all missing and blank. Is there any updated script i could use?

As MikoFrosty says, for this script to catch the whole document without any blanks, you need to manually scroll down very slowly to let everything load, which is pretty slow and annoying; so, as an alternative, you can change the end of the document URL from "/edit" to "/mobilebasic".

As far as I can tell, the mobilebasic interface always loads the whole document automatically. I think it may sometimes drop some complex formatting, but that's probably not going to transfer perfectly regardless.

i've done that too. scrolling until the last page. when i try to change the edit into mobilebasic i can see every page's text but can't highlight and copy any.

Hi! i tried using the script but it wasn't working. the middle pages were all missing and blank. Is there any updated script i could use?

As MikoFrosty says, for this script to catch the whole document without any blanks, you need to manually scroll down very slowly to let everything load, which is pretty slow and annoying; so, as an alternative, you can change the end of the document URL from "/edit" to "/mobilebasic".
As far as I can tell, the mobilebasic interface always loads the whole document automatically. I think it may sometimes drop some complex formatting, but that's probably not going to transfer perfectly regardless.

i've done that too. scrolling until the last page. when i try to change the edit into mobilebasic i can see every page's text but can't highlight and copy any.

Another workaround that worked for me: (For Chrome)
once you have to document in mobilebasic view, use F12 to open the inspector, then F1 to get to the Preferences tab, scroll to the bottom of the tab and select "Disable Javascript." Once that is done leave the inspector open and reload the page, then you should be able to highlight and copy the entire doc.

Hi! i tried using the script but it wasn't working. the middle pages were all missing and blank. Is there any updated script i could use?

As MikoFrosty says, for this script to catch the whole document without any blanks, you need to manually scroll down very slowly to let everything load, which is pretty slow and annoying; so, as an alternative, you can change the end of the document URL from "/edit" to "/mobilebasic".
As far as I can tell, the mobilebasic interface always loads the whole document automatically. I think it may sometimes drop some complex formatting, but that's probably not going to transfer perfectly regardless.

i've done that too. scrolling until the last page. when i try to change the edit into mobilebasic i can see every page's text but can't highlight and copy any.

Another workaround that worked for me: (For Chrome)
once you have to document in mobilebasic view, use F12 to open the inspector, then F1 to get to the Preferences tab, scroll to the bottom of the tab and select "Disable Javascript." Once that is done leave the inspector open and reload the page, then you should be able to highlight and copy the entire doc.

yooow this one worked. thanks a lot!!

i've tried using both scripts and neither have worked, but i don't have the best understanding of chrome and was wondering if someone else could take a shot at it? specifically for this doc, i need it to keep the formatting exactly.

Preview Tip:

1-6 as described above

(7) After copying document.body.innerText, take a blank .html file with the bare minimum skeleton and paste your content between the paragraph tag. e.g. :

<!DOCTYPE html>
<html>
<body>
<h1>Name of Your Document</h1>
<p>PASTE_YOUR_CONTENT_HERE</p>
</body>
</html>

(8) Edit the file with Notepad++ (or any likewise editor)
(9) Replace all occurrences of \n with <br> <Ctrl+h>
(10) Save the .html file and now open it with a browser. Now you can preview the content with the basic preserved formatting.

nice !!! it works

It didn't work for me, but I found a work around.

  1. Create a new blank google sheet. http://sheet.new is also a nifty trick.
  2. Enter the following formula on Cell A1
    =importrange("https://docs.google.com/spreadsheets/d/{ProtectedGoogleSheetID}/edit","{SheetName!Range}")
    make sure to replace the {ProtectedGoogleSheetID} as well as {SheetName!Range => Sheet1!A1:C999 for example}.

It's not editable yet, but you can copy the content.
(optional) Select All (Cmd+A), Copy content (Cmd+C), Paste values only (Cmd+Shift+V)

Good Lord.
Great help here. Thanks, sir

I would update the instructions to:

  1. Change the end of the document url from /edit to /mobilebasic.
  2. Disable Javascript (as described in steps 2 and 3 below).
  3. Keeping the console open, reload the page. Select all + copy.
  4. Create a new blank Google Doc. Paste.

That retained all formatting for me perfectly.

changing the URL end to the mobilebasic just results in a message "Sorry, unable to open the file at this time."

The end of the doc is /edit#gid=0 and when I change this to /mobilebasic I get that message.

It is also possible to just do
1 - 3 description above
after disablejavascript just Ctrl + P to save as PDF

@jd412369 Bravo! bro!

@mitar worked like a charm. btw you can just copy you don't need any other google doc

@jd412369 @deadcat6 @Snarp @Snarp

NOT WORKING FOR GOOGLE SLIDES. FYI. Disabling javascript bricks the UI, obviously. PDF printing also is caught by the deactivated javascript environment. I hacked around a little but could not find a solution. What needs to be stopped in the loaded javascript VM is the function that prevents all these thigns from happening. What is the official name for this function?

@le-dawg mitar's solution is worked for me.

Does not seems to work on google sheets, currently

Edit: solution - change the end of the url to /preview

Edit2: For excel users, I imagine this trick would work nicely, in combination with /preview https://twitter.com/asmith83/status/1549373680496656385

i make tool crawl data it but it working for text https://www.youtube.com/watch?v=fMW65aVWOmg

Can you share, thanks a lot.

i make tool crawl data it but it working for text https://www.youtube.com/watch?v=fMW65aVWOmg

Can you share, thanks a lot.

nice hack!


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK