Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 3 additions & 47 deletions background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,13 @@ async function isConnected(details) {
console.log("Connected url pattern detected, checking...");
var auth_data = await utils.checkSession(details);
if (auth_data.is_connected) {
await browser.tabs.update(auth_data.tab.id, {"active": true, "url": "../"+co.CONNECTED_LOCAL_PAGE});
await chrome.tabs.update(auth_data.tab.id, {"active": true, "url": chrome.runtime.getURL(co.CONNECTED_LOCAL_PAGE)});
};
}

async function customizeLogin(details) {
console.log("Form detected, customizing Google login...");
let filter = browser.webRequest.filterResponseData(details.requestId);
let decoder = new TextDecoder("utf-8");
let encoder = new TextEncoder();

let data = [];
filter.ondata = event => {
data.push(event.data);
};

filter.onstop = event => {
let str = "";
for (let buffer of data) {
str += decoder.decode(buffer, {stream: true});
}
str += decoder.decode(); // end-of-stream

// Injecting cool things
try {
let logo_match = /<div id=\"logo\".*?<svg .*?<\/svg><\/div><\/div>/i.exec(str)[0];
let parser = new DOMParser();
let node = parser.parseFromString(logo_match, 'text/html');
node.getElementById("logo").getElementsByTagName("svg")[0].parentElement.innerHTML = "<img src=\"https://files.catbox.moe/171jq5.png\" style=\"width: 70px; margin-top: -10px;\">";
let new_substr = node.documentElement.innerHTML;
str = str.replace(logo_match, new_substr);

let sub_match = /id=\"headingSubtext\".*?<span .*?>Use your Google Account<\/span>/i.exec(str)[0];
str = str.replace(sub_match, sub_match.replace("Use your Google Account", "🦖 Connect your Google Account"));
} catch (error) {
console.log("GHunt error while customizing login :", error);
};

filter.write(encoder.encode(str));
filter.close();
};
};

// Registering listeners

browser.webRequest.onBeforeRequest.addListener(
customizeLogin,
{urls: [co.LOGIN_FORM_URL, co.MULTI_LOGIN_FORM_URL], types: ["main_frame"]},
["blocking"]
);

browser.webRequest.onCompleted.addListener(
chrome.webRequest.onCompleted.addListener(
isConnected,
{urls: [co.CONNECTED_URL_PATTERN]}
);
);
8 changes: 4 additions & 4 deletions ghunt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import * as co from "./lib/constants.js"

(function() {
async function main() {
var tabs = await browser.tabs.query({"url": co.CONNECTED_URL_PATTERN})
var tabs = await chrome.tabs.query({"url": co.CONNECTED_URL_PATTERN})
if (tabs.length > 0) {
var target_tab = tabs[0];
await browser.tabs.update(target_tab.id, {"active": true, "url": co.START_LOGIN_URL})
await chrome.tabs.update(target_tab.id, {"active": true, "url": co.START_LOGIN_URL})
} else {
await browser.tabs.create({
await chrome.tabs.create({
"url": co.START_LOGIN_URL
});
}
Expand All @@ -20,4 +20,4 @@ import * as co from "./lib/constants.js"
};
});

}());
}());
20 changes: 10 additions & 10 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import * as co from "../lib/constants.js"


