-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Oguzhan Ergin
committed
Dec 23, 2014
1 parent
9637a8d
commit a8ede08
Showing
7 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// ==UserScript== | ||
// @name Office Online Viewer | ||
// @description View office documents in your browser with Microsoft Office Online | ||
// @namespace ogzergin | ||
// @version 0.1 | ||
// @include * | ||
// @exclude http*://view.officeapps.live.com/* | ||
// @exclude http*://docs.google.com/* | ||
// @exclude http*://mail.google.com/* | ||
// @exclude http*://viewer.zoho.com/* | ||
// @exclude http*://office.live.com/* | ||
// ==/UserScript== | ||
|
||
var pageLinks=document.links; | ||
var fileTypes=["doc","docx","xls","xlsx","ppt","pps","pptx"]; | ||
|
||
//https://view.officeapps.live.com/op/view.aspx?src= | ||
var strOfficeHost ="view.officeapps.live.com"; | ||
var strViewOfficeUrl = "https://" + strOfficeHost + "/op/view.aspx?src="; | ||
|
||
parseLinks(); | ||
|
||
addDebouncedEventListener(document, 'DOMNodeInserted', function(evt) { | ||
parseLinks(); | ||
}, 1000); | ||
|
||
function endsWith(str, suffix) { // check if string has suffix | ||
return str.indexOf(suffix, str.length - suffix.length) !== -1; | ||
} | ||
|
||
function stripQueryString(str) { | ||
return str.protocol + '//' + str.hostname + str.pathname; | ||
} | ||
|
||
function parseLinks(){ | ||
|
||
for(var i=0;i<pageLinks.length;i++){ | ||
if(pageLinks[i].isParsed != true && pageLinks[i].host != strOfficeHost){ | ||
parseLink(pageLinks[i]); | ||
pageLinks[i].isParsed=true; | ||
} | ||
} | ||
} | ||
|
||
function parseLink(link){ | ||
|
||
var url = stripQueryString(link); | ||
|
||
if(checkType(url)){ | ||
addOfficeLink(link); | ||
} | ||
|
||
} | ||
|
||
function checkType(str){ | ||
for(var i=0; i<fileTypes.length; i++){ | ||
if(endsWith(str, '.'+fileTypes[i])) | ||
return true; | ||
} | ||
return false; | ||
} | ||
//word => http://i.imgur.com/Wce14X6.png | ||
//powerpoint => http://i.imgur.com/iQn5mKp.png | ||
// excel => http://i.imgur.com/xPTt5d6.png | ||
function addOfficeLink(link){ | ||
var officeLink = document.createElement('a'); | ||
officeLink.href = strViewOfficeUrl + encodeURI(stripQueryString(link)); | ||
officeLink.isParsed=true; | ||
officeLink.target="_blank"; | ||
|
||
var ico = document.createElement("img"); | ||
|
||
if(endsWith(officeLink.href, ".doc")||endsWith(officeLink.href, ".docx")) | ||
ico.src = "http://i.imgur.com/Wce14X6.png"; | ||
else if(endsWith(officeLink.href, ".xls")|| endsWith(officeLink.href, ".xlsx")) | ||
ico.src = "http://i.imgur.com/xPTt5d6.png"; | ||
else | ||
ico.src = "http://i.imgur.com/iQn5mKp.png"; | ||
|
||
|
||
ico.style.marginLeft = "5px"; | ||
officeLink.appendChild(ico); | ||
link.parentNode.insertBefore(officeLink, link.nextSibling); | ||
|
||
} | ||
|
||
function addDebouncedEventListener(obj, eventType, listener, delay) { | ||
var timer; | ||
|
||
obj.addEventListener(eventType, function(evt) { | ||
if (timer) { | ||
window.clearTimeout(timer); | ||
} | ||
timer = window.setTimeout(function() { | ||
timer = null; | ||
listener.call(obj, evt); | ||
}, delay); | ||
}, false); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "Office Online Viewer", | ||
"version": "0.1", | ||
"manifest_version": 2, | ||
"description" : "View office documents in your browser with Microsoft Office Online", | ||
"icons": { "16": "icons/16x16.png", "48": "icons/48x48.png", "128": "icons/128x128.png" }, | ||
|
||
"content_scripts": [ | ||
{ | ||
"matches": ["http://*/*", "https://*/*"], | ||
"exclude_matches": ["http://view.officeapps.live.com/*", "https://view.officeapps.live.com/*", "http://office.live.com/*", "https://office.live.com/*", "http://docs.google.com/*", "https://docs.google.com/*", "http://mail.google.com/*", "https://mail.google.com/*", "http://viewer.zoho.com/*", "https://viewer.zoho.com/*"], | ||
"js": ["content.js"] | ||
} | ||
] | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// ==UserScript== | ||
// @name Office Online Viewer | ||
// @description View office documents in your browser with Microsoft Office Online | ||
// @namespace ogzergin | ||
// @version 0.1 | ||
// @include * | ||
// @exclude http*://view.officeapps.live.com/* | ||
// @exclude http*://docs.google.com/* | ||
// @exclude http*://mail.google.com/* | ||
// @exclude http*://viewer.zoho.com/* | ||
// @exclude http*://office.live.com/* | ||
// ==/UserScript== | ||
|
||
var pageLinks=document.links; | ||
var fileTypes=["doc","docx","xls","xlsx","ppt","pps","pptx"]; | ||
|
||
//https://view.officeapps.live.com/op/view.aspx?src= | ||
var strOfficeHost ="view.officeapps.live.com"; | ||
var strViewOfficeUrl = "https://" + strOfficeHost + "/op/view.aspx?src="; | ||
|
||
parseLinks(); | ||
|
||
addDebouncedEventListener(document, 'DOMNodeInserted', function(evt) { | ||
parseLinks(); | ||
}, 1000); | ||
|
||
function endsWith(str, suffix) { // check if string has suffix | ||
return str.indexOf(suffix, str.length - suffix.length) !== -1; | ||
} | ||
|
||
function stripQueryString(str) { | ||
return str.protocol + '//' + str.hostname + str.pathname; | ||
} | ||
|
||
function parseLinks(){ | ||
|
||
for(var i=0;i<pageLinks.length;i++){ | ||
if(pageLinks[i].isParsed != true && pageLinks[i].host != strOfficeHost){ | ||
parseLink(pageLinks[i]); | ||
pageLinks[i].isParsed=true; | ||
} | ||
} | ||
} | ||
|
||
function parseLink(link){ | ||
|
||
var url = stripQueryString(link); | ||
|
||
if(checkType(url)){ | ||
addOfficeLink(link); | ||
} | ||
|
||
} | ||
|
||
function checkType(str){ | ||
for(var i=0; i<fileTypes.length; i++){ | ||
if(endsWith(str, '.'+fileTypes[i])) | ||
return true; | ||
} | ||
return false; | ||
} | ||
//word => http://i.imgur.com/Wce14X6.png | ||
//powerpoint => http://i.imgur.com/iQn5mKp.png | ||
// excel => http://i.imgur.com/xPTt5d6.png | ||
function addOfficeLink(link){ | ||
var officeLink = document.createElement('a'); | ||
officeLink.href = strViewOfficeUrl + encodeURI(stripQueryString(link)); | ||
officeLink.isParsed=true; | ||
officeLink.target="_blank"; | ||
|
||
var ico = document.createElement("img"); | ||
|
||
if(endsWith(officeLink.href, ".doc")||endsWith(officeLink.href, ".docx")) | ||
ico.src = "http://i.imgur.com/Wce14X6.png"; | ||
else if(endsWith(officeLink.href, ".xls")|| endsWith(officeLink.href, ".xlsx")) | ||
ico.src = "http://i.imgur.com/xPTt5d6.png"; | ||
else | ||
ico.src = "http://i.imgur.com/iQn5mKp.png"; | ||
|
||
|
||
ico.style.marginLeft = "5px"; | ||
officeLink.appendChild(ico); | ||
link.parentNode.insertBefore(officeLink, link.nextSibling); | ||
|
||
} | ||
|
||
function addDebouncedEventListener(obj, eventType, listener, delay) { | ||
var timer; | ||
|
||
obj.addEventListener(eventType, function(evt) { | ||
if (timer) { | ||
window.clearTimeout(timer); | ||
} | ||
timer = window.setTimeout(function() { | ||
timer = null; | ||
listener.call(obj, evt); | ||
}, delay); | ||
}, false); | ||
} |