|
|
@ -1,12 +1,25 @@
|
|
|
|
/** global: browser */
|
|
|
|
/** global: browser */
|
|
|
|
/** global: XMLSerializer */
|
|
|
|
/** global: XMLSerializer */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* global browser, chrome */
|
|
|
|
|
|
|
|
/* eslint-env browser */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function sendMessage(id, subject, callback) {
|
|
|
|
|
|
|
|
(chrome || browser).runtime.sendMessage({
|
|
|
|
|
|
|
|
id,
|
|
|
|
|
|
|
|
subject,
|
|
|
|
|
|
|
|
source: 'content.js',
|
|
|
|
|
|
|
|
}, callback || (() => {}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (typeof browser !== 'undefined' && typeof document.body !== 'undefined') {
|
|
|
|
if (typeof browser !== 'undefined' && typeof document.body !== 'undefined') {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
sendMessage('init', {});
|
|
|
|
sendMessage('init', {});
|
|
|
|
|
|
|
|
|
|
|
|
// HTML
|
|
|
|
// HTML
|
|
|
|
let html = new XMLSerializer().serializeToString(document).split('\n');
|
|
|
|
let html = new XMLSerializer().serializeToString(document)
|
|
|
|
|
|
|
|
.replace(new RegExp('(.{1000,}[^>]*>)<', 'g'), (match, p1) => `${p1}\n<`)
|
|
|
|
|
|
|
|
.split('\n');
|
|
|
|
|
|
|
|
|
|
|
|
html = html
|
|
|
|
html = html
|
|
|
|
.slice(0, 1000).concat(html.slice(html.length - 1000))
|
|
|
|
.slice(0, 1000).concat(html.slice(html.length - 1000))
|
|
|
@ -31,14 +44,14 @@ if (typeof browser !== 'undefined' && typeof document.body !== 'undefined') {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
removeEventListener('message', onMessage);
|
|
|
|
window.removeEventListener('message', onMessage);
|
|
|
|
|
|
|
|
|
|
|
|
sendMessage('analyze', { js: event.data.js });
|
|
|
|
sendMessage('analyze', { js: event.data.js });
|
|
|
|
|
|
|
|
|
|
|
|
script.remove();
|
|
|
|
script.remove();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
addEventListener('message', onMessage);
|
|
|
|
window.addEventListener('message', onMessage);
|
|
|
|
|
|
|
|
|
|
|
|
sendMessage('get_js_patterns', {}, (response) => {
|
|
|
|
sendMessage('get_js_patterns', {}, (response) => {
|
|
|
|
if (response) {
|
|
|
|
if (response) {
|
|
|
@ -58,14 +71,6 @@ if (typeof browser !== 'undefined' && typeof document.body !== 'undefined') {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function sendMessage(id, subject, callback) {
|
|
|
|
|
|
|
|
(chrome || browser).runtime.sendMessage({
|
|
|
|
|
|
|
|
id,
|
|
|
|
|
|
|
|
subject,
|
|
|
|
|
|
|
|
source: 'content.js',
|
|
|
|
|
|
|
|
}, callback || (() => {}));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/44774834
|
|
|
|
// https://stackoverflow.com/a/44774834
|
|
|
|
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/executeScript#Return_value
|
|
|
|
// https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/executeScript#Return_value
|
|
|
|
undefined;
|
|
|
|
undefined; // eslint-disable-line no-unused-expressions
|
|
|
|