Skip to content

Commit

Permalink
fix: switch to interactive mode when a captcha appears, fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
neopostmodern committed Aug 7, 2020
1 parent 31c1249 commit c78ec6b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 50 deletions.
8 changes: 8 additions & 0 deletions app/actions/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
SET_BROWSER_VIEW_READY,
SET_BROWSER_VIEW_URL,
SET_BROWSER_WINDOW,
SET_INTERACTIVE_MODE,
SHOW_CONFIGURATION,
SHOW_DEV_TOOLS,
OPEN_PDF
Expand Down Expand Up @@ -94,6 +95,13 @@ export function showConfiguration(): Action {
};
}

export function setInteractiveMode(interactiveModeEnabled: boolean): Action {
return {
type: SET_INTERACTIVE_MODE,
payload: interactiveModeEnabled
}
}

export function performScroll(name: BrowserViewName, deltaY: number): Action {
return {
type: PERFORM_SCROLL,
Expand Down
20 changes: 10 additions & 10 deletions app/components/BotOverlay.scss
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
bottom: 0;
}

$bot-illustration-offset-right: 10vh;
$bot-illustration-width: 15vh;
$bot-illustration-offset-right: 10vmax;
$bot-illustration-width: 15vmax;
.botIllustration {
position: absolute;
bottom: -2px;
Expand All @@ -39,29 +39,29 @@ $bot-illustration-width: 15vh;
}

$speech-bubble-color: $BOT_LIGHT;
$speech-bubble-anchor-width: 4vh;
$speech-bubble-anchor-width: 4vmax;
.speechBubble {
position: absolute;
right: $bot-illustration-offset-right + $bot-illustration-width +
$speech-bubble-anchor-width - 1vh;
bottom: 3vh;
$speech-bubble-anchor-width - 1vmax;
bottom: 3vmax;
background-color: $speech-bubble-color;
color: #333;
font-size: calc(20px + 1vh);
font-size: calc(20px + 1vmax);
padding: 0.5em 0.7em 0.4em;
margin-left: 0.5em;
}
.speechBubble::after {
content: '';
position: absolute;
right: 0;
bottom: 1vh;
bottom: 1vmax;
width: 0;
height: 0;
border: 0 solid transparent;
border-top-width: 2vh;
border-left: 4vh $speech-bubble-color solid;
margin-right: -4vh;
border-top-width: 2vmax;
border-left: 4vmax $speech-bubble-color solid;
margin-right: -4vmax;
}

.animations {
Expand Down
1 change: 1 addition & 0 deletions app/constants/actionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const ELECTRON_ROUTING = 'ELECTRON_ROUTING';
export const INTERNAL_ADD_BROWSER_VIEW = 'INTERNAL_ADD_BROWSER_VIEW';
export const HIDE_CONFIGURATION = 'HIDE_CONFIGURATION';
export const SHOW_CONFIGURATION = 'SHOW_CONFIGURATION';
export const SET_INTERACTIVE_MODE = 'SET_INTERACTIVE_MODE';
export const PERFORM_SCROLL = 'PERFORM_SCROLL';
export const SHOW_DEV_TOOLS = 'SHOW_DEV_TOOLS';
export const OPEN_PDF = 'OPEN_PDF';
Expand Down
92 changes: 58 additions & 34 deletions app/middleware/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,81 @@ import { calculateOverviewBoundingBoxes } from '../actions/overlay';
import { getFlatData, getOverviewData, refreshVerdicts } from '../actions/data';
import { FLAT_ACTION } from '../reducers/data';
import { sendFlatViewingNotificationMail } from '../actions/email';
import { launchNextTask, queueInvestigateFlat } from '../actions/bot';
import { launchNextTask, queueInvestigateFlat, setBotMessage } from '../actions/bot';
import { setInteractiveMode } from '../actions/electron';
import {
discardApplicationProcess,
endApplicationProcess,
generateApplicationTextAndSubmit
} from '../actions/application';
import AbortionSystem, { ABORTION_MANUAL } from '../utils/abortionSystem';
import ElectronUtils from '../utils/electronUtils';

export default (store: Store) => (next: (action: Action) => void) => async (
action: Action
) => {
const handlePuppetReady = async () => {
await sleep(5000);

const { puppet } = store.getState().electron.views;

puppet.browserView.webContents.insertCSS(`
#cmp-faktor-io-brand-consent-notice {
display: none !important;
}
`);

const electronUtils = new ElectronUtils(puppet.browserView.webContents);
if ((await electronUtils.evaluate('document.title')).includes('Ich bin kein Roboter')) {
store.dispatch(setBotMessage('Mensch! Du bist dran.'));

if (!puppet.browserView.webContents.isFocused()) {
puppet.browserView.webContents.focus();
}
store.dispatch(setInteractiveMode(true));

while ((await electronUtils.evaluate('document.title')).includes('Ich bin kein Roboter')) {
await sleep(1000);
}
store.dispatch(setBotMessage('Geschafft, ich übernehme wieder!'));
store.dispatch(setInteractiveMode(false));

await sleep(5000);
await handlePuppetReady();
return;
}

if (puppet.url.startsWith('https://www.immobilienscout24.de/Suche')) {
setImmediate(() => store.dispatch(calculateOverviewBoundingBoxes()));
setTimeout(
() => store.dispatch(calculateOverviewBoundingBoxes()),
1000
);
setTimeout(
() => store.dispatch(calculateOverviewBoundingBoxes()),
5000
);

await store.dispatch(getOverviewData());
await store.dispatch(refreshVerdicts());
await sleep(20000);
store.dispatch(launchNextTask());
}

if (puppet.url.startsWith('https://www.immobilienscout24.de/expose/')) {
await store.dispatch(getFlatData());
store.dispatch(refreshVerdicts());
}
}

if (action.type === RESET_BOT) {
AbortionSystem.abort(ABORTION_MANUAL);
store.dispatch(endApplicationProcess());
}

if (action.type === SET_BROWSER_VIEW_READY) {
if (action.payload.name === 'puppet' && action.payload.ready) {
setImmediate(async () => {
await sleep(5000);

const { puppet } = store.getState().electron.views;

puppet.browserView.webContents.insertCSS(`
#cmp-faktor-io-brand-consent-notice {
display: none !important;
}
`);

if (puppet.url.startsWith('https://www.immobilienscout24.de/Suche')) {
setImmediate(() => store.dispatch(calculateOverviewBoundingBoxes()));
setTimeout(
() => store.dispatch(calculateOverviewBoundingBoxes()),
1000
);
setTimeout(
() => store.dispatch(calculateOverviewBoundingBoxes()),
5000
);

await store.dispatch(getOverviewData());
await store.dispatch(refreshVerdicts());
await sleep(20000);
store.dispatch(launchNextTask());
}

if (puppet.url.startsWith('https://www.immobilienscout24.de/expose/')) {
await store.dispatch(getFlatData());
store.dispatch(refreshVerdicts());
}
});
setImmediate(handlePuppetReady);
}
}

Expand Down
5 changes: 5 additions & 0 deletions app/middleware/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PERFORM_SCROLL,
SCROLL_WHILE_IDLE,
SET_BROWSER_WINDOW,
SET_INTERACTIVE_MODE,
SHOW_CONFIGURATION,
SHOW_DEV_TOOLS,
STOP_SCROLLING_WHILE_IDLE
Expand Down Expand Up @@ -114,6 +115,10 @@ export default (store: Store) => (next: (action: Action) => void) => async (
}
}

if (action.type === SET_INTERACTIVE_MODE) {
setImmediate(() => resizeViews(store.getState().electron));
}

if (action.type === PERFORM_SCROLL) {
const electronUtils = new ElectronUtils(
store.getState().electron.views[
Expand Down
12 changes: 9 additions & 3 deletions app/reducers/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
INTERNAL_ADD_BROWSER_VIEW,
SET_BROWSER_VIEW_READY,
SET_BROWSER_VIEW_URL,
SET_BROWSER_WINDOW
SET_BROWSER_WINDOW,
SET_INTERACTIVE_MODE
} from '../constants/actionTypes';
import type { Action } from './types';

Expand All @@ -28,13 +29,15 @@ export type Views = {
export type electronStateType = {
window: ?BrowserWindow,
views: Views,
configurationHidden: boolean
configurationHidden: boolean,
interactiveMode: boolean
};

const electronDefaultState: electronStateType = {
views: {},
window: null,
configurationHidden: false
configurationHidden: false,
interactiveMode: false
};

export default function electron(
Expand All @@ -59,6 +62,9 @@ export default function electron(
if (action.type === HIDE_CONFIGURATION) {
return { ...state, configurationHidden: true };
}
if (action.type === SET_INTERACTIVE_MODE) {
return { ...state, interactiveMode: action.payload }
}

return state;
}
10 changes: 7 additions & 3 deletions app/utils/resizeViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export default function resizeViews(
) {
const {
window,
views: { puppet, sidebar, botOverlay, configuration, devMenu }
views: { puppet, sidebar, botOverlay, configuration, devMenu },
interactiveMode
} = electronState;
if (window === undefined || window === null) {
// eslint-disable-next-line no-console
Expand All @@ -30,12 +31,15 @@ export default function resizeViews(
width: windowWidth - sideBarWidth, // - 20, // by not subtracting the offset we push the scrollbar out of view
height: windowHeight - 20
});

const botOverlayHeightInManualMode = 150;
botOverlay.browserView.setBounds({
x: sideBarWidth,
y: 0,
y: interactiveMode ? windowHeight - botOverlayHeightInManualMode : 0,
width: windowWidth - sideBarWidth,
height: windowHeight
height: interactiveMode ? botOverlayHeightInManualMode : windowHeight
});

let configurationY = electronState.configurationHidden ? windowHeight : 0;
if (
configurationVisibility !== undefined &&
Expand Down

0 comments on commit c78ec6b

Please sign in to comment.