summaryrefslogtreecommitdiff
path: root/examples/js/googledocs.js
blob: 3ebc67c0713ed45a390e9c171e7b5ec82cce6641 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!javascript

/*
 * Shortcut to toggle usage of Google Docs
 */
var shortCut = "tgd";

/*
 * Whether to initially use Google Docs
 */
var useDocs = true;

/*
 * list off all supported filetypes, comment / uncomment to enable/disable
 * filetype
 */
var supported = [ 
  "DOC", 
  "DOCX", 
  "XLS", 
  "XLSX", 
  "PPT", 
  "PPTX", 
  "ODT", 
  "ODS",
  "PDF", 
  "PAGES", 
  "AI", 
  "PSD", 
  "TIFF", 
  "DXF", 
  "SVG", 
  "EPS", 
  "PS", 
  "TTF",
  "OTF", 
  "XPS", 
  // "ZIP", 
  // "RAR"  
];


var id = signals.connect("download", downloadCheck);
var reg = new RegExp(".*\.(" + supported.join("|") + ")$", "i");

function downloadCheck(w, d) {
  if (w.mainFrame.host === "docs.google.com")
    return false;
  else if (reg.test(d.networkRequest.uri)) {
    w.loadUri("http://docs.google.com/viewer?url=" + d.networkRequest.uri);
    return true;
  }
}
function toggleDocs() {
  useDocs = !useDocs;
  if (!useDocs) {
    signals.disconnect(id);
    io.notify("Google Docs disabled");
  }
  else {
    id = signals.connect("download", downloadCheck);
    io.notify("Google Docs enabled");
  }
}
bind(shortCut, toggleDocs, "googleDocs");