various fixes
This commit is contained in:
@@ -23,7 +23,9 @@
|
||||
|
||||
// ── Extension→Page messaging (capture context for the popup) ──────────────
|
||||
browser.runtime.onMessage.addListener(function (msg) {
|
||||
if (msg && msg.kind === 'get_context') {
|
||||
if (!msg || typeof msg.kind !== 'string') return Promise.resolve(undefined);
|
||||
|
||||
if (msg.kind === 'get_context') {
|
||||
var selection = '';
|
||||
try { selection = window.getSelection().toString().trim(); } catch (e) {}
|
||||
return Promise.resolve({
|
||||
@@ -32,6 +34,26 @@
|
||||
url: window.location.href || '',
|
||||
});
|
||||
}
|
||||
|
||||
if (msg.kind === 'get_viewport') {
|
||||
var ph = Math.max(
|
||||
document.documentElement ? document.documentElement.scrollHeight : 0,
|
||||
document.body ? document.body.scrollHeight : 0
|
||||
);
|
||||
return Promise.resolve({
|
||||
viewportWidth: window.innerWidth || document.documentElement.clientWidth || 0,
|
||||
viewportHeight: window.innerHeight || document.documentElement.clientHeight || 0,
|
||||
pageHeight: ph,
|
||||
devicePixelRatio: window.devicePixelRatio || 1,
|
||||
scrollY: window.scrollY || window.pageYOffset || 0,
|
||||
});
|
||||
}
|
||||
|
||||
if (msg.kind === 'scroll_to') {
|
||||
window.scrollTo(0, msg.y);
|
||||
return Promise.resolve({ y: window.scrollY || window.pageYOffset || 0 });
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
});
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user