intermediate
This commit is contained in:
+47
@@ -0,0 +1,47 @@
|
||||
const port = browser.runtime.connectNative("mozacReaderExtract");
|
||||
|
||||
let domChanged = false;
|
||||
let lastContent = '';
|
||||
|
||||
function parseContent() {
|
||||
const article = window.parseReaderable(document);
|
||||
|
||||
if (article && lastContent !== article.textContent) {
|
||||
port.postMessage(article);
|
||||
|
||||
lastContent = article.textContent;
|
||||
}
|
||||
|
||||
domChanged = false;
|
||||
}
|
||||
|
||||
port.onMessage.addListener((message) => {
|
||||
if (message.action === "parseContent") {
|
||||
if (domChanged) {
|
||||
parseContent();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
domChanged = true;
|
||||
});
|
||||
|
||||
const observerConfig = {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
characterData: true,
|
||||
attributes: false
|
||||
};
|
||||
|
||||
// Wait for page to be fully loaded
|
||||
if (document.readyState === 'complete') {
|
||||
parseContent();
|
||||
observer.observe(document.body, observerConfig);
|
||||
} else {
|
||||
window.addEventListener('load', parseContent);
|
||||
}
|
||||
|
||||
window.addEventListener('unload', () => {
|
||||
observer.disconnect();
|
||||
});
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"manifest_version": 2,
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
"id": "readability-extract@movenext.me"
|
||||
}
|
||||
},
|
||||
"name": "Extract text of Websites",
|
||||
"version": "1.0",
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["<all_urls>"],
|
||||
"js": [
|
||||
"readability.min.js",
|
||||
"content.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
"permissions": [
|
||||
"mozillaAddons",
|
||||
"geckoViewAddons",
|
||||
"nativeMessaging",
|
||||
"nativeMessagingFromContent",
|
||||
"storage",
|
||||
"tabs",
|
||||
"webNavigation",
|
||||
"<all_urls>"
|
||||
]
|
||||
}
|
||||
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../../../../../javascript/readability/dist/readability.min.js
|
||||
Reference in New Issue
Block a user