async function main(choice) {
var current_tab = await browser.tabs.getCurrent();
var current_tab = await chrome.tabs.getCurrent();
if (choice == "close") {
await browser.tabs.remove(current_tab.id);
await chrome.tabs.remove(current_tab.id);
}

var status_label = document.getElementsByClassName("status_text")[0];

var storage = await browser.storage.local.get("ghunt");
var storage = await chrome.storage.local.get("ghunt");
if ("ghunt" in storage && storage.ghunt.ready) {
var encoded_cookies = utils.encodeCookies(storage.ghunt.cookies);
var finished = false;
Expand All @@ -24,7 +24,7 @@ async function main(choice) {
} else {
status_label.innerHTML = "Can't contact GHunt on 127.0.0.1:60067 ...";
};

} else if (choice == "base64") {
await navigator.clipboard.writeText(encoded_cookies).then(function() {
finished = true;
Expand All @@ -35,7 +35,7 @@ async function main(choice) {
};

if (finished) {
await browser.storage.local.remove("ghunt");
await chrome.storage.local.remove("ghunt");
console.log("Terminating, I removed stored data !");

var table = document.getElementById("methods_list");
Expand All @@ -44,15 +44,15 @@ async function main(choice) {

} else {
status_label.innerHTML = "Please log in into your Google account.";
var tabs = await browser.tabs.query({"url": co.CONNECTED_URL_PATTERN})
var tabs = await chrome.tabs.query({"url": co.CONNECTED_URL_PATTERN})
if (tabs.length > 0) {
var target_tab = tabs[0];
await browser.tabs.update(target_tab.id, {"active": true, "url": co.START_LOGIN_URL})
await chrome.tabs.update(target_tab.id, {"active": true, "url": co.START_LOGIN_URL})
} else {
await browser.tabs.create({
await chrome.tabs.create({
"url": co.START_LOGIN_URL
});
await browser.tabs.remove(current_tab.id);
await chrome.tabs.remove(current_tab.id);
}
}
}
Expand All @@ -65,4 +65,4 @@ document.addEventListener("click", function(e) {
} else if (e.target.id == "method_close") {
main("close");
}
});
});
8 changes: 4 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ export function encodeCookies(cookies) {

export async function checkSession(details) {
console.log("Got details :", details);

if (!details) {
console.log("No details provided to checkSession, aborting.");
return {"is_connected": false};
};

var target_tab = await browser.tabs.get(details.tabId);
var target_tab = await chrome.tabs.get(details.tabId);
console.log("Got tab :", target_tab);
if (!target_tab) {
console.log("No tab found with connected url pattern, aborting checkSession.");
return {"is_connected": false};
}

var raw_cookies = await browser.cookies.getAll({"domain":"google.com", "storeId": details.cookieStoreId});
var raw_cookies = await chrome.cookies.getAll({"domain":"google.com"});

var wanted = ["SID", "SSID", "APISID", "SAPISID", "HSID", "LSID", "__Secure-3PSID", "oauth_token"];

Expand All @@ -66,7 +66,7 @@ export async function checkSession(details) {

if (Object.keys(ghunt_cookies).length >= wanted.length) {
console.log("Connected ! Putting data in storage...");
await browser.storage.local.set({"ghunt": {
await chrome.storage.local.set({"ghunt": {
"cookies": ghunt_cookies,
"ready": true
}});
Expand Down
48 changes: 23 additions & 25 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
{

"manifest_version": 2,
"manifest_version": 3,
"name": "GHunt Companion",
"version": "2.0.0",
"version": "3.0.0",

"description": "Load all needed cookies to use GHunt peacefully.",

"icons": {
"48": "assets/ghunt_square.png"
"48": "assets/ghunt_square.png"
},

"permissions": [
"webRequest",
"webRequestBlocking",
"*://*.google.com/*",
"storage",
"cookies"
"webRequest",
"storage",
"cookies"
],

"content_scripts": [
{
"js": ["lib/browser-polyfill.min.js"],
"matches": ["*://*.google.com/*"]
}

"host_permissions": [
"*://*.google.com/*"
],

"background": {
"page": "background/background.html"
"service_worker": "background/background.js",
"type": "module"
},

"web_accessible_resources": [
"popup/interface.html"
{
"resources": ["pages/connected.html"],
"matches": ["*://*.google.com/*"]
}
],

"browser_action": {
"default_icon": "assets/ghunt_square.png",
"default_title": "GHunt Companion",
"default_popup": "popup/interface.html"
"action": {
"default_icon": "assets/ghunt_square.png",
"default_title": "GHunt Companion",
"default_popup": "popup/interface.html"
}

}
}
3 changes: 0 additions & 3 deletions pages/connected.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,300;0,400;0,500;0,700;0,900;1,300;1,400&display=swap" rel="stylesheet">
<link href="../assets/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<link rel="stylesheet" href="connected.css">
<script src="../lib/browser-polyfill.min.js"></script>
<script type="module" src="../lib/constants.js"></script>
<script type="module" src="../lib/utils.js"></script>
<script type="module" src="../lib/sync.js"></script>
</header>

Expand Down
3 changes: 0 additions & 3 deletions popup/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
<meta charset="UTF-8">
<html>
<header>
<script src="../lib/browser-polyfill.min.js"></script>
<script type="module" src="../lib/constants.js"></script>
<script type="module" src="../lib/utils.js"></script>
<script type="module" src="../ghunt.js"></script>

<link href="../assets/bootstrap.min.css" rel="stylesheet" integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
Expand Down