Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
Oguzhan Ergin committed Dec 23, 2014
1 parent 9637a8d commit a8ede08
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 0 deletions.
99 changes: 99 additions & 0 deletions chrome-addon/src/content.js
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);
}
Binary file added chrome-addon/src/icons/128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chrome-addon/src/icons/16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chrome-addon/src/icons/48x48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions chrome-addon/src/manifest.json
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 added ff-addon/coming soon
Empty file.
99 changes: 99 additions & 0 deletions userscript/OfficeOnlineViewer.user.js
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);
}

0 comments on commit a8ede08

Please sign in to comment.