mirror of
https://github.com/fregante/GhostText.git
synced 2024-11-24 12:15:54 +03:00
Improve compatibility with CSP pages (#315)
This commit is contained in:
parent
331c70f7f0
commit
3fb653eea1
@ -7,8 +7,7 @@
|
||||
* @typedef { import('@codemirror/view').EditorView } EditorView
|
||||
*/
|
||||
|
||||
// Do not write code outside this function, it won't be available because this function is serialized
|
||||
export default function unsafeMessenger() {
|
||||
function unsafeMessenger() {
|
||||
const lastKnownValue = new WeakMap();
|
||||
document.body.addEventListener('gt:get', listener);
|
||||
|
||||
@ -129,5 +128,6 @@ export default function unsafeMessenger() {
|
||||
}
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
undefined; // Avoids issues with tabs.injectScript
|
||||
unsafeMessenger();
|
||||
|
||||
console.log('Advanced editors messenger ready');
|
||||
|
@ -30,12 +30,10 @@ async function handleAction({id}) {
|
||||
// eslint-disable-next-line object-shorthand -- Chrome hates it
|
||||
func: () => {
|
||||
try {
|
||||
console.log('Starting GT');
|
||||
// eslint-disable-next-line no-undef -- Different context
|
||||
startGT();
|
||||
return 'ready';
|
||||
return true;
|
||||
} catch {
|
||||
console.log('not ready');
|
||||
return false;
|
||||
}
|
||||
},
|
||||
@ -58,6 +56,13 @@ async function handleAction({id}) {
|
||||
target: {tabId: id, frameIds: virginFrames},
|
||||
injectImmediately: true,
|
||||
});
|
||||
|
||||
chrome.scripting.executeScript({
|
||||
files: ['/advanced-editors-messenger.js'],
|
||||
target: {tabId: id, frameIds: virginFrames},
|
||||
world: 'MAIN',
|
||||
injectImmediately: true,
|
||||
});
|
||||
}
|
||||
|
||||
function handlePortListenerErrors(listener) {
|
||||
|
@ -1,5 +1,4 @@
|
||||
import GThumane from './humane-ghosttext.js';
|
||||
import advancedEditors from './advanced-editors-messenger.js';
|
||||
import optionsStorage from './options-storage.js';
|
||||
|
||||
const knownElements = new Map();
|
||||
@ -153,6 +152,12 @@ class GhostTextField {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.field.value === undefined) {
|
||||
console.log('field value is undefined');
|
||||
console.log(this.field);
|
||||
return;
|
||||
}
|
||||
|
||||
console.info('sending', this.field.value.length, 'characters');
|
||||
this.port.postMessage(
|
||||
JSON.stringify({
|
||||
@ -340,14 +345,7 @@ function stopGT() {
|
||||
document.body.classList.remove('GT--waiting');
|
||||
}
|
||||
|
||||
function init() {
|
||||
const script = document.createElement('script');
|
||||
script.textContent = '(' + advancedEditors.toString() + ')()';
|
||||
document.head.append(script);
|
||||
}
|
||||
|
||||
window.startGT = startGT;
|
||||
window.stopGT = stopGT;
|
||||
|
||||
init();
|
||||
startGT();
|
||||
setTimeout(startGT, 100);
|
||||
|
@ -35,7 +35,7 @@
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "ghosttext@bfred.it",
|
||||
"strict_min_version": "120.0"
|
||||
"strict_min_version": "128.0"
|
||||
}
|
||||
},
|
||||
"options_ui": {
|
||||
@ -91,6 +91,7 @@
|
||||
"humane-ghosttext.css",
|
||||
"humane-ghosttext.js",
|
||||
"icons/*",
|
||||
"advanced-editors-messenger.js",
|
||||
"options-storage.js",
|
||||
"options.html",
|
||||
"options.js"
|
||||
|
Loading…
Reference in New Issue
Block a user