Skip to content

Commit

Permalink
Merge pull request #43 from xoFeulB/v0.5
Browse files Browse the repository at this point in the history
V0.5
  • Loading branch information
HeyHamachi authored Mar 27, 2024
2 parents 0fe659f + 2359801 commit 04edaf4
Show file tree
Hide file tree
Showing 15 changed files with 981 additions and 1,340 deletions.
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.formatOnSave": true,
"editor.tabSize": 2,
"html.format.wrapLineLength": 0,
"editor.detectIndentation": false,
}
212 changes: 14 additions & 198 deletions background/js/background.js
Original file line number Diff line number Diff line change
@@ -1,204 +1,20 @@
// © BlueFoxEnterprise
// https://github.com/xoFeulB

{
(async () => {
let log = console.log;

let R = {
pageInfo: {},
event_observer: {},
debugger: {},
};

let actions = {
"Debugger.attach": async (o, sender) => {
await chrome.debugger.attach({ tabId: sender.tab.id }, "1.3");
log("Debugger Attached", sender);
R.debugger[sender.tab.id] = sender;
return sender.tab.id;
},
"Debugger.detach": async (o, sender) => {
chrome.debugger.detach({ tabId: sender.tab.id });
log("Debugger Detached", sender);
return sender.tab.id;
},
"Debugger.isOnline": async (o, sender) => {
if (sender.tab.id in R.debugger) {
return true;
}
return false;
},
"Page.captureScreenshot": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"Page.captureScreenshot",
o
);
return result.data;
},
"DOMDebugger.getEventListeners": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"DOMDebugger.getEventListeners",
o
);
return result;
},
"Runtime.enable": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"Runtime.compileScript",
o
);
return result;
},
"Runtime.compileScript": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"Runtime.compileScript",
o
);
return result;
},
"Runtime.evaluate": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"Runtime.evaluate",
o
);
return result;
},
"Runtime.runScript ": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"Runtime.runScript",
o
);
return result;
},
"DOM.resolveNode": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"DOM.resolveNode",
o
);
return result;
},
"DOM.getOuterHTML": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"DOM.getOuterHTML",
o
);
return result;
},
"DOM.querySelectorAll": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"DOM.querySelectorAll",
o
);
return result;
},
"DOMSnapshot.captureSnapshot": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"DOMSnapshot.captureSnapshot",
o
);
return result;
},
"DOM.getDocument": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"DOM.getDocument",
o
);
return result;
},
"BlueFox.storeEvent": async (o, sender) => {
R.event_observer[sender.tab.id].push({
url: sender.tab.url,
title: sender.tab.title,
action: o,
});
},
"Input.dispatchKeyEvent": async (o, sender) => {
let result = await chrome.debugger.sendCommand(
chrome.runtime.onMessage.addListener(
(message, sender, sendResponse) => {
(async () => {
try {
let R = await chrome.debugger.sendCommand(
{ tabId: sender.tab.id },
"Input.dispatchKeyEvent",
o
message.type,
message.object
);
return result;
},
"Tab.getCurrent": async (o, sender) => {
let result = sender.tab;
return result;
},
"Tab.createWindow": async (o, sender) => {
let result = await chrome.windows.create(o);
return result;
},
"Tab.removeWindow": async (o, sender) => {
let result = await chrome.windows.remove(o);
return result;
},
};

chrome.runtime.onMessage.addListener(
(message, sender, sendResponse) => {
if (message.type in actions) {
(async () => {
try {
let R = await actions[message.type](message.object, sender);
sendResponse(R);
} catch (e) {
sendResponse(e);
}
})();
return true;
} else {
return false;
}
sendResponse(R);
} catch (e) {
sendResponse(e);
}
);

chrome.tabs.onRemoved.addListener((tabId) => {
delete R.event_observer[tabId];
delete R.pageInfo[tabId];
delete R.debugger[tabId];
});

chrome.tabs.onUpdated.addListener(async (tabId) => {
try {
R.event_observer[tabId] = [];
let dom_snapshot = await chrome.debugger.sendCommand(
{ tabId: tabId },
"DOMSnapshot.captureSnapshot",
{
computedStyles: [],
}
);
let strings = dom_snapshot.documents[0].nodes.nodeValue
.filter((_) => {
return _ != -1 && dom_snapshot.strings[_].trim();
})
.map((_) => {
return dom_snapshot.strings[_].trim();
});

R.pageInfo[tabId] = {
title: R.debugger[tabId].tab.title,
url: R.debugger[tabId].tab.url,
strings: strings,
};
} catch { }
});

chrome.tabs.onCreated.addListener((tab) => {
R.pageInfo[tab.id] = {};
});

})();
}
})();
return true;
}
);
23 changes: 0 additions & 23 deletions content/js/document_idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,5 @@

{
(async () => {
/* BlueFoxServer */ {
if (
[
window.location.host == "localhost.bluefox.ooo:7777",
window.location.href == "https://ooo.bluefox.ooo/BlueFox/info/index.json",
].some((_) => { return _; })
) {
let R = await chrome.runtime.sendMessage({
type: "Tab.getCurrent",
object: null
});
await chrome.runtime.sendMessage({
type: "Tab.createWindow",
object: {
url: `chrome-extension://${chrome.runtime.id}/tab/html/index.html`,
}
});
await chrome.runtime.sendMessage({
type: "Tab.removeWindow",
object: R.windowId
});
}
}
})();
}
Loading

0 comments on commit 04edaf4

Please sign in to comment.