Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Last active September 9, 2018 01:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save subtleGradient/f4808c0eef8c826592c91eacb84b0c21 to your computer and use it in GitHub Desktop.
Save subtleGradient/f4808c0eef8c826592c91eacb84b0c21 to your computer and use it in GitHub Desktop.
Google Docs script to Create new Document from selected text and then link selected text to that new document URL; Use Google Docs like a Wiki
/*
Copyright 2018 Thomas Aylott <oblivious@subtlegradient.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---
Some code copied from here:
https://developers.google.com/gsuite/add-ons/docs/quickstart/translate
*/
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Create new Document and link selected text', 'createNewDocumentAndLinkSelectedText')
.addToUi();
}
function onInstall(e) {
onOpen(e);
}
function createNewDocumentAndLinkSelectedText(){
var thisDoc = DocumentApp.getActiveDocument();
thisDoc
var selection = DocumentApp.getActiveDocument().getSelection();
if (selection == null){ throw new Error('Please select some text.');}
var doc = DocumentApp.create(getSelectedText());
insertLinkFromHereToThere(thisDoc, doc);
copySelectionToNewDoc(selection, doc);
selection.getRangeElements()
.filter(function(element){return element.getElement().editAsText})
.map(function(element){return element.getElement().editAsText()})
.forEach(function(text){
text.setLinkUrl(doc.getUrl());
});
}
function insertLinkFromHereToThere(parentDoc, childDoc) {
var parentDocNameP = childDoc.appendParagraph(parentDoc.getName());
parentDocNameP.setLinkUrl(parentDoc.getUrl());
}
function copySelectionToNewDoc(selection, targetDoc) {
var body = targetDoc.getBody();
selection.getRangeElements()
.map(function(element){return element.getElement()})
.forEach(function(element){
var type = element.getType();
if (type == DocumentApp.ElementType.PARAGRAPH){
body.appendParagraph(element.copy());
}
else if (type == DocumentApp.ElementType.TEXT){
body.appendParagraph(element.getText());
}
else if (type == DocumentApp.ElementType.TABLE){
body.appendTable(element.copy());
}
else if (type == DocumentApp.ElementType.LIST_ITEM){
body.appendListItem(element.copy());
}
else {
var typeText = type.toString();
Logger.log("Failed to insert element of type " + type);
}
});
targetDoc.saveAndClose();
}
function getSelectedText() {
var selection = DocumentApp.getActiveDocument().getSelection();
if (!selection) {
throw new Error('Please select some text.');
} else {
var text = [];
var elements = selection.getRangeElements();
for (var i = 0; i < elements.length; ++i) {
if (elements[i].isPartial()) {
var element = elements[i].getElement().asText();
var startIndex = elements[i].getStartOffset();
var endIndex = elements[i].getEndOffsetInclusive();
text.push(element.getText().substring(startIndex, endIndex + 1));
} else {
var element = elements[i].getElement();
// Only translate elements that can be edited as text; skip images and
// other non-text elements.
if (element.editAsText) {
var elementText = element.asText().getText();
// This check is necessary to exclude images, which return a blank
// text element.
if (elementText) {
text.push(elementText);
}
}
}
}
if (!text.length) {
throw new Error('Please select some text.');
}
return text;
}
}
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Privacy Policy for the Google Docs as Wiki script</title>
<h1>Privacy Policy</h1>
<p>Effective date: August 30, 2018</p>
<p>Things That Do Stuff, LLC ("us", "we", or "our") operates the http://thingsthatdostuff.com website (the "Service").</p>
<p>This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data. This Privacy Policy for Things That Do Stuff, LLC is powered by <a href="https://www.freeprivacypolicy.com/free-privacy-policy-generator.php">FreePrivacyPolicy.com</a>.</p>
<p>We use your data to provide and improve the Service. By using the Service, you agree to the collection and use of information in accordance with this policy. Unless otherwise defined in this Privacy Policy, terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, accessible from http://thingsthatdostuff.com</p>
<h2>Information Collection And Use</h2>
<p>We collect several different types of information for various purposes to provide and improve our Service to you.</p>
<h3>Types of Data Collected</h3>
<h4>Personal Data</h4>
<p>While using our Service, we may ask you to provide us with certain personally identifiable information that can be used to contact or identify you ("Personal Data"). Personally identifiable information may include, but is not limited to:</p>
<ul>
<li>Email address</li><li>First name and last name</li><li>Phone number</li><li>Address, State, Province, ZIP/Postal code, City</li><li>Cookies and Usage Data</li>
</ul>
<h4>Usage Data</h4>
<p>We may also collect information how the Service is accessed and used ("Usage Data"). This Usage Data may include information such as your computer's Internet Protocol address (e.g. IP address), browser type, browser version, the pages of our Service that you visit, the time and date of your visit, the time spent on those pages, unique device identifiers and other diagnostic data.</p>
<h4>Tracking & Cookies Data</h4>
<p>We use cookies and similar tracking technologies to track the activity on our Service and hold certain information.</p>
<p>Cookies are files with small amount of data which may include an anonymous unique identifier. Cookies are sent to your browser from a website and stored on your device. Tracking technologies also used are beacons, tags, and scripts to collect and track information and to improve and analyze our Service.</p>
<p>You can instruct your browser to refuse all cookies or to indicate when a cookie is being sent. However, if you do not accept cookies, you may not be able to use some portions of our Service.</p>
<p>Examples of Cookies we use:</p>
<ul>
<li><strong>Session Cookies.</strong> We use Session Cookies to operate our Service.</li>
<li><strong>Preference Cookies.</strong> We use Preference Cookies to remember your preferences and various settings.</li>
<li><strong>Security Cookies.</strong> We use Security Cookies for security purposes.</li>
</ul>
<h2>Use of Data</h2>
<p>Things That Do Stuff, LLC uses the collected data for various purposes:</p>
<ul>
<li>To provide and maintain the Service</li>
<li>To notify you about changes to our Service</li>
<li>To allow you to participate in interactive features of our Service when you choose to do so</li>
<li>To provide customer care and support</li>
<li>To provide analysis or valuable information so that we can improve the Service</li>
<li>To monitor the usage of the Service</li>
<li>To detect, prevent and address technical issues</li>
</ul>
<h2>Transfer Of Data</h2>
<p>Your information, including Personal Data, may be transferred to — and maintained on — computers located outside of your state, province, country or other governmental jurisdiction where the data protection laws may differ than those from your jurisdiction.</p>
<p>If you are located outside United States and choose to provide information to us, please note that we transfer the data, including Personal Data, to United States and process it there.</p>
<p>Your consent to this Privacy Policy followed by your submission of such information represents your agreement to that transfer.</p>
<p>Things That Do Stuff, LLC will take all steps reasonably necessary to ensure that your data is treated securely and in accordance with this Privacy Policy and no transfer of your Personal Data will take place to an organization or a country unless there are adequate controls in place including the security of your data and other personal information.</p>
<h2>Disclosure Of Data</h2>
<h3>Legal Requirements</h3>
<p>Things That Do Stuff, LLC may disclose your Personal Data in the good faith belief that such action is necessary to:</p>
<ul>
<li>To comply with a legal obligation</li>
<li>To protect and defend the rights or property of Things That Do Stuff, LLC</li>
<li>To prevent or investigate possible wrongdoing in connection with the Service</li>
<li>To protect the personal safety of users of the Service or the public</li>
<li>To protect against legal liability</li>
</ul>
<h2>Security Of Data</h2>
<p>The security of your data is important to us, but remember that no method of transmission over the Internet, or method of electronic storage is 100% secure. While we strive to use commercially acceptable means to protect your Personal Data, we cannot guarantee its absolute security.</p>
<h2>Service Providers</h2>
<p>We may employ third party companies and individuals to facilitate our Service ("Service Providers"), to provide the Service on our behalf, to perform Service-related services or to assist us in analyzing how our Service is used.</p>
<p>These third parties have access to your Personal Data only to perform these tasks on our behalf and are obligated not to disclose or use it for any other purpose.</p>
<h3>Analytics</h3>
<p>We may use third-party Service Providers to monitor and analyze the use of our Service.</p>
<ul>
<li>
<p><strong>Google Analytics</strong></p>
<p>Google Analytics is a web analytics service offered by Google that tracks and reports website traffic. Google uses the data collected to track and monitor the use of our Service. This data is shared with other Google services. Google may use the collected data to contextualize and personalize the ads of its own advertising network.</p>
<p>You can opt-out of having made your activity on the Service available to Google Analytics by installing the Google Analytics opt-out browser add-on. The add-on prevents the Google Analytics JavaScript (ga.js, analytics.js, and dc.js) from sharing information with Google Analytics about visits activity.</p> <p>For more information on the privacy practices of Google, please visit the Google Privacy & Terms web page: <a href="https://policies.google.com/privacy?hl=en">https://policies.google.com/privacy?hl=en</a></p>
</li>
</ul>
<h2>Links To Other Sites</h2>
<p>Our Service may contain links to other sites that are not operated by us. If you click on a third party link, you will be directed to that third party's site. We strongly advise you to review the Privacy Policy of every site you visit.</p>
<p>We have no control over and assume no responsibility for the content, privacy policies or practices of any third party sites or services.</p>
<h2>Children's Privacy</h2>
<p>Our Service does not address anyone under the age of 18 ("Children").</p>
<p>We do not knowingly collect personally identifiable information from anyone under the age of 18. If you are a parent or guardian and you are aware that your Children has provided us with Personal Data, please contact us. If we become aware that we have collected Personal Data from children without verification of parental consent, we take steps to remove that information from our servers.</p>
<h2>Changes To This Privacy Policy</h2>
<p>We may update our Privacy Policy from time to time. We will notify you of any changes by posting the new Privacy Policy on this page.</p>
<p>We will let you know via email and/or a prominent notice on our Service, prior to the change becoming effective and update the "effective date" at the top of this Privacy Policy.</p>
<p>You are advised to review this Privacy Policy periodically for any changes. Changes to this Privacy Policy are effective when they are posted on this page.</p>
<h2>Contact Us</h2>
<p>If you have any questions about this Privacy Policy, please contact us:</p>
<ul>
<li>By email: thomas+privacypolicy@thingsthatdostuff.com</li>
</ul>
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Terms of service for the Google Docs as Wiki script</title>
<h1>Terms of Service ("Terms")</h1>
<p>Last updated: August 30, 2018</p>
<p>Please read these Terms of Service ("Terms", "Terms of Service") carefully before using the thingsthatdostuff.com website (the "Service") operated by Docs as Wiki tools ("us", "we", or "our").</p>
<p>Your access to and use of the Service is conditioned on your acceptance of and compliance with these Terms. These Terms apply to all visitors, users and others who access or use the Service.</p>
<p>By accessing or using the Service you agree to be bound by these Terms. If you disagree with any part of the terms then you may not access the Service. This Terms of Service agreement for Docs as Wiki tools is <a href="https://termsfeed.com/terms-conditions/generator/">based on the Terms and Conditions from TermsFeed</a>.</p>
<h2>Links To Other Web Sites</h2>
<p>Our Service may contain links to third-party web sites or services that are not owned or controlled by Docs as Wiki tools.</p>
<p>Docs as Wiki tools has no control over, and assumes no responsibility for, the content, privacy policies, or practices of any third party web sites or services. You further acknowledge and agree that Docs as Wiki tools shall not be responsible or liable, directly or indirectly, for any damage or loss caused or alleged to be caused by or in connection with use of or reliance on any such content, goods or services available on or through any such web sites or services.</p>
<p>We strongly advise you to read the terms and conditions and privacy policies of any third-party web sites or services that you visit.</p>
<h2>Governing Law</h2>
<p>These Terms shall be governed and construed in accordance with the laws of Florida, United States, without regard to its conflict of law provisions.</p>
<p>Our failure to enforce any right or provision of these Terms will not be considered a waiver of those rights. If any provision of these Terms is held to be invalid or unenforceable by a court, the remaining provisions of these Terms will remain in effect. These Terms constitute the entire agreement between us regarding our Service, and supersede and replace any prior agreements we might have between us regarding the Service.</p>
<h2>Changes</h2>
<p>We reserve the right, at our sole discretion, to modify or replace these Terms at any time. If a revision is material we will try to provide at least 30 days notice prior to any new terms taking effect. What constitutes a material change will be determined at our sole discretion.</p>
<p>By continuing to access or use our Service after those revisions become effective, you agree to be bound by the revised terms. If you do not agree to the new terms, please stop using the Service.</p>
<h2>Contact Us</h2>
<p>If you have any questions about these Terms, please contact us.</p>
@subtleGradient
Copy link
Author

@subtleGradient
Copy link
Author

Select some text and then select the menu item "Docs as Wiki (tools) / Create new Document and link selected text"

@subtleGradient
Copy link
Author

docs as wiki tools screenshot

docs as wiki tools banner

docs as wiki tools icon

@subtleGradient
Copy link
Author

docs as wiki tools screenshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment