Assign first popup on the search page as a depth of 1

This commit is contained in:
toasted-nutbread 2019-10-15 20:23:25 -04:00
parent 099909287f
commit 16521fec93
4 changed files with 11 additions and 8 deletions

View File

@ -25,6 +25,8 @@ async function searchFrontendSetup() {
const options = await apiOptionsGet(optionsContext);
if (!options.scanning.enableOnSearchPage) { return; }
window.frontendInitializationData = {depth: 1, proxy: false};
const scriptSrcs = [
'/fg/js/frontend-api-receiver.js',
'/fg/js/popup.js',

View File

@ -49,11 +49,10 @@ class Frontend {
}
static create() {
const initializationData = window.frontendInitializationData;
const isNested = (initializationData !== null && typeof initializationData === 'object');
const {id, depth, parentFrameId, ignoreNodes, url} = isNested ? initializationData : {};
const data = window.frontendInitializationData || {};
const {id, depth=0, parentFrameId, ignoreNodes, url, proxy=false} = data;
const popup = isNested ? new PopupProxy(depth + 1, id, parentFrameId, url) : PopupProxyHost.instance.createPopup(null);
const popup = proxy ? new PopupProxy(depth + 1, id, parentFrameId, url) : PopupProxyHost.instance.createPopup(null, depth);
const frontend = new Frontend(popup, ignoreNodes);
frontend.prepare();
return frontend;

View File

@ -35,7 +35,7 @@ async function popupNestedInitialize(id, depth, parentFrameId, url) {
const ignoreNodes = options.scanning.enableOnPopupExpressions ? [] : [ '.expression', '.expression *' ];
window.frontendInitializationData = {id, depth, parentFrameId, ignoreNodes, url};
window.frontendInitializationData = {id, depth, parentFrameId, ignoreNodes, url, proxy: true};
const scriptSrcs = [
'/fg/js/frontend-api-sender.js',

View File

@ -50,10 +50,12 @@ class PopupProxyHost {
});
}
createPopup(parentId) {
createPopup(parentId, depth) {
const parent = (typeof parentId === 'string' && this.popups.hasOwnProperty(parentId) ? this.popups[parentId] : null);
const depth = (parent !== null ? parent.depth + 1 : 0);
const id = `${this.nextId}`;
if (parent !== null) {
depth = parent.depth + 1;
}
++this.nextId;
const popup = new Popup(id, depth, this.frameIdPromise);
if (parent !== null) {
@ -65,7 +67,7 @@ class PopupProxyHost {
}
async createNestedPopup(parentId) {
return this.createPopup(parentId).id;
return this.createPopup(parentId, 0).id;
}
getPopup(id) {