send actions to popUps
log proxycheck returns again
This commit is contained in:
parent
69ffeefd3d
commit
53b9aeeec7
|
@ -108,6 +108,9 @@ function init() {
|
||||||
window.addEventListener('resize', onWindowResize);
|
window.addEventListener('resize', onWindowResize);
|
||||||
onWindowResize();
|
onWindowResize();
|
||||||
|
|
||||||
|
// listen ofr messages from popups
|
||||||
|
window.addEventListener('message', store.dispatch);
|
||||||
|
|
||||||
store.dispatch(initTimer());
|
store.dispatch(initTimer());
|
||||||
|
|
||||||
store.dispatch(fetchMe());
|
store.dispatch(fetchMe());
|
||||||
|
|
|
@ -150,8 +150,8 @@ function ModCanvastools() {
|
||||||
const [brcoords, selectBRCoords] = useState(keptState.brcoords);
|
const [brcoords, selectBRCoords] = useState(keptState.brcoords);
|
||||||
const [tlrcoords, selectTLRCoords] = useState(keptState.tlrcoords);
|
const [tlrcoords, selectTLRCoords] = useState(keptState.tlrcoords);
|
||||||
const [brrcoords, selectBRRCoords] = useState(keptState.brrcoords);
|
const [brrcoords, selectBRRCoords] = useState(keptState.brrcoords);
|
||||||
const [tlccoords, selectTLCCoords] = useState(keptState.tlrcoords);
|
const [tlccoords, selectTLCCoords] = useState(keptState.tlccoords);
|
||||||
const [brccoords, selectBRCCoords] = useState(keptState.brrcoords);
|
const [brccoords, selectBRCCoords] = useState(keptState.brccoords);
|
||||||
const [resp, setResp] = useState(null);
|
const [resp, setResp] = useState(null);
|
||||||
const [cleanerstats, setCleanerStats] = useState({});
|
const [cleanerstats, setCleanerStats] = useState({});
|
||||||
const [submitting, setSubmitting] = useState(false);
|
const [submitting, setSubmitting] = useState(false);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import React, {
|
||||||
import { useSelector, useDispatch } from 'react-redux';
|
import { useSelector, useDispatch } from 'react-redux';
|
||||||
import { t } from 'ttag';
|
import { t } from 'ttag';
|
||||||
|
|
||||||
|
import popUps from '../core/popUps';
|
||||||
import {
|
import {
|
||||||
moveWindow,
|
moveWindow,
|
||||||
removeWindow,
|
removeWindow,
|
||||||
|
@ -81,23 +82,7 @@ const Window = ({ id }) => {
|
||||||
} = position;
|
} = position;
|
||||||
|
|
||||||
const popUp = useCallback((evt) => {
|
const popUp = useCallback((evt) => {
|
||||||
let left;
|
popUps.open(xPos, yPos, width, height);
|
||||||
let top;
|
|
||||||
try {
|
|
||||||
left = Math.round(window.top.screenX + xPos);
|
|
||||||
top = Math.round(window.top.screenY + yPos);
|
|
||||||
if (Number.isNaN(left) || Number.isNaN(top)) {
|
|
||||||
throw new Error('NaN');
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
left = 0;
|
|
||||||
top = 0;
|
|
||||||
}
|
|
||||||
window.lmao = window.open(
|
|
||||||
'./win',
|
|
||||||
'lol',
|
|
||||||
`popup=yes,width=${width},height=${height},left=${left},top=${top},toolbar=no,status=no,directories=no,menubar=no`,
|
|
||||||
);
|
|
||||||
close(evt);
|
close(evt);
|
||||||
}, [xPos, yPos, width, height]);
|
}, [xPos, yPos, width, height]);
|
||||||
|
|
||||||
|
|
|
@ -18,10 +18,8 @@ const TikTok = ({ url }) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function fetchData() {
|
async function fetchData() {
|
||||||
const prot = window.location.protocol.startsWith('http')
|
|
||||||
? window.location.protocol : 'https';
|
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
const tkurl = `${prot}//www.tiktok.com/oembed?url=${encodeURIComponent(url)}`;
|
const tkurl = `${window.location.protocol}//www.tiktok.com/oembed?url=${encodeURIComponent(url)}`;
|
||||||
const resp = await fetch(tkurl);
|
const resp = await fetch(tkurl);
|
||||||
const embedData = await resp.json();
|
const embedData = await resp.json();
|
||||||
if (embedData.html) {
|
if (embedData.html) {
|
||||||
|
|
|
@ -78,8 +78,6 @@ class PixelPlainterControls {
|
||||||
viewport.addEventListener('mousedown', this.onMouseDown, false);
|
viewport.addEventListener('mousedown', this.onMouseDown, false);
|
||||||
viewport.addEventListener('mousemove', this.onMouseMove, false);
|
viewport.addEventListener('mousemove', this.onMouseMove, false);
|
||||||
viewport.addEventListener('mouseup', this.onMouseUp, false);
|
viewport.addEventListener('mouseup', this.onMouseUp, false);
|
||||||
// TODO check if we can go passive here
|
|
||||||
// viewport.addEventListener('wheel', this.onWheel, { passive: true });
|
|
||||||
viewport.addEventListener('wheel', this.onWheel, false);
|
viewport.addEventListener('wheel', this.onWheel, false);
|
||||||
viewport.addEventListener('touchstart', this.onTouchStart, false);
|
viewport.addEventListener('touchstart', this.onTouchStart, false);
|
||||||
viewport.addEventListener('touchend', this.onTouchEnd, false);
|
viewport.addEventListener('touchend', this.onTouchEnd, false);
|
||||||
|
@ -486,7 +484,6 @@ class PixelPlainterControls {
|
||||||
const { store, viewport } = this;
|
const { store, viewport } = this;
|
||||||
viewport.style.cursor = 'auto';
|
viewport.style.cursor = 'auto';
|
||||||
store.dispatch(unsetHover());
|
store.dispatch(unsetHover());
|
||||||
store.dispatch(onViewFinishChange());
|
|
||||||
this.holdPainting = 0;
|
this.holdPainting = 0;
|
||||||
this.clearTabTimeout();
|
this.clearTabTimeout();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
*
|
* export palette in gimp format
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function appendNumberText(number) {
|
function appendNumberText(number) {
|
||||||
|
|
69
src/core/popUps.js
Normal file
69
src/core/popUps.js
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*
|
||||||
|
* keeping track of open popups
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PopUps {
|
||||||
|
constructor() {
|
||||||
|
this.wins = [];
|
||||||
|
this.origin = window.location.origin;
|
||||||
|
this.closeAll = this.closeAll.bind(this);
|
||||||
|
window.addEventListener('beforeunload', this.closeAll);
|
||||||
|
}
|
||||||
|
|
||||||
|
open(xPos, yPos, width, height) {
|
||||||
|
let left;
|
||||||
|
let top;
|
||||||
|
try {
|
||||||
|
left = Math.round(window.top.screenX + xPos);
|
||||||
|
top = Math.round(window.top.screenY + yPos);
|
||||||
|
if (Number.isNaN(left) || Number.isNaN(top)) {
|
||||||
|
throw new Error('NaN');
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
left = 0;
|
||||||
|
top = 0;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const newWindow = window.open(
|
||||||
|
'./win',
|
||||||
|
'lol',
|
||||||
|
`popup=yes,width=${width},height=${height},left=${left},top=${top},toolbar=no,status=no,directories=no,menubar=no`,
|
||||||
|
);
|
||||||
|
this.wins.push(newWindow);
|
||||||
|
} catch {
|
||||||
|
// nothing, just don't bubble up
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatch(msg) {
|
||||||
|
const { wins } = this;
|
||||||
|
console.log('sending', msg);
|
||||||
|
try {
|
||||||
|
for (let i = 0; i < wins.length; i += 1) {
|
||||||
|
const win = wins[i];
|
||||||
|
if (win.closed) {
|
||||||
|
wins.splice(i, 1);
|
||||||
|
i -= 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
win.postMessage(msg, this.origin);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
closeAll() {
|
||||||
|
while (this.wins.length) {
|
||||||
|
const win = this.wins.pop();
|
||||||
|
win.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const popUps = new PopUps();
|
||||||
|
|
||||||
|
window.lol = popUps.wins;
|
||||||
|
|
||||||
|
export default popUps;
|
|
@ -1,3 +1,5 @@
|
||||||
# Store
|
# Store
|
||||||
We use redux as a state manager of our application:
|
We use redux as a state manager of our application:
|
||||||
https://redux.js.org/
|
https://redux.js.org/
|
||||||
|
|
||||||
|
All actions that have a p/ prefix are shared between popups with the parent / popUp middlewares
|
||||||
|
|
|
@ -235,12 +235,10 @@ export function preLoadedBigChunk(
|
||||||
|
|
||||||
export function receiveBigChunk(
|
export function receiveBigChunk(
|
||||||
center,
|
center,
|
||||||
chunk,
|
|
||||||
) {
|
) {
|
||||||
return {
|
return {
|
||||||
type: 'REC_BIG_CHUNK',
|
type: 'REC_BIG_CHUNK',
|
||||||
center,
|
center,
|
||||||
chunk,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
33
src/store/middleware/parent.js
Normal file
33
src/store/middleware/parent.js
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* send and receive actions from parent window
|
||||||
|
*/
|
||||||
|
|
||||||
|
const BLACKLIST = [
|
||||||
|
'SET_HOVER',
|
||||||
|
'UNSET_HOVER',
|
||||||
|
'SET_SCALE',
|
||||||
|
'SET_VIEW_COORDINATES',
|
||||||
|
];
|
||||||
|
const { origin } = window.location;
|
||||||
|
|
||||||
|
export default () => (next) => (action) => {
|
||||||
|
if (action instanceof MessageEvent) {
|
||||||
|
if (action.origin !== origin) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return next(action.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.opener
|
||||||
|
&& !window.opener.closed
|
||||||
|
&& !BLACKLIST.includes(action.type)
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
window.opener.postMessage(action, origin);
|
||||||
|
} catch {
|
||||||
|
// nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(action);
|
||||||
|
};
|
29
src/store/middleware/popUps.js
Normal file
29
src/store/middleware/popUps.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* send and receive actions from popups
|
||||||
|
*/
|
||||||
|
import popUps from '../../core/popUps';
|
||||||
|
|
||||||
|
const BLACKLIST = [
|
||||||
|
'SET_HOVER',
|
||||||
|
'UNSET_HOVER',
|
||||||
|
'SET_SCALE',
|
||||||
|
'SET_VIEW_COORDINATES',
|
||||||
|
];
|
||||||
|
|
||||||
|
export default () => (next) => (action) => {
|
||||||
|
if (action instanceof MessageEvent) {
|
||||||
|
if (action.origin !== window.location.origin) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return next(action.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (popUps.wins.length
|
||||||
|
&& !BLACKLIST.includes(action.type)
|
||||||
|
&& action.type.indexOf('WIN') === -1
|
||||||
|
) {
|
||||||
|
popUps.dispatch(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(action);
|
||||||
|
};
|
|
@ -34,6 +34,7 @@ import array from './middleware/array';
|
||||||
import promise from './middleware/promise';
|
import promise from './middleware/promise';
|
||||||
import notifications from './middleware/notifications';
|
import notifications from './middleware/notifications';
|
||||||
import title from './middleware/title';
|
import title from './middleware/title';
|
||||||
|
import popUps from './middleware/popUps';
|
||||||
import extensions from './middleware/extensions';
|
import extensions from './middleware/extensions';
|
||||||
|
|
||||||
const windowsPersist = persistReducer({
|
const windowsPersist = persistReducer({
|
||||||
|
@ -59,6 +60,7 @@ const store = createStore(
|
||||||
thunk,
|
thunk,
|
||||||
promise,
|
promise,
|
||||||
array,
|
array,
|
||||||
|
popUps,
|
||||||
audio,
|
audio,
|
||||||
notifications,
|
notifications,
|
||||||
title,
|
title,
|
||||||
|
|
|
@ -21,6 +21,7 @@ import win from './reducers/win';
|
||||||
* middleware
|
* middleware
|
||||||
*/
|
*/
|
||||||
import promise from './middleware/promise';
|
import promise from './middleware/promise';
|
||||||
|
import parent from './middleware/parent';
|
||||||
|
|
||||||
const reducers = combineReducers({
|
const reducers = combineReducers({
|
||||||
...sharedReducers,
|
...sharedReducers,
|
||||||
|
@ -33,6 +34,7 @@ const store = createStore(
|
||||||
applyMiddleware(
|
applyMiddleware(
|
||||||
thunk,
|
thunk,
|
||||||
promise,
|
promise,
|
||||||
|
parent,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -264,9 +264,9 @@ class ChunkLoader {
|
||||||
try {
|
try {
|
||||||
const img = await loadImage(url);
|
const img = await loadImage(url);
|
||||||
chunkRGB.fromImage(img);
|
chunkRGB.fromImage(img);
|
||||||
this.store.dispatch(receiveBigChunk(center, chunkRGB));
|
this.store.dispatch(receiveBigChunk(center));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.store.dispatch(receiveBigChunkFailure(center, error));
|
this.store.dispatch(receiveBigChunkFailure(center, error.message));
|
||||||
if (historicalTime) {
|
if (historicalTime) {
|
||||||
chunkRGB.empty(true);
|
chunkRGB.empty(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -289,13 +289,13 @@ class ChunkLoader {
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Chunk response was invalid');
|
throw new Error('Chunk response was invalid');
|
||||||
}
|
}
|
||||||
this.store.dispatch(receiveBigChunk(center, chunkRGB));
|
this.store.dispatch(receiveBigChunk(center));
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Network response was not ok.');
|
throw new Error('Network response was not ok.');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
chunkRGB.empty();
|
chunkRGB.empty();
|
||||||
this.store.dispatch(receiveBigChunkFailure(center, error));
|
this.store.dispatch(receiveBigChunkFailure(center, error.message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,9 +306,9 @@ class ChunkLoader {
|
||||||
const url = `tiles/${this.canvasId}/${zoom}/${cx}/${cy}.webp`;
|
const url = `tiles/${this.canvasId}/${zoom}/${cx}/${cy}.webp`;
|
||||||
const img = await loadImage(url);
|
const img = await loadImage(url);
|
||||||
chunkRGB.fromImage(img);
|
chunkRGB.fromImage(img);
|
||||||
this.store.dispatch(receiveBigChunk(center, chunkRGB));
|
this.store.dispatch(receiveBigChunk(center));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.store.dispatch(receiveBigChunkFailure(center, error));
|
this.store.dispatch(receiveBigChunkFailure(center, error.message));
|
||||||
chunkRGB.empty();
|
chunkRGB.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class PcKeyProvider {
|
||||||
if (keys.length) {
|
if (keys.length) {
|
||||||
logger.info(`Loaded pc Keys: ${keys}`);
|
logger.info(`Loaded pc Keys: ${keys}`);
|
||||||
} else {
|
} else {
|
||||||
logger.info(`You have to define PROXYCHECK_KEY to use proxycheck.io`);
|
logger.info('You have to define PROXYCHECK_KEY to use proxycheck.io');
|
||||||
}
|
}
|
||||||
this.availableKeys = keys;
|
this.availableKeys = keys;
|
||||||
this.deniedKeys = [];
|
this.deniedKeys = [];
|
||||||
|
@ -93,7 +93,6 @@ function reqProxyCheck(ips) {
|
||||||
}
|
}
|
||||||
const postData = `ips=${ips.join(',')}`;
|
const postData = `ips=${ips.join(',')}`;
|
||||||
const path = `/v2/?vpn=1&asn=1&key=${key}`;
|
const path = `/v2/?vpn=1&asn=1&key=${key}`;
|
||||||
logger.info(`Request for ${postData}`);
|
|
||||||
|
|
||||||
const options = {
|
const options = {
|
||||||
hostname: 'proxycheck.io',
|
hostname: 'proxycheck.io',
|
||||||
|
@ -120,7 +119,9 @@ function reqProxyCheck(ips) {
|
||||||
|
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
try {
|
try {
|
||||||
const result = JSON.parse(data.join(''));
|
const jsonString = data.join('');
|
||||||
|
logger.info(`${postData}: ${jsonString}`);
|
||||||
|
const result = JSON.parse(jsonString);
|
||||||
if (result.status !== 'ok') {
|
if (result.status !== 'ok') {
|
||||||
if (result.status === 'error' && ips.length === 1) {
|
if (result.status === 'error' && ips.length === 1) {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
export function saveSelection() {
|
|
||||||
if (window.getSelection) {
|
|
||||||
const sel = window.getSelection();
|
|
||||||
if (sel.getRangeAt && sel.rangeCount) {
|
|
||||||
return sel.getRangeAt(0);
|
|
||||||
}
|
|
||||||
} else if (document.selection && document.selection.createRange) {
|
|
||||||
return document.selection.createRange();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function restoreSelection(range) {
|
|
||||||
if (range) {
|
|
||||||
if (window.getSelection) {
|
|
||||||
const sel = window.getSelection();
|
|
||||||
sel.removeAllRanges();
|
|
||||||
sel.addRange(range);
|
|
||||||
} else if (document.selection && range.select) {
|
|
||||||
range.select();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,4 +10,5 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log('hello');
|
console.log('hello');
|
||||||
renderAppWin(document.getElementById('app'), store);
|
renderAppWin(document.getElementById('app'), store);
|
||||||
|
window.addEventListener('message', store.dispatch);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user