#636: basic Auto Reader View
This commit is contained in:
parent
7b55a0cc47
commit
83a100c423
|
@ -13,6 +13,8 @@ Cu.import("resource://gre/modules/ExtensionContent.jsm");
|
||||||
|
|
||||||
const g104FxForcePref = "tenfourfox.reader.force-enable"; // TenFourFox issue 583
|
const g104FxForcePref = "tenfourfox.reader.force-enable"; // TenFourFox issue 583
|
||||||
const g104FxStickyPref = "tenfourfox.reader.sticky"; // TenFourFox issue 620
|
const g104FxStickyPref = "tenfourfox.reader.sticky"; // TenFourFox issue 620
|
||||||
|
const g104FxAutoPref = "tenfourfox.reader.auto."; // TenFourFox issue 636
|
||||||
|
|
||||||
Cu.import("resource://gre/modules/Preferences.jsm");
|
Cu.import("resource://gre/modules/Preferences.jsm");
|
||||||
|
|
||||||
XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
|
XPCOMUtils.defineLazyModuleGetter(this, "E10SUtils",
|
||||||
|
@ -262,6 +264,7 @@ var AboutReaderListener = {
|
||||||
_articlePromise: null,
|
_articlePromise: null,
|
||||||
_alwaysAllowReaderMode: true, // TenFourFox issue 583
|
_alwaysAllowReaderMode: true, // TenFourFox issue 583
|
||||||
_stickyReaderMode: true, // TenFourFox issue 620
|
_stickyReaderMode: true, // TenFourFox issue 620
|
||||||
|
_currentURISpec: null, // TenFourFox issue 636
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
addEventListener("AboutReaderContentLoaded", this, false, true);
|
addEventListener("AboutReaderContentLoaded", this, false, true);
|
||||||
|
@ -273,12 +276,15 @@ var AboutReaderListener = {
|
||||||
Services.prefs.addObserver(g104FxForcePref, this, false);
|
Services.prefs.addObserver(g104FxForcePref, this, false);
|
||||||
Services.prefs.addObserver(g104FxStickyPref, this, false);
|
Services.prefs.addObserver(g104FxStickyPref, this, false);
|
||||||
Services.obs.addObserver(this, "AboutReader:Ready", false);
|
Services.obs.addObserver(this, "AboutReader:Ready", false);
|
||||||
|
/* content-document-global-created seems to NS_ASSERT */
|
||||||
|
Services.obs.addObserver(this, "document-element-inserted", false);
|
||||||
},
|
},
|
||||||
|
|
||||||
// TenFourFox issue 583
|
// TenFourFox issue 583 + 636
|
||||||
uninit: function() {
|
uninit: function() {
|
||||||
Services.prefs.removeObserver(g104FxForcePref, this, false);
|
Services.prefs.removeObserver(g104FxForcePref, this, false);
|
||||||
Services.obs.removeObserver(this, "AboutReader:Ready");
|
Services.obs.removeObserver(this, "AboutReader:Ready");
|
||||||
|
Services.obs.removeObserver(this, "document-element-inserted");
|
||||||
},
|
},
|
||||||
observe: function(subject, topic, data) { // jshint ignore:line
|
observe: function(subject, topic, data) { // jshint ignore:line
|
||||||
if (topic === "nsPref:changed") {
|
if (topic === "nsPref:changed") {
|
||||||
|
@ -288,6 +294,51 @@ var AboutReaderListener = {
|
||||||
if (topic === "AboutReader:Ready") {
|
if (topic === "AboutReader:Ready") {
|
||||||
this.stickyReaderLinks();
|
this.stickyReaderLinks();
|
||||||
}
|
}
|
||||||
|
if (topic === "document-element-inserted") { // TenFourFox issue 636
|
||||||
|
this.doAutoReaderView();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// TenFourFox issue 636
|
||||||
|
doAutoReaderView: function() {
|
||||||
|
if (!content || this.isAboutReader)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!content.document.documentURI.startsWith("http:") &&
|
||||||
|
!content.document.documentURI.startsWith("https")) {
|
||||||
|
/* could be another about: page, could be ftp, ... */
|
||||||
|
this._currentURISpec = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* if we ended up back here because we explicitly exited Reader View on
|
||||||
|
the same URL, then honour what the user probably wants. */
|
||||||
|
let loc = content.document.location;
|
||||||
|
if (this._currentURISpec == loc.href) return;
|
||||||
|
this._currentURISpec = loc.href;
|
||||||
|
|
||||||
|
let uri = Services.io.newURI(loc.href, null, null);
|
||||||
|
if (uri && uri.host && uri.host.length && uri.host.length > 0) {
|
||||||
|
let w = null;
|
||||||
|
try {
|
||||||
|
w = Services.prefs.getCharPref(g104FxAutoPref + uri.host);
|
||||||
|
} catch(e) { }
|
||||||
|
if (w && w.length && w.length > 0) {
|
||||||
|
if (w == "y") {
|
||||||
|
loc.href = "about:reader?url="+encodeURIComponent(uri.spec);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (w == "s") {
|
||||||
|
if (uri.path && uri.path.length && uri.path != "" && uri.path != "/"
|
||||||
|
&& !uri.path.startsWith("/?")
|
||||||
|
&& !uri.path.toLowerCase().startsWith("/index.")
|
||||||
|
) {
|
||||||
|
loc.href = "about:reader?url="+encodeURIComponent(uri.spec);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
receiveMessage: function(message) {
|
receiveMessage: function(message) {
|
||||||
|
|
Loading…
Reference in New Issue