Skip to content

Commit 4d78cf3

Browse files
committed
Merge branch 'ajustes-avaliacao' into develop
2 parents f1d7db2 + d070328 commit 4d78cf3

30 files changed

+738
-304
lines changed

manifest.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
}
1919
],
2020
"browser_action": {
21-
"default_icon": "/assets/icon.png"
21+
"default_icon": "/assets/icon.png",
22+
"default_popup": "popup.html"
2223
},
23-
"permissions": ["webRequest", "tabs", "<all_urls>"],
24+
"permissions": ["webRequest", "tabs", "<all_urls>", "declarativeContent", "storage", "activeTab", "scripting"],
2425
"web_accessible_resources": ["node_modules/hacktimer/HackTimer.min.js"]
26+
2527
}

popup.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" href="button.css">
5+
</head>
6+
<body>
7+
<div>
8+
<input id="start" type="button" data-status="0" value="Start"></input><br><br>
9+
10+
<label for="language">Language:</label>
11+
<select type="text" id="language" name="language">
12+
<option value="pt">PT</option>
13+
<option value="en">EN</option>
14+
</select><br><br>
15+
16+
<label for="time-between-interactions">Time Between Interactions(ms):</label>
17+
<input type="text" id="time-between-interactions" name="time-between-interactions"><br>
18+
19+
<label for="variant-limit">Variant Limit:</label>
20+
<input type="text" id="variant-limit" name="variant-limit"><br>
21+
22+
<label for="min-child-node-diff">Min Child Nodes Diff:</label>
23+
<input type="text" id="min-child-node-diff" name="min-child-node-diff"><br>
24+
25+
<!-- <label for="html-tags-for-diff">HTML Tags for Diff:</label>
26+
<input type="text" id="html-tags-for-diff" name="html-tags-for-diff"><br> -->
27+
28+
<label for="max-wait-time-unload">Max Wait Time for Unload (ms):</label>
29+
<input type="text" id="max-wait-time-unload" name="max-wait-time-unload"><br>
30+
31+
<label for="int-cell-tolerance-percentage">Interactable Cell Tolerance Percentage:</label>
32+
<input type="number" min="1" max="100" id="int-cell-tolerance-percentage" name="int-cell-tolerance-percentage"><br>
33+
34+
<label for="consider-full-url">Consider full URL:</label>
35+
<textarea id="consider-full-url" name="consider-full-url"></textarea>
36+
37+
</div>
38+
<script src="dist/popup.js"></script>
39+
</body>
40+
</html>

src/background-script/background.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { CodeChangeMonitor } from './extension/CodeChangeMonitor';
77
import { InMemoryDatabase } from './extension/InMemoryDatabase';
88
import { CommunicationChannel } from '../shared/comm/CommunicationChannel';
99
import { ChromeCommunicationChannel } from '../shared/comm/ChromeCommunicationChannel';
10+
import { IndexedDBObjectStorage } from '../shared/storage/IndexedDBObjectStorage';
11+
import { getConfig } from '../content-script/util';
1012

1113
const extension: Extension = new ChromeExtension(chrome);
1214

