quickSnote
This commit is contained in:
37
browser-extension/content.js
Normal file
37
browser-extension/content.js
Normal file
@@ -0,0 +1,37 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
// ── Page→Extension messaging (used by the snotes helper page) ─────────────
|
||||
window.addEventListener('message', function (event) {
|
||||
if (event.source !== window) return;
|
||||
var msg = event.data;
|
||||
if (!msg || typeof msg.kind !== 'string') return;
|
||||
|
||||
switch (msg.kind) {
|
||||
case 'snotes-ping':
|
||||
window.postMessage({ kind: 'snotes-pong', version: '1.0.0' }, '*');
|
||||
break;
|
||||
case 'snotes-settings': {
|
||||
var data = {};
|
||||
if (msg.serverUrl !== undefined) data.serverUrl = msg.serverUrl;
|
||||
if (Object.keys(data).length > 0) browser.storage.sync.set(data);
|
||||
window.postMessage({ kind: 'snotes-settings-ack', ok: true }, '*');
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// ── Extension→Page messaging (capture context for the popup) ──────────────
|
||||
browser.runtime.onMessage.addListener(function (msg) {
|
||||
if (msg && msg.kind === 'get_context') {
|
||||
var selection = '';
|
||||
try { selection = window.getSelection().toString().trim(); } catch (e) {}
|
||||
return Promise.resolve({
|
||||
selection: selection,
|
||||
title: document.title || '',
|
||||
url: window.location.href || '',
|
||||
});
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user