diff --git a/chrome-addon/src/content.js b/chrome-addon/src/content.js new file mode 100644 index 0000000..2408638 --- /dev/null +++ b/chrome-addon/src/content.js @@ -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 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); +} diff --git a/chrome-addon/src/icons/128x128.png b/chrome-addon/src/icons/128x128.png new file mode 100644 index 0000000..01262c3 Binary files /dev/null and b/chrome-addon/src/icons/128x128.png differ diff --git a/chrome-addon/src/icons/16x16.png b/chrome-addon/src/icons/16x16.png new file mode 100644 index 0000000..2dcee0b Binary files /dev/null and b/chrome-addon/src/icons/16x16.png differ diff --git a/chrome-addon/src/icons/48x48.png b/chrome-addon/src/icons/48x48.png new file mode 100644 index 0000000..17e03c6 Binary files /dev/null and b/chrome-addon/src/icons/48x48.png differ diff --git a/chrome-addon/src/manifest.json b/chrome-addon/src/manifest.json new file mode 100644 index 0000000..602eb63 --- /dev/null +++ b/chrome-addon/src/manifest.json @@ -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"] + } + ] +} \ No newline at end of file diff --git a/ff-addon/coming soon b/ff-addon/coming soon new file mode 100644 index 0000000..e69de29 diff --git a/userscript/OfficeOnlineViewer.user.js b/userscript/OfficeOnlineViewer.user.js new file mode 100644 index 0000000..2408638 --- /dev/null +++ b/userscript/OfficeOnlineViewer.user.js @@ -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 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); +}