96 lines
2.5 KiB
JavaScript
96 lines
2.5 KiB
JavaScript
/*
|
|
Copyright (C) 2013-2017 Grégory Soutadé
|
|
|
|
This file is part of gPass.
|
|
|
|
gPass is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
gPass is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with gPass. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
function url_block_callback(details)
|
|
{
|
|
// console.log(JSON.stringify(details));
|
|
if (details.requestBody)
|
|
{
|
|
if (details.requestBody.formData)
|
|
{
|
|
for (var key in details.requestBody.formData)
|
|
{
|
|
for(var idx in details.requestBody.formData[key])
|
|
{
|
|
value = details.requestBody.formData[key][idx];
|
|
if (value.startsWith("@@") ||
|
|
value.startsWith("@_"))
|
|
return {cancel: true};
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
// Analyse POST parameters
|
|
if (details.method == "POST" && details.requestBody.raw)
|
|
{
|
|
alert(details.requestBody.raw);
|
|
var postedString = decodeURIComponent(String.fromCharCode.apply(null,
|
|
new Uint8Array(details.requestBody.raw[0].bytes)));
|
|
if (postedString.indexOf("=@@") != -1 ||
|
|
postedString.indexOf("=@_") != -1)
|
|
return {cancel: true};
|
|
}
|
|
*/
|
|
}
|
|
|
|
return {cancel: false};
|
|
}
|
|
|
|
chrome.runtime.onMessage.addListener(
|
|
function(request, sender, sendResponse) {
|
|
|
|
if (request.type == "notification")
|
|
{
|
|
options = {
|
|
type: "basic",
|
|
title : "gPass",
|
|
message : request.options.message,
|
|
iconUrl:chrome.extension.getURL("icons/gpass_icon_64.png")
|
|
};
|
|
|
|
chrome.notifications.create("gPass", options, function(){});
|
|
|
|
window.setTimeout(function() {chrome.notifications.clear("gPass", function(){})}, 2000);
|
|
}
|
|
else if (request.type == "block_url")
|
|
{
|
|
chrome.tabs.getCurrent(function cb(tab) {
|
|
if (tab)
|
|
{
|
|
chrome.webRequest.onBeforeRequest.addListener(
|
|
url_block_callback,
|
|
{urls:[request.options.url],
|
|
"types":["main_frame"],
|
|
"tabId":tab.id,
|
|
"windowId":tab.windowId
|
|
},
|
|
["blocking", "requestBody"]);
|
|
}
|
|
else
|
|
{
|
|
chrome.webRequest.onBeforeRequest.addListener(
|
|
url_block_callback,
|
|
{urls:[request.options.url], "types":["main_frame"]},
|
|
["blocking", "requestBody"]);
|
|
}
|
|
});
|
|
}
|
|
});
|