@@ -23,10 +25,13 @@ extension.searchTab({ url: 'http://localhost/*' }).then((tabs) => {
2325

2426
const communicationChannel: CommunicationChannel = new ChromeCommunicationChannel(chrome);
2527
const inMemoryDatabase = new InMemoryDatabase();
26-
const manager: ExtensionFacade = new ExtensionFacade(
27-
extension,
28-
communicationChannel,
29-
inMemoryDatabase,
30-
4
31-
);
32-
manager.setup();
28+
getConfig(new IndexedDBObjectStorage<string>('config', 'config')).then((config) => {
29+
const manager: ExtensionFacade = new ExtensionFacade(
30+
extension,
31+
communicationChannel,
32+
inMemoryDatabase,
33+
4,
34+
config
35+
);
36+
manager.setup();
37+
});

src/background-script/extension/ElementAnalysis.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { Exclude } from "class-transformer";
12
import { ElementAnalysisStatus } from "../../content-script/crawler/ElementAnalysisStatus";
23
import { TransformURL } from "../../content-script/decorators";
3-
import { getURLWithoutQueries } from "../../content-script/util";
4+
import { getURLasString } from "../../content-script/util";
5+
import { Config } from "../../shared/config";
46

57
export class ElementAnalysis {
68
private id?: string;
@@ -13,11 +15,15 @@ export class ElementAnalysis {
1315

1416
private tabId: string;
1517

16-
constructor(pathToElement: string, pageUrl: URL, status: ElementAnalysisStatus, tabId: string) {
18+
@Exclude()
19+
private config: Config;
20+
21+
constructor(pathToElement: string, pageUrl: URL, status: ElementAnalysisStatus, tabId: string, config: Config) {
1722
this.pathToElement = pathToElement;
1823
this.pageUrl = pageUrl;
1924
this.status = status;
2025
this.tabId = tabId;
26+
this.config = config;
2127
}
2228

2329
public getPathToElement(): string {
@@ -27,7 +33,7 @@ export class ElementAnalysis {
2733
public getId(): string {
2834
if (!this.id) {
2935
const pathToElement = this.getPathToElement();
30-
const id = getURLWithoutQueries(this.pageUrl) + ':' + pathToElement;
36+
const id = getURLasString(this.pageUrl, this.config) + ':' + pathToElement;
3137
this.id = id;
3238
return id;
3339
} else {

src/background-script/extension/ExtensionFacade.ts

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { GraphStorage } from '../storage/GraphStorage';
1616
import { ElementInteractionGraph } from '../graph/ElementInteractionGraph';
1717
import { ElementInteraction } from '../../content-script/crawler/ElementInteraction';
1818
import { Graph } from '../../content-script/graph/Graph';
19-
import { getURLWithoutQueries, sleep } from '../../content-script/util';
19+
import { getURLasString, sleep } from '../../content-script/util';
2020
import { ElementAnalysisStatus } from '../../content-script/crawler/ElementAnalysisStatus';
2121
import { ElementAnalysisStorage as ElementAnalysisStorageBackground } from '../../background-script/storage/ElementAnalysisStorage';
2222
import { PageAnalysisStorage as PageAnalysisStorageBackground } from '../../background-script/storage/PageAnalysisStorage';
@@ -30,6 +30,7 @@ import { IndexedDBDatabases } from '../../shared/storage/IndexedDBDatabases';
3030
import { deleteDB } from 'idb';
3131
import { PageAnalysis } from '../../content-script/crawler/PageAnalysis';
3232
import { PageAnalysisStatus } from '../../content-script/crawler/PageAnalysisStatus';
33+
import { Config } from '../../shared/config';
3334

3435
export class ExtensionFacade {
3536
private openedTabs: Array<Tab>;
@@ -45,12 +46,14 @@ export class ExtensionFacade {
4546
private tabAjaxCalls: Map<string, string[]>;
4647
private specMutex: Mutex;
4748
private initialHost: string|null;
49+
private config: Config;
4850

4951
constructor(
5052
extension: Extension,
5153
communicationChannel: CommunicationChannel,
5254
inMemoryDatabase: InMemoryDatabase,
53-
openedTabsLimit: number
55+
openedTabsLimit: number,
56+
config: Config,
5457
) {
5558
this.openedTabs = [];
5659
this.extension = extension;
@@ -65,35 +68,14 @@ export class ExtensionFacade {
6568
this.tabAjaxCalls = new Map<string, string[]>();
6669
this.specMutex = new Mutex('spec-mutex');
6770
this.initialHost = null;
71+
this.config = config;
6872
}
6973

7074
public async setup(): Promise<void> {
7175
let _this = this;
7276
await this.deleteIDBDatabases();
73-
this.extension.setBrowserActionListener(
74-
ExtensionBrowserAction.ExtensionIconClicked,
75-
async function (tab: Tab) {
76-
if (!_this.extensionIsEnabled) {
77-
if(!tab.getURL()){
78-
throw new Error("Tab has no URL");
79-
}
80-
//@ts-ignore
81-
_this.initialHost = tab.getURL().host;
82-
_this.extensionIsEnabled = true;
83-
_this.openedTabs.push(tab);
84-
_this.tabFinished.set(tab.getId(), false);
85-
_this.openedTabsCounter++;
86-
// while(_this.tabStillHasAjaxToComplete(tab)){
87-
// await sleep(5);
88-
// }
89-
_this.sendOrderToCrawlTab(tab, true);
90-
} else {
91-
_this.extension.reload();
92-
}
93-
}
94-
);
95-
96-
this.listenToAjaxCalls();
77+
78+
//this.listenToAjaxCalls();
9779

9880
this.communicationChannel.setMessageListener(async function (
9981
message: Message,
@@ -107,8 +89,41 @@ export class ExtensionFacade {
10789
) {
10890
if (responseCallback) responseCallback(new Message([], sender.getId()));
10991
}
110-
111-
if (message.includesAction(Command.SetValueInMemoryDatabase)) {
92+
console.log(message);
93+
if (message.includesAction(Command.Start)){
94+
if (!_this.extensionIsEnabled) {
95+
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
96+
if(!tabs[0].id || !tabs[0].url){
97+
return false;
98+
}
99+
var activeTab = new Tab(tabs[0].id.toString(), new URL(tabs[0].url));
100+
if(!activeTab.getURL()){
101+
throw new Error("Tab has no URL");
102+
}
103+
//@ts-ignore
104+
_this.initialHost = activeTab.getURL().host;
105+
_this.setExtensionRunningStatus(true);
106+
_this.openedTabs.push(activeTab);
107+
_this.tabFinished.set(activeTab.getId(), false);
108+
_this.openedTabsCounter++;
109+
// while(_this.tabStillHasAjaxToComplete(tab)){
110+
// await sleep(5);
111+
// }
112+
_this.sendOrderToCrawlTab(activeTab, true);
113+
});
114+
115+
} else {
116+
_this.extension.reload();
117+
}
118+
} else if (message.includesAction(Command.GetRunningStatus)) {
119+
const data = message.getExtra();
120+
if (data) {
121+
if (responseCallback) {
122+
responseCallback(new Message([], _this.extensionIsEnabled));
123+
}
124+
}
125+
}
126+
else if (message.includesAction(Command.SetValueInMemoryDatabase)) {
112127
const data = message.getExtra();
113128
if (data) {
114129
const key = data.key;
@@ -265,7 +280,7 @@ export class ExtensionFacade {
265280
const concordiaFiles = new FeatureFileGenerator();
266281
concordiaFiles.generate(spec);
267282

268-
_this.extensionIsEnabled = false;
283+
_this.setExtensionRunningStatus(false);
269284
}
270285
} else if (message.includesAction(Command.ProcessUnload)) {
271286
_this.tabLocked.set(sender.getId(), true);
@@ -342,9 +357,9 @@ export class ExtensionFacade {
342357
Variant
343358
);
344359
const elementInteractionStorage = new ElementInteractionStorage(featureStorage, variantStorage);
345-
const elementAnalysisStorage = new ElementAnalysisStorage(communicationChannel);
360+
const elementAnalysisStorage = new ElementAnalysisStorage(communicationChannel, this.config);
346361
const graphStorage = new GraphStorage(this.inMemoryDatabase);
347-
return new ElementInteractionGraph('tab-' + id, elementInteractionStorage, elementAnalysisStorage, graphStorage);
362+
return new ElementInteractionGraph('tab-' + id, elementInteractionStorage, elementAnalysisStorage, graphStorage, this.config);
348363
}
349364

350365
private async setInteractionElementAsAnalyzed(interaction: ElementInteraction<HTMLElement>, sender: Tab): Promise<void> {
@@ -353,7 +368,8 @@ export class ExtensionFacade {
353368
interaction.getElementSelector(),
354369
interaction.getPageUrl(),
355370
ElementAnalysisStatus.Done,
356-
sender.getId()
371+
sender.getId(),
372+
this.config
357373
);
358374
const elementAnalysisStorage = new ElementAnalysisStorageBackground(this.inMemoryDatabase);
359375
await elementAnalysisStorage.set(elementAnalysis.getId(), elementAnalysis);
@@ -364,7 +380,8 @@ export class ExtensionFacade {
364380
elementPath,
365381
url,
366382
ElementAnalysisStatus.Done,
367-
sender.getId()
383+
sender.getId(),
384+
this.config
368385
);
369386
const elementAnalysisStorage = new ElementAnalysisStorageBackground(this.inMemoryDatabase);
370387
await elementAnalysisStorage.set(elementAnalysis.getId(), elementAnalysis);
@@ -376,8 +393,8 @@ export class ExtensionFacade {
376393
PageAnalysisStatus.Done,
377394
);
378395

379-
const pageAnalysisStorage = new PageAnalysisStorageBackground(this.inMemoryDatabase);
380-
await pageAnalysisStorage.set(getURLWithoutQueries(pageAnalysis.getUrl()), pageAnalysis);
396+
const pageAnalysisStorage = new PageAnalysisStorageBackground(this.inMemoryDatabase, this.config);
397+
await pageAnalysisStorage.set(getURLasString(pageAnalysis.getUrl(), this.config), pageAnalysis);
381398
}
382399

383400
public openNewTab(url: URL): void {
@@ -434,7 +451,8 @@ export class ExtensionFacade {
434451
element,
435452
url,
436453
ElementAnalysisStatus.Done,
437-
sender.getId()
454+
sender.getId(),
455+
this.config
438456
);
439457
const elementAnalysisStorage = new ElementAnalysisStorageBackground(this.inMemoryDatabase);
440458
await elementAnalysisStorage.set(analysis.getId(), analysis);
@@ -554,4 +572,10 @@ export class ExtensionFacade {
554572
}
555573
}
556574

575+
private async setExtensionRunningStatus(status : boolean){
576+
this.extensionIsEnabled = status;
577+
const runningStatusStorage = new IndexedDBObjectStorage<boolean>(IndexedDBDatabases.RunningStatus, IndexedDBDatabases.RunningStatus);
578+
runningStatusStorage.set('status', status);
579+
}
580+
557581
}

src/background-script/graph/ElementInteractionGraph.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { ElementAnalysisStatus } from "../../content-script/crawler/ElementAnaly
22
import { ElementInteraction } from "../../content-script/crawler/ElementInteraction";
33
import { Graph } from "../../content-script/graph/Graph";
44
import { ElementAnalysisStorage } from "../../content-script/storage/ElementAnalysisStorage";
5-
import { getURLWithoutQueries } from "../../content-script/util";
5+
import { getURLasString } from "../../content-script/util";
6+
import { Config } from "../../shared/config";
67
import { ObjectStorage } from "../../shared/storage/ObjectStorage";
78
import { GraphStorage } from "../storage/GraphStorage";
89

@@ -14,13 +15,15 @@ export class ElementInteractionGraph {
1415
private id: string,
1516
private elementInteractionStorage: ObjectStorage<ElementInteraction<HTMLElement>>,
1617
private elementAnalysisStorage: ElementAnalysisStorage,
17-
private graphStorage: GraphStorage
18+
private graphStorage: GraphStorage ,
19+
private config: Config,
1820
) {
1921
this.id = id;
2022
this.elementInteractionStorage = elementInteractionStorage;
2123
this.elementAnalysisStorage = elementAnalysisStorage;
2224
this.elementInteractionGraphKey = 'interactions-graph-' + this.id;
2325
this.lastInteractionKey = 'last-interaction-' + this.id;
26+
this.config = config;
2427
}
2528

2629
public async addElementInteractionToGraph(
@@ -141,8 +144,8 @@ export class ElementInteractionGraph {
141144
interaction: ElementInteraction<HTMLElement>,
142145
urlCriteria: { interactionUrl: URL; isEqual: boolean }
143146
): boolean {
144-
const interactionUrl = getURLWithoutQueries(interaction.getPageUrl());
145-
const url = getURLWithoutQueries(urlCriteria.interactionUrl);
147+
const interactionUrl = getURLasString(interaction.getPageUrl(), this.config);
148+
const url = getURLasString(urlCriteria.interactionUrl, this.config);
146149
const urlIsEqual = urlCriteria.isEqual;
147150
if (
148151
(urlIsEqual && url != interactionUrl) ||
@@ -205,7 +208,7 @@ export class ElementInteractionGraph {
205208
): Promise<boolean> {
206209
const nextInteraction = await this.getNextInteraction(interaction);
207210
if (nextInteraction) {
208-
return getURLWithoutQueries(nextInteraction.getPageUrl()) != getURLWithoutQueries(interaction.getPageUrl());
211+
return getURLasString(nextInteraction.getPageUrl(), this.config) != getURLasString(interaction.getPageUrl(), this.config);
209212
}
210213
return false;
211214
}

0 commit comments

Comments
 (0)