Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Attempt to fix #53
Browse files Browse the repository at this point in the history
  • Loading branch information
Serega007RU committed Oct 2, 2023
1 parent 037b03f commit 363feaf
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 1 deletion.
2 changes: 1 addition & 1 deletion public/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
data-settings="reload_delay_time"
/>
</div>
</div>
</div>
</div>
<!-- reCAPTCHA -->
<div class="tab-content" data-tab="recaptcha">
Expand Down
30 changes: 30 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ chrome.runtime.onInstalled.addListener(async () => {
});

const kvStorage = {};
let fakeIdToId = {};
chrome.runtime.onMessage.addListener(function (
{ type, label },
sender,
Expand All @@ -66,7 +67,36 @@ chrome.runtime.onMessage.addListener(function (
label.key = `${sender.tab.id}_${label.key}`;
}
sendResponse({ status: 'success', value: kvStorage[label.key] });
} else if (type === 'HackTimer') {
if (label.name === 'setInterval') {
fakeIdToId[label.fakeId] = setInterval(function () {
triggerTimer(label.name, sender.tab.id, label.fakeId);
}, label.time);
} else if (label.name === 'clearInterval') {
clearInterval(fakeIdToId[label.fakeId]);
delete fakeIdToId[label.fakeId];
} else if (label.name === 'setTimeout') {
fakeIdToId[label.fakeId] = setTimeout(function () {
triggerTimer(label.name, sender.tab.id, label.fakeId);
delete fakeIdToId[label.fakeId];
}, label.time);
} else if (label.name === 'clearTimeout') {
clearTimeout(fakeIdToId[label.fakeId]);
delete fakeIdToId[label.fakeId];
}
}
})();
return true;
});

async function triggerTimer(name, tabId, fakeId) {
try {
await chrome.tabs.sendMessage(tabId, {
type: 'HackTimer',
label: { fakeId },
});
} catch (error) {
if (name === 'setInterval') clearInterval(fakeIdToId[fakeId]);
delete fakeIdToId[fakeId];
}
}
98 changes: 98 additions & 0 deletions src/hacktimer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
let fakeIdToCallback = {},
lastFakeId = 0,
maxFakeId = 0x7fffffff; // 2 ^ 31 - 1, 31 bit, positive values of signed 32 bit integer
window.fakeIdToCallback = fakeIdToCallback;

function getFakeId() {
do {
if (lastFakeId === maxFakeId) {
lastFakeId = 0;
} else {
lastFakeId++;
}
} while (fakeIdToCallback.hasOwnProperty(lastFakeId));
return lastFakeId;
}

window.setInterval = function (callback, time /* , parameters */) {
let fakeId = getFakeId();
fakeIdToCallback[fakeId] = {
callback: callback,
parameters: Array.prototype.slice.call(arguments, 2),
};
chrome.runtime.sendMessage({
type: 'HackTimer',
label: {
name: 'setInterval',
fakeId,
time,
},
});
return fakeId;
};
window.clearInterval = function (fakeId) {
if (fakeIdToCallback.hasOwnProperty(fakeId)) {
delete fakeIdToCallback[fakeId];
chrome.runtime.sendMessage({
type: 'HackTimer',
label: {
name: 'clearInterval',
fakeId,
},
});
}
};
window.setTimeout = function (callback, time /* , parameters */) {
let fakeId = getFakeId();
fakeIdToCallback[fakeId] = {
callback: callback,
parameters: Array.prototype.slice.call(arguments, 2),
isTimeout: true,
};
chrome.runtime.sendMessage({
type: 'HackTimer',
label: {
name: 'setTimeout',
fakeId,
time,
},
});
return fakeId;
};
window.clearTimeout = function (fakeId) {
if (fakeIdToCallback.hasOwnProperty(fakeId)) {
delete fakeIdToCallback[fakeId];
chrome.runtime.sendMessage({
type: 'HackTimer',
label: {
name: 'clearTimeout',
fakeId,
},
});
}
};

chrome.runtime.onMessage.addListener(function (
{ type, label } /*, sender, sendResponse*/
) {
if (type === 'HackTimer') {
let fakeId = label.fakeId,
request,
parameters,
callback;
if (fakeIdToCallback.hasOwnProperty(fakeId)) {
request = fakeIdToCallback[fakeId];
callback = request.callback;
parameters = request.parameters;
if (request.hasOwnProperty('isTimeout') && request.isTimeout) {
delete fakeIdToCallback[fakeId];
}
}
if (typeof callback === 'string') {
console.error('Callback is not supported as string');
}
if (typeof callback === 'function') {
callback.apply(window, parameters);
}
}
});
1 change: 1 addition & 0 deletions src/hcaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import Jimp from 'jimp';
import { Time } from './utils';
require('./hacktimer.js');
const ort = require('onnxruntime-web');

// Modify ort wasm path
Expand Down
1 change: 1 addition & 0 deletions src/recaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import Jimp from 'jimp';
import { KVStorage, Time } from './utils.js';

require('./hacktimer.js');
const ort = require('onnxruntime-web');

// Modify ort wasm path
Expand Down

0 comments on commit 363feaf

Please sign in to comment.