forked from Manojkh/ConVista-CPI-Helper-Chrome-Extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
42 lines (35 loc) · 1.41 KB
/
background.js
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
//GNU GPL v3
//Please visit our github page: https://github.com/dbeck121/ConVista-CPI-Helper-Chrome-Extension
'use strict';
//activate on this site
chrome.runtime.onInstalled.addListener(function () {
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
chrome.declarativeContent.onPageChanged.addRules([{
conditions: [new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlMatches: '.*?hana\.ondemand\.com\/itspaces\/.*?' },
})],
actions: [new chrome.declarativeContent.ShowPageAction()]
}]);
});
});
//scan Headers for X-CSRF Token
chrome.webRequest.onBeforeSendHeaders.addListener(
function (details) {
for (var i = 0; i < details.requestHeaders.length; ++i) {
if (details.requestHeaders[i].name == "X-CSRF-Token") {
var xcsrftoken = details.requestHeaders[i].value;
var tenant = details.url.split("/")[2].split(".")[0];
//xcsrf token will be saved in a local object with name xcsrf_<tenant>
var name = 'xcsrf_' + tenant;
var obj = {};
obj[name] = xcsrftoken;
chrome.storage.local.set(obj, function () {
console.log("xcsrf token saved");
});
break;
}
}
return { requestHeaders: details.requestHeaders };
},
{ urls: ["https://*.hana.ondemand.com/itspaces/api/1.0/workspace*/artifacts/*/iflows/*?lockinfo=true&webdav=LOCK"] },
["requestHeaders"]);