Advertisement
Guest User

gdrive/hemingway integration /im3w1l

a guest
Feb 12th, 2014
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Document Read
  3. // @namespace   bogus
  4. // @include     https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
  5. // @version     1
  6. // @include     https://docs.google.com/*
  7. // @include     http://www.hemingwayapp.com/
  8. // @grant       GM_openInTab
  9. // @grant       GM_setValue
  10. // @grant       GM_getValue
  11. // @grant       GM_deleteValue
  12. // ==/UserScript==
  13.  
  14. function beginsWith (a, b) {
  15.     return a.substring(0,b.length) == b;
  16. }
  17.  
  18. var tb = document.getElementById("docs-primary-toolbars");
  19. if (beginsWith (document.location.href, "https://docs.google.com/") && tb) {
  20.     var nb = document.createElement("input");
  21.     nb.type="button"
  22.     nb.value="Check em"
  23.     function getTexts(node){
  24.         var text = "";
  25.         if(node.nodeType === 3){
  26.             text+=node.nodeValue+"\n";
  27.         }
  28.         else if(node.nodeType === 1) {
  29.            var children = node.childNodes;
  30.            for(var i = 0; i < children.length; ++i) {
  31.               text += getTexts(children[i]);
  32.            }
  33.         }
  34.         return text;
  35.     }
  36.  
  37.     function checkem() {
  38.         tt = document.getElementsByClassName("kix-appview-editor")[0];
  39.         var texts = getTexts(tt);
  40.        
  41.         GM_setValue("hemingway-text", texts);
  42.         GM_openInTab("http://www.hemingwayapp.com");
  43.     }
  44.     nb.onclick=checkem;
  45.     tb.appendChild (nb);
  46. } else if (beginsWith(location.href, "http://www.hemingwayapp.com")) {
  47.     var texts = GM_getValue ("hemingway-text");
  48.     if (texts !== undefined) {
  49.         var editor = document.getElementById("editor");
  50.         editor.value=texts;
  51.         GM_deleteValue ("hemingway-text");
  52.        
  53.         var event = document.createEvent("KeyboardEvent");
  54.         event.initKeyEvent("keyup",true,true,null,false,false,false,false,0,0);
  55.         editor.dispatchEvent(event);
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement