From 1252691a3577fbb4d7a8be1d8b6ac1b6d277c3c6 Mon Sep 17 00:00:00 2001 From: Ruud Steltenpool Date: Fri, 6 May 2016 23:52:57 +0200 Subject: [PATCH] Added files via upload --- background.js | 79 ++++++++++++++++++++++++++++++++++++++------------- manifest.json | 30 ++++--------------- 2 files changed, 66 insertions(+), 43 deletions(-) diff --git a/background.js b/background.js index d2f46dc..dc1b33e 100644 --- a/background.js +++ b/background.js @@ -1,20 +1,61 @@ chrome.webRequest.onHeadersReceived.addListener(function(details) { - function isContentType(element) { - // , index, array - return element.name.toLowerCase()==='content-type' - } - function isContentDisposition(element) { - // , index, array - return element.name.toLowerCase()==='content-disposition' - } - var headers = details.responseHeaders - var webContentTypes=["text/html","text/plain","application/javascript","application/json","application/xml","text/xml","image/svg+xml","font/opentype","text/csv","text/tsv"] - console.log("your Chrome extension IS running") - - if (webContentTypes.includes(headers.find(isContentType).value)){ - var indexCD=headers.findIndex(isContentDisposition) - if (indexCD!==-1) headers[indexCD].value='inline' - } - -return {responseHeaders:headers}; -}, {urls: ['https://*.something.nl/*']}, ["blocking","responseHeaders"]); + var return_value, response_headers, get_header_value, target_content_types, hv_content_type, hv_content_disposition; + var debug_enabled, debug; + + debug_enabled = false; + debug = function(msg){ + if (debug_enabled){ + console.log('[onHeadersReceived]: ' + msg); + } + }; + + debug('entered..'); + + return_value = {}; + response_headers = details.responseHeaders; + + get_header_value = function(header_name){ + var is_header, header_obj, header_value, header_index; + + is_header = function(header, index){ + var is_match = (header.name.toLowerCase() === header_name); + if (is_match){header_index = index;} + return is_match; + }; + + header_name = header_name.toLowerCase(); + header_index = -1; + if (typeof Array.prototype.find === 'function'){ + header_obj = response_headers.find(is_header); + } + else { + header_obj = response_headers.filter(is_header); + header_obj = (header_obj.length === 0)? undefined : header_obj[0]; + } + header_value = (typeof header_obj === 'undefined')? '' : header_obj.value.toLowerCase(); + + return [header_value, header_index]; + }; + + target_content_types = ["text/html","text/plain","text/xml","text/csv","text/tsv","text/javascript","application/javascript","application/json","application/xml","image/svg+xml","font/opentype"]; + hv_content_type = get_header_value('content-type'); + debug('content-type = ' + hv_content_type[0]); + + if (target_content_types.indexOf(hv_content_type[0]) !== -1){ + // response matches a target content-type + debug('content-type is a match'); + + hv_content_disposition = get_header_value('content-disposition'); + if (hv_content_disposition[1] !== -1){ + debug('content-disposition = ' + hv_content_disposition[0]); + + // response_headers[hv_content_disposition[1]]['value'] = 'inline'; + response_headers.splice(hv_content_disposition[1], 1); + return_value.responseHeaders = response_headers; + + debug('response_headers = ' + JSON.stringify(response_headers)); + } + } + + return return_value; +}, {"urls": ["*://something.nl/*", "*://*.something.nl/*"]}, ["blocking", "responseHeaders"]); \ No newline at end of file diff --git a/manifest.json b/manifest.json index 3c21f51..4b1782e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,33 +1,15 @@ { "manifest_version": 2, - "name": "open web files in browser", - "version": "0.20162502.1705", - "default_locale": "en", - "description": "Where web applications force to save files locally, it is ignored for certain file types per domain", - "browser_action": { - "default_icon": { - "19": "browserbar_19x19.png", - "38": "icon38.jpg" - }, - "default_title": "link verder", - "default_popup": "popup.html" - }, - "icons": { "16": "contextMenu_16x16.png", - "48": "extensionList_48x48.jpg", - "128": "details_128x128.png" - }, - "author":"steltenpower", - "homepage_url": "http://path/to/homepage", + "name": "Something.nl website fix", + "version": "1", + "description": "Something - open particular file types in browser instead of displaying a 'save as' dialog", "background": { "scripts": ["background.js"] }, "permissions": [ "webRequest", "webRequestBlocking", - "https://*.something.nl/*" - ], - "options_ui": { - "page": "options.html", - "chrome_style": true - } + "*://something.nl/*", + "*://*.something.nl/*" + ] } \ No newline at end of file