", attributes);
if (cardsView) {
a.find(".mark-as-read")
.last()
.before(e);
}
else if (magazineView) {
a.find(".ago").after(e);
}
else if (articleView) {
a.find(".fx.metadata").append(e);
}
else {
a.find(".CondensedToolbar .button-dropdown").prepend(e);
}
return e;
};
var markAsReadBelowElement = addButton(ext.markAsReadAboveBelowId, {
class: ext.markAsReadAboveBelowClass + " mark-below-as-read",
title: "Mark articles below" +
(cardsView ? " and on the right" : "") +
" as read/unread"
});
var markAsReadAboveElement = addButton(ext.markAsReadAboveBelowId, {
class: ext.markAsReadAboveBelowClass + " mark-above-as-read",
title: "Mark articles above" +
(cardsView ? " and on the left" : "") +
" as read/unread"
});
var openAndMarkAsReadElement = addButton(ext.openAndMarkAsReadId, {
class: ext.openAndMarkAsReadClass,
title: "Open in a new window/tab and mark as read"
});
if (articleView) {
markAsReadBelowElement.detach().insertAfter(markAsReadAboveElement);
}
else if (magazineView) {
markAsReadAboveElement.detach().insertAfter(markAsReadBelowElement);
}
var link = getLink(a);
var openAndMarkAsRead = function (event) {
event.stopPropagation();
window.open(link, link);
reader.askMarkEntryAsRead(entryId);
if (articleView) {
$(a)
.closest(ext.articleViewEntryContainerSelector)
.removeClass("unread")
.addClass("read");
}
};
onClickCapture(openAndMarkAsReadElement, openAndMarkAsRead);
var visualElement;
if (cardsView) {
visualElement = a.find(".visual-container");
}
else if (magazineView) {
visualElement = a.find(".visual");
}
if (visualElement) {
onClickCapture(visualElement, function (e) {
if (getFFnS(ext.visualOpenAndMarkAsReadId)) {
openAndMarkAsRead(e);
}
});
}
if (titleView) {
onClickCapture(a.find(".content"), function (e) {
if (getFFnS(ext.titleOpenAndMarkAsReadId)) {
e.stopPropagation();
reader.askMarkEntryAsRead(entryId);
}
});
}
onClickCapture(markAsReadBelowElement, getMarkAsReadAboveBelowCallback(entryId, false));
onClickCapture(markAsReadAboveElement, getMarkAsReadAboveBelowCallback(entryId, true));
});
};
FeedlyPage.prototype.reset = function () {
this.clearHidingInfo();
var i = sessionStorage.length;
while (i--) {
var key = sessionStorage.key(i);
if (/^FFnS_/.test(key)) {
sessionStorage.removeItem(key);
}
}
};
FeedlyPage.prototype.refreshHidingInfo = function () {
var hiddenCount = 0;
$(ext.articleSelector).each(function (i, a) {
if (!$(a).is(":visible")) {
hiddenCount++;
}
});
this.clearHidingInfo();
if (hiddenCount == 0) {
return;
}
$(ext.hidingInfoSibling).after(" (" +
hiddenCount +
" hidden entries)
");
};
FeedlyPage.prototype.clearHidingInfo = function () {
$("." + this.hiddingInfoClass).remove();
};
FeedlyPage.prototype.put = function (id, value, persistent) {
sessionStorage.setItem("FFnS" + (persistent ? "#" : "_") + id, JSON.stringify(value));
};
FeedlyPage.prototype.get = function (id, persistent) {
return JSON.parse(sessionStorage.getItem("FFnS" + (persistent ? "#" : "_") + id));
};
FeedlyPage.prototype.getById = function (id) {
return document.getElementById(id + "_main");
};
FeedlyPage.prototype.fetchMoreEntries = function (batchSize) {
var autoLoadingMessageId = "FFnS_LoadingMessage";
var stream = getStreamPage().stream;
if ($(".message.loading").length == 0) {
$(ext.articlesContainerSelector)
.first()
.before($("", {
id: autoLoadingMessageId,
class: "message loading",
text: "Auto loading all articles"
}));
}
stream.setBatchSize(batchSize);
console.log("Fetching more articles (batch size: " +
stream._batchSize +
") at: " +
new Date().toTimeString());
stream.askMoreEntries();
stream.askingMoreEntries = false;
};
FeedlyPage.prototype.loadNextBatch = function (ev) {
ev && ev.stopPropagation();
var navigo = window["streets"].service("navigo");
var reader = window["streets"].service("reader");
var entries = navigo.originalEntries || navigo.getEntries();
var markAsReadEntryIds;
if (getFFnS(ext.keepArticlesUnreadId)) {
markAsReadEntryIds = getFFnS(ext.articlesToMarkAsReadId);
}
else {
markAsReadEntryIds = entries
.sort(function (a, b) {
return a.jsonInfo.crawled - b.jsonInfo.crawled;
})
.map(function (e) {
return e.id;
});
}
var keptUnreadEntryIds = getKeptUnreadEntryIds();
markAsReadEntryIds = markAsReadEntryIds.filter(function (id) {
return keptUnreadEntryIds.indexOf(id) < 0;
});
reader.askMarkEntriesAsRead(markAsReadEntryIds, {});
window.scrollTo(0, 0);
$(ext.articlesContainerSelector).empty();
navigo.originalEntries = null;
navigo.entries = [];
fetchMoreEntries(getFFnS(ext.batchSizeId, true));
};
FeedlyPage.prototype.overrideLoadingEntries = function () {
var streamObj = getStreamObj();
if (!streamObj) {
setTimeout(overrideLoadingEntries, 1000);
return;
}
putFFnS(ext.isNewestFirstId, streamObj._sort === "newest", true);
var autoLoadingMessageId = "#FFnS_LoadingMessage";
var loadNextBatchBtnId = "#FFnS_LoadNextBatchBtn";
var secondaryMarkAsReadBtnsSelector = ".mark-as-read-button.secondary";
var loadByBatchText = "Mark batch as read and load next batch";
var navigo = window["streets"].service("navigo");
var reader = window["streets"].service("reader");
var autoLoadAllArticleDefaultBatchSize = 1000;
var isAutoLoad = function () {
try {
return (getStreamPage() != null &&
($(ext.articleSelector).length == 0 ||
$(ext.unreadArticlesCountSelector).length > 0) &&
!(getStreamPage().stream.state.info.subscribed === false) &&
getFFnS(ext.autoLoadAllArticlesId, true));
}
catch (e) {
return false;
}
};
var prototype = Object.getPrototypeOf(streamObj);
var setBatchSize = prototype.setBatchSize;
prototype.setBatchSize = function (customSize) {
if (this._batchSize == customSize) {
return;
}
if (isAutoLoad()) {
this._batchSize = customSize;
}
else {
setBatchSize.apply(this, arguments);
}
};
var navigoPrototype = Object.getPrototypeOf(navigo);
var setEntries = navigoPrototype.setEntries;
navigoPrototype.setEntries = function (entries) {
try {
if (entries.length > 0) {
putFFnS(ext.sortArticlesId, true);
}
if (entries.length > 0 &&
entries[entries.length - 1].jsonInfo.unread &&
isAutoLoad()) {
var isLoadByBatch = getFFnS(ext.loadByBatchEnabledId, true);
var firstLoadByBatch_1 = false;
if (navigo.initAutoLoad) {
navigo.initAutoLoad = false;
firstLoadByBatch_1 = isLoadByBatch;
}
var streamPage = getStreamPage();
streamPage._scrollTarget.removeEventListener("scroll", streamPage._throttledCheckMoreEntriesNeeded);
var isBatchLoading = true;
var autoLoadAllArticleBatchSize_1 = autoLoadAllArticleDefaultBatchSize;
if (isLoadByBatch) {
var batchSize = getFFnS(ext.batchSizeId, true);
autoLoadAllArticleBatchSize_1 = batchSize;
if (entries.length >= batchSize) {
isBatchLoading = false;
}
}
var stream = getStreamPage().stream;
var hasAllEntries = stream.state.hasAllEntries;
if (!hasAllEntries &&
!stream.askingMoreEntries &&
!stream.state.isLoadingEntries &&
isBatchLoading &&
$(loadNextBatchBtnId).length == 0) {
stream.askingMoreEntries = true;
setTimeout(function () {
var batchSize = autoLoadAllArticleBatchSize_1;
if (firstLoadByBatch_1) {
batchSize = batchSize - entries.length;
}
fetchMoreEntries(batchSize);
}, 100);
}
else if (hasAllEntries || !isBatchLoading) {
$(autoLoadingMessageId).remove();
if (hasAllEntries) {
console.log("End auto load all articles at: " + new Date().toTimeString());
if (isLoadByBatch) {
$(loadNextBatchBtnId).remove();
}
}
else if (isLoadByBatch && $(loadNextBatchBtnId).length == 0) {
$(ext.articlesContainerSelector)
.last()
.after($("", {
id: loadNextBatchBtnId.substring(1),
class: "full-width secondary",
type: "button",
style: "margin-top: 1%;",
text: loadByBatchText
}));
onClickCapture($(loadNextBatchBtnId), loadNextBatch);
}
}
}
setTimeout(function () {
var markAsReadEntries = $(ext.markAsReadImmediatelySelector);
if (markAsReadEntries.length == 0) {
return;
}
var ids = $.map(markAsReadEntries.toArray(), function (e) {
return $(e).attr(ext.articleEntryIdAttribute);
});
reader.askMarkEntriesAsRead(ids, {});
markAsReadEntries
.removeClass(ext.markAsReadImmediatelyClass)
.removeClass("unread")
.addClass("read");
}, 1000);
}
catch (e) {
console.log(e);
}
return setEntries.apply(this, arguments);
};
NodeCreationObserver.onCreation(ext.loadingMessageSelector, function (e) {
if ($(autoLoadingMessageId).length == 1) {
$(e).hide();
}
});
NodeCreationObserver.onCreation(secondaryMarkAsReadBtnsSelector, function (e) {
if (getFFnS(ext.loadByBatchEnabledId, true)) {
$(secondaryMarkAsReadBtnsSelector).attr("title", loadByBatchText);
}
});
};
FeedlyPage.prototype.overrideMarkAsRead = function () {
var reader = window["streets"].service("reader");
var navigo = window["streets"].service("navigo");
var pagesPkg = window["devhd"].pkg("pages");
var prototype = pagesPkg.ReactPage.prototype;
var markAsRead = prototype.markAsRead;
prototype.markAsRead = function (lastEntryObject) {
var _this = this;
var jumpToNext = function () {
if (!/latest\/?$/i.test(document.URL)) {
if (navigo.getNextURI()) {
_this.feedly.jumpToNext();
}
else {
_this.feedly.loadDefaultPage();
}
}
else {
_this.feedly.jumpToNext();
}
};
if (lastEntryObject && lastEntryObject.asOf) {
markAsRead.call(this, lastEntryObject);
}
else if (getFFnS(ext.loadByBatchEnabledId, true) &&
!getStreamPage().stream.state.hasAllEntries) {
loadNextBatch();
}
else if (getFFnS(ext.keepArticlesUnreadId)) {
console.log("Marking as read with keeping new articles unread");
var idsToMarkAsRead = getFFnS(ext.articlesToMarkAsReadId);
if (idsToMarkAsRead) {
var keptUnreadEntryIds_2 = getKeptUnreadEntryIds();
idsToMarkAsRead = idsToMarkAsRead.filter(function (id) {
return keptUnreadEntryIds_2.indexOf(id) < 0;
});
console.log(idsToMarkAsRead.length + " new articles will be marked as read");
reader.askMarkEntriesAsRead(idsToMarkAsRead, {});
}
else {
console.log("No article to mark as read");
}
jumpToNext();
}
else {
markAsRead.call(this, lastEntryObject);
jumpToNext();
}
};
};
FeedlyPage.prototype.overrideSorting = function () {
var navigo = window["streets"].service("navigo");
var prototype = Object.getPrototypeOf(navigo);
function filterVisible(entry) {
return !($(getById(entry.id)).css("display") === "none");
}
function ensureSortedEntries() {
var entries = navigo.entries;
var originalEntries = navigo.originalEntries || entries;
navigo.originalEntries = originalEntries;
var sortedVisibleArticles = getFFnS(ext.sortedVisibleArticlesId);
if (!sortedVisibleArticles) {
navigo.entries = originalEntries;
navigo.originalEntries = null;
return;
}
var len = sortedVisibleArticles.length;
var sorted = len == entries.length;
for (var i = 0; i < len && sorted; i++) {
if (entries[i].id !== sortedVisibleArticles[i] ||
!filterVisible(entries[i])) {
sorted = false;
}
}
if (!sorted) {
entries = [].concat(originalEntries);
entries = entries.filter(filterVisible);
entries.sort(function (a, b) {
return (sortedVisibleArticles.indexOf(a.id) -
sortedVisibleArticles.indexOf(b.id));
});
navigo.entries = entries;
}
}
var lookupNextEntry = prototype.lookupNextEntry;
var lookupPreviousEntry = prototype.lookupPreviousEntry;
var getEntries = prototype.getEntries;
var setEntries = prototype.setEntries;
var reset = prototype.reset;
prototype.lookupNextEntry = function (a) {
ensureSortedEntries();
return lookupNextEntry.call(this, getFFnS(ext.hideAfterReadId) ? true : a);
};
prototype.lookupPreviousEntry = function (a) {
ensureSortedEntries();
return lookupPreviousEntry.call(this, getFFnS(ext.hideAfterReadId) ? true : a);
};
prototype.getEntries = function () {
try {
ensureSortedEntries();
}
catch (e) {
console.log(e);
}
return getEntries.apply(this, arguments);
};
prototype.setEntries = function () {
navigo.originalEntries = null;
return setEntries.apply(this, arguments);
};
prototype.reset = function () {
navigo.originalEntries = null;
return reset.apply(this, arguments);
};
prototype.listEntryIds = function () {
var a = [];
var entries = navigo.originalEntries || navigo.entries;
return (entries.forEach(function (b) {
a.push(b.getId());
}),
a);
};
};
FeedlyPage.prototype.overrideNavigation = function () {
var navigo = window["streets"].service("navigo");
var prototype = Object.getPrototypeOf(navigo);
var collectionPrefix = "collection/content/";
prototype.getNextURI = function () {
var e = this.nextURI;
if (!e ||
(e.endsWith("/category/global.all") &&
e.endsWith(getStreamObj().streamId))) {
try {
var categories = JSON.parse(window["streets"]
.service("preferences")
.getPreference("categoriesOrderingId"));
return collectionPrefix + categories[0];
}
catch (e) {
console.log(e);
}
}
return e;
};
};
return FeedlyPage;
}());
var UIManager = (function () {
function UIManager() {
this.containsReadArticles = false;
this.forceReloadGlobalSettings = false;
this.keywordToId = {};
this.idCount = 1;
this.sortingSelectId = "SortingType";
this.htmlSettingsElements = [
{
type: HTMLElementType.SelectBox,
ids: [
this.sortingSelectId,
"KeywordMatchingMethod",
this.getKeywordMatchingSelectId(false)
]
},
{
type: HTMLElementType.ColorInput,
ids: ["HighlightDuplicatesColor"]
},
{
type: HTMLElementType.CheckBox,
ids: [
"FilteringEnabled",
"RestrictingEnabled",
"SortingEnabled",
"PinHotToTop",
"KeepUnread_AdvancedControlsReceivedPeriod",
"Hide_AdvancedControlsReceivedPeriod",
"ShowIfHot_AdvancedControlsReceivedPeriod",
"MarkAsReadVisible_AdvancedControlsReceivedPeriod",
"OpenAndMarkAsRead",
"MarkAsReadAboveBelow",
"HideWhenMarkAboveBelow",
"HideAfterRead",
"ReplaceHiddenWithGap",
"AlwaysUseDefaultMatchingAreas",
"VisualOpenAndMarkAsRead",
"TitleOpenAndMarkAsRead",
"MarkAsReadFiltered",
"AutoRefreshEnabled",
"OpenCurrentFeedArticles",
"OpenCurrentFeedArticlesUnreadOnly",
"MarkAsReadOnOpenCurrentFeedArticles",
"DisplayDisableAllFiltersButton",
"HideDuplicates",
"MarkAsReadDuplicates",
"HighlightDuplicates",
"Enabled_FilteringByReadingTime",
"KeepUnread_FilteringByReadingTime"
]
},
{
type: HTMLElementType.NumberInput,
ids: [
"MinPopularity_AdvancedControlsReceivedPeriod",
"AutoRefreshMinutes",
"MaxOpenCurrentFeedArticles",
"ThresholdMinutes_FilteringByReadingTime",
"WordsPerMinute_FilteringByReadingTime"
]
}
];
this.settingsDivContainerId = this.getHTMLId("settingsDivContainer");
this.closeBtnId = this.getHTMLId("CloseSettingsBtn");
}
UIManager.prototype.init = function () {
var _this = this;
return new AsyncResult(function (p) {
_this.settingsManager = new SettingsManager(_this);
_this.keywordManager = new KeywordManager();
_this.page = new FeedlyPage();
_this.htmlSubscriptionManager = new HTMLSubscriptionManager(_this);
_this.settingsManager.init().then(function () {
_this.articleManager = new ArticleManager(_this.settingsManager, _this.keywordManager, _this.page);
_this.autoLoadAllArticlesCB = new HTMLGlobalSettings(ext.autoLoadAllArticlesId, false, _this);
_this.globalSettingsEnabledCB = new HTMLGlobalSettings("globalSettingsEnabled", true, _this, true, false);
_this.loadByBatchEnabledCB = new HTMLGlobalSettings(ext.loadByBatchEnabledId, false, _this);
_this.batchSizeInput = new HTMLGlobalSettings(ext.batchSizeId, 200, _this);
var crossCheckSettings = _this.settingsManager.getCrossCheckDuplicatesSettings();
_this.crossCheckDuplicatesCB = new HTMLGlobalSettings("CrossCheckDuplicates", false, _this, false, false);
_this.crossCheckDuplicatesDaysInput = new HTMLGlobalSettings("CrossCheckDuplicatesDays", 3, _this, false, false);
_this.crossCheckDuplicatesCB.setAdditionalChangeCallback(function (val) {
return crossCheckSettings.setEnabled(val);
});
_this.crossCheckDuplicatesDaysInput.setAdditionalChangeCallback(function (val) {
return crossCheckSettings.setDays(val);
});
_this.globalSettings = [
_this.autoLoadAllArticlesCB,
_this.loadByBatchEnabledCB,
_this.batchSizeInput,
_this.globalSettingsEnabledCB,
_this.crossCheckDuplicatesCB,
_this.crossCheckDuplicatesDaysInput
];
_this.initGlobalSettings(_this.globalSettings.slice(0)).then(function () {
_this.page.initAutoLoad();
_this.updateSubscription().then(function () {
_this.initUI();
_this.registerSettings();
_this.updateMenu();
_this.initSettingsCallbacks();
_this.postInit();
p.done();
}, _this);
}, _this);
}, _this);
}, this);
};
UIManager.prototype.initGlobalSettings = function (settings) {
var _this = this;
if (settings.length == 1) {
return settings[0].init();
}
else {
return new AsyncResult(function (p) {
settings
.pop()
.init()
.then(function () {
_this.initGlobalSettings(settings).chain(p);
}, _this);
}, this);
}
};
UIManager.prototype.resetGlobalSettings = function (settings) {
var _this = this;
if (settings.length == 1) {
return settings[0].reset();
}
else {
return new AsyncResult(function (p) {
settings
.pop()
.reset()
.then(function () {
_this.resetGlobalSettings(settings).chain(p);
}, _this);
}, this);
}
};
UIManager.prototype.updatePage = function () {
try {
this.resetPage();
this.updateSubscription().then(this.updateMenu, this);
}
catch (err) {
console.log(err);
}
};
UIManager.prototype.resetPage = function () {
this.containsReadArticles = false;
this.articleManager.resetArticles();
};
UIManager.prototype.refreshPage = function () {
this.updatePage();
this.refreshFilteringAndSorting();
};
UIManager.prototype.refreshFilteringAndSorting = function () {
this.page.reset();
this.page.update(this.subscription);
this.articleManager.refreshArticles();
};
UIManager.prototype.updateSubscription = function () {
var _this = this;
return new AsyncResult(function (p) {
var globalSettingsEnabled = _this.globalSettingsEnabledCB.getValue();
_this.settingsManager
.loadSubscription(globalSettingsEnabled, _this.forceReloadGlobalSettings)
.then(function (sub) {
_this.subscription = sub;
p.done();
}, _this);
}, this);
};
UIManager.prototype.updateMenu = function () {
var _this = this;
this.htmlSubscriptionManager.update();
setTimeout(function () {
_this.refreshFilteringAndSorting();
if ((_this.subscription.isSortingEnabled &&
_this.subscription.getSortingType() == SortingType.PopularityAsc) ||
_this.subscription.getSortingType() == SortingType.PopularityDesc) {
var maxCheck_1 = 10;
var handle_1 = setInterval(function () {
if (maxCheck_1-- === 0) {
return clearInterval(handle_1);
}
_this.articleManager.checkPopularityAndSort();
}, 3000);
}
}, 500);
getFilteringTypes().forEach(function (type) {
_this.prepareFilteringList(type);
});
this.updateSettingsControls();
// Additional sorting types
$("#FFnS_AdditionalSortingTypes").empty();
this.subscription.getAdditionalSortingTypes().forEach(function (s) {
var id = _this.registerAdditionalSortingType();
$id(id).val(s);
});
// coloring rules
$("#FFnS_ColoringRules").empty();
this.subscription
.getColoringRules()
.forEach(this.registerColoringRule, this);
this.refreshColoringRuleArrows();
this.updateSettingsModeTitle();
};
UIManager.prototype.updateSettingsModeTitle = function () {
var title = this.globalSettingsEnabledCB.getValue()
? "Global"
: "Subscription";
title += " settings";
$id("FFnS_settings_mode_title").text(title);
};
UIManager.prototype.updateSettingsControls = function () {
$id("FFnS_SettingsControls_SelectedSubscription").html(this.getImportOptionsHTML());
var linkedSubContainer = $id("FFnS_SettingsControls_LinkedSubContainer");
var linkedSub = $id("FFnS_SettingsControls_LinkedSub");
if ((!this.globalSettingsEnabledCB.getValue() &&
this.subscription.getURL() !==
this.settingsManager.getActualSubscriptionURL()) ||
(this.globalSettingsEnabledCB.getValue() &&
!this.settingsManager.isGlobalMode())) {
linkedSubContainer.css("display", "");
linkedSub.text("Subscription currently linked to: " + this.subscription.getURL());
}
else {
linkedSubContainer.css("display", "none");
linkedSub.text("");
}
};
UIManager.prototype.getSettingsControlsSelectedSubscription = function () {
return $id("FFnS_SettingsControls_SelectedSubscription").val();
};
UIManager.prototype.initUI = function () {
this.initSettingsMenu();
this.initShowSettingsBtns();
this.globalSettings.forEach(function (globalSetting) {
globalSetting.initUI();
});
};
UIManager.prototype.initSettingsMenu = function () {
var marginElementClass = this.getHTMLId("margin_element");
var tabsMenuId = this.getHTMLId("tabs_menu");
var tabsContentContainerId = this.getHTMLId("tabs_content");
var settingsHtml = bindMarkup(templates.settingsHTML, [
{
name: "SortingSelect",
value: this.getSortingSelectHTML(this.getHTMLId(this.sortingSelectId))
},
{
name: "FilteringList.Type.FilteredOut",
value: this.getFilteringListHTML(FilteringType.FilteredOut)
},
{
name: "FilteringList.Type.RestrictedOn",
value: this.getFilteringListHTML(FilteringType.RestrictedOn)
},
{
name: "ImportMenu.SubscriptionOptions",
value: this.getImportOptionsHTML()
},
{ name: "closeIconLink", value: ext.closeIconLink },
{ name: "plusIconLink", value: ext.plusIconLink },
{ name: "eraseIconLink", value: ext.eraseIconLink },
{
name: "DefaultKeywordMatchingArea",
value: this.getKeywordMatchingSelectHTML("multiple required", false)
},
{
name: "KeywordMatchingMethod",
value: this.getKeywordMatchingMethod(true)
}
]);
$("body").prepend(settingsHtml);
// set up tabs
$("#" + tabsMenuId + " a").click(function (event) {
event.preventDefault();
$(this)
.parent()
.addClass("current");
$(this)
.parent()
.siblings()
.removeClass("current");
var tab = $(this).attr("href");
$("#" + tabsContentContainerId + " > div")
.not(tab)
.css("display", "none");
$(tab).show();
});
$("#" + tabsContentContainerId + " > div")
.first()
.show();
};
UIManager.prototype.getSortingSelectHTML = function (id) {
return bindMarkup(templates.sortingSelectHTML, [
{ name: "Id", value: id },
{ name: "PopularityDesc", value: SortingType.PopularityDesc },
{ name: "TitleAsc", value: SortingType.TitleAsc },
{ name: "PopularityAsc", value: SortingType.PopularityAsc },
{ name: "TitleDesc", value: SortingType.TitleDesc },
{ name: "PublishDateNewFirst", value: SortingType.PublishDateNewFirst },
{ name: "PublishDateOldFirst", value: SortingType.PublishDateOldFirst },
{ name: "PublishDayNewFirst", value: SortingType.PublishDayNewFirst },
{ name: "PublishDayOldFirst", value: SortingType.PublishDayOldFirst },
{ name: "ReceivedDateNewFirst", value: SortingType.ReceivedDateNewFirst },
{ name: "ReceivedDateOldFirst", value: SortingType.ReceivedDateOldFirst },
{ name: "SourceAsc", value: SortingType.SourceAsc },
{ name: "SourceDesc", value: SortingType.SourceDesc },
{
name: "SourceNewestReceiveDate",
value: SortingType.SourceNewestReceiveDate
},
{ name: "Random", value: SortingType.Random }
]);
};
UIManager.prototype.getFilteringListHTML = function (type) {
var ids = this.getIds(type);
var filteringListHTML = bindMarkup(templates.filteringListHTML, [
{ name: "FilteringTypeTabId", value: this.getFilteringTypeTabId(type) },
{ name: "inputId", value: this.getHTMLId(ids.inputId) },
{ name: "plusBtnId", value: this.getHTMLId(ids.plusBtnId) },
{ name: "eraseBtnId", value: this.getHTMLId(ids.eraseBtnId) },
{ name: "filetringKeywordsId", value: ids.filetringKeywordsId },
{
name: "FilteringKeywordMatchingArea",
value: this.getKeywordMatchingSelectHTML("filtering", true, type)
}
]);
return filteringListHTML;
};
UIManager.prototype.getKeywordMatchingSelectHTML = function (attributes, includeDefaultOption, type, selectId) {
var defaultOption = includeDefaultOption
? bindMarkup(templates.emptyOptionHTML, [
{ name: "value", value: "-- area (optional) --" }
])
: "";
var filteringListHTML = bindMarkup(templates.keywordMatchingSelectHTML, [
{
name: "Id",
value: selectId || this.getKeywordMatchingSelectId(true, type)
},
{ name: "attributes", value: attributes },
{ name: "defaultOption", value: defaultOption },
{ name: "selectFirst", value: includeDefaultOption ? "" : "selected" },
{ name: "KeywordMatchingArea.Title", value: KeywordMatchingArea.Title },
{ name: "KeywordMatchingArea.Body", value: KeywordMatchingArea.Body },
{ name: "KeywordMatchingArea.Author", value: KeywordMatchingArea.Author }
]);
return filteringListHTML;
};
UIManager.prototype.getKeywordMatchingSelectId = function (html, type) {
var suffix = type == undefined ? "s" : "_" + FilteringType[type];
var id = "KeywordMatchingArea" + suffix;
return html ? this.getHTMLId(id) : id;
};
UIManager.prototype.getKeywordMatchingMethod = function (fullSize, id) {
id = id || "FFnS_KeywordMatchingMethod";
return bindMarkup(templates.keywordMatchingMethodHTML, [
{ name: "id", value: id },
{
name: "KeywordMatchingMethod.Simple",
value: KeywordMatchingMethod.Simple
},
{ name: "KeywordMatchingMethod.Word", value: KeywordMatchingMethod.Word },
{
name: "KeywordMatchingMethod.RegExp",
value: KeywordMatchingMethod.RegExp
},
{ name: "size", value: fullSize ? 'size="3"' : "" }
]);
};
UIManager.prototype.getImportOptionsHTML = function () {
var optionsHTML = "";
var urls = this.settingsManager.getAllSubscriptionURLs();
urls.forEach(function (url) {
optionsHTML += bindMarkup(templates.optionHTML, [
{ name: "value", value: url }
]);
});
return optionsHTML;
};
UIManager.prototype.initShowSettingsBtns = function () {
var this_ = this;
NodeCreationObserver.onCreation(ext.settingsBtnPredecessorSelector, function (element) {
if ($(element).parent().find(".ShowSettingsBtn").length > 0) {
return;
}
var clone = $(element).clone();
$(clone)
.empty()
.removeAttr("class")
.attr("title", "Feedly filtering and sorting")
.addClass("ShowSettingsBtn");
$(element).after(clone);
$(clone).click(function () {
$id(this_.settingsDivContainerId).toggle();
});
});
};
UIManager.prototype.registerSettings = function () {
var _this = this;
this.htmlSettingsElements.forEach(function (element) {
_this.htmlSubscriptionManager.registerSettings(element.ids, element.type);
});
this.htmlSubscriptionManager.registerSettings([
"Hours_AdvancedControlsReceivedPeriod",
"Days_AdvancedControlsReceivedPeriod"
], HTMLElementType.NumberInput, {
update: function (subscriptionSetting) {
var advancedControlsReceivedPeriod = subscriptionSetting.manager.subscription.getAdvancedControlsReceivedPeriod();
var maxHours = advancedControlsReceivedPeriod.maxHours;
var advancedPeriodHours = maxHours % 24;
var advancedPeriodDays = Math.floor(maxHours / 24);
if (subscriptionSetting.id.indexOf("Hours") != -1) {
$id(subscriptionSetting.htmlId).val(advancedPeriodHours);
}
else {
$id(subscriptionSetting.htmlId).val(advancedPeriodDays);
}
}
});
this.htmlSubscriptionManager.registerSelectBoxBoolean(ext.markAsReadAboveBelowReadId, function (subscription) {
return subscription.isMarkAsReadAboveBelowRead();
});
this.htmlSubscriptionManager.registerSelectBoxBoolean("FilterLong_FilteringByReadingTime", function (subscription) {
return subscription.getFilteringByReadingTime().filterLong;
});
};
UIManager.prototype.initSettingsCallbacks = function () {
var _this = this;
this.htmlSubscriptionManager.setUpCallbacks();
$id(this.closeBtnId).click(function () {
$id(_this.settingsDivContainerId).toggle();
});
var importSettings = $id("FFnS_ImportSettings");
importSettings.change(function () {
_this.settingsManager.importAllSettings(importSettings.prop("files")[0]);
});
$id("FFnS_ExportSettings").click(function () {
_this.settingsManager.exportAllSettings();
});
$id("FFnS_SettingsControls_ImportFromOtherSub").click(function () {
_this.importFromOtherSub();
});
$id("FFnS_SettingsControls_LinkToSub").click(function () {
_this.linkToSub();
});
$id("FFnS_SettingsControls_UnlinkFromSub").click(function () {
_this.unlinkFromSub();
});
$id("FFnS_SettingsControls_DeleteSub").click(function () {
_this.deleteSub();
});
$id("FFnS_AddSortingType").click(function () {
var id = _this.registerAdditionalSortingType();
_this.subscription.addAdditionalSortingType($id(id).val());
_this.refreshFilteringAndSorting();
});
$id("FFnS_EraseSortingTypes").click(function () {
_this.subscription.setAdditionalSortingTypes([]);
$("#FFnS_AdditionalSortingTypes").empty();
_this.refreshFilteringAndSorting();
});
onClick($id("FFnS_AddColoringRule"), function () {
var cr = new ColoringRule();
_this.registerColoringRule(cr);
_this.subscription.addColoringRule(cr);
_this.articleManager.refreshColoring();
_this.refreshColoringRuleArrows();
});
onClick($id("FFnS_EraseColoringRules"), function () {
_this.subscription.setColoringRules([]);
$id("FFnS_ColoringRules").empty();
_this.articleManager.refreshColoring();
});
this.setUpFilteringListEvents();
var useDefaultMatchingAreas = $id("FFnS_AlwaysUseDefaultMatchingAreas");
function toggleFilteringKeywordMatchingSelects() {
var selects = $(".FFnS_keywordMatchingSelect[filtering]");
if (isChecked($(useDefaultMatchingAreas))) {
selects.hide();
}
else {
selects.show();
}
}
toggleFilteringKeywordMatchingSelects();
useDefaultMatchingAreas.change(toggleFilteringKeywordMatchingSelects);
};
UIManager.prototype.postInit = function () {
var _this = this;
var syncManager = DataStore.getSyncStorageManager();
var syncCBId = "FFnS_syncSettingsEnabled";
if (syncManager) {
setChecked(syncCBId, syncManager.isSyncEnabled());
$id(syncCBId).change(function () {
syncManager.setSyncEnabled(isChecked($id(syncCBId)));
_this.forceReloadGlobalSettings = true;
_this.resetGlobalSettings(_this.globalSettings.slice(0)).then(function () {
_this.refreshPage();
_this.forceReloadGlobalSettings = false;
}, _this);
});
}
else {
$id(syncCBId)
.closest(".setting_group")
.remove();
}
if (this.subscription.isAutoRefreshEnabled()) {
setInterval(function () {
$(".icon-toolbar-refresh-secondary")
.first()
.click();
}, this.subscription.getAutoRefreshTime());
}
var forceRefreshArticlesBtn = $("", {
id: ext.forceRefreshArticlesId,
style: "display: none;"
});
$("body").append(forceRefreshArticlesBtn);
forceRefreshArticlesBtn.click(function (e) {
e.preventDefault();
_this.articleManager.refreshArticles();
});
onClick($(".icon-fx-light-mode-md-black, .icon-fx-dark-mode-md-black"), function () {
setTimeout(function () { return _this.articleManager.refreshColoring(); }, 100);
});
};
UIManager.prototype.registerAdditionalSortingType = function () {
var _this = this;
var id = this.getHTMLId("AdditionalSortingType_" + this.idCount++);
$("#FFnS_AdditionalSortingTypes").append(this.getSortingSelectHTML(id));
$id(id).change(function () { return _this.updateAdditionalSortingTypes(); });
return id;
};
UIManager.prototype.registerColoringRule = function (cr) {
var _this = this;
var ids = new ColoringRuleHTMLIds(this.getHTMLId("ColoringRule_" + this.idCount++));
var self = this;
// append template
var html = bindMarkup(templates.coloringRuleHTML, [
{ name: "Id", value: ids.id },
{ name: "Color", value: cr.color },
{ name: "SpecificKeywords", value: ColoringRuleSource.SpecificKeywords },
{ name: "SourceTitle", value: ColoringRuleSource.SourceTitle },
{
name: "RestrictingKeywords",
value: ColoringRuleSource.RestrictingKeywords
},
{
name: "FilteringKeywords",
value: ColoringRuleSource.FilteringKeywords
},
{
name: "KeywordMatchingMethod",
value: this.getKeywordMatchingMethod(false, ids.id + "_KeywordMatchingMethod")
},
{
name: "KeywordMatchingArea",
value: this.getKeywordMatchingSelectHTML("required", false, null, ids.id + "_KeywordMatchingArea")
},
{ name: "plusIconLink", value: ext.plusIconLink },
{ name: "eraseIconLink", value: ext.eraseIconLink },
{ name: "moveUpIconLink", value: ext.moveUpIconLink },
{ name: "moveDownIconLink", value: ext.moveDownIconLink }
]);
$("#FFnS_ColoringRules").append(html);
// set current values
setChecked(ids.highlightId, cr.highlightAllTitle);
$id(ids.sourceId).val(cr.source);
$id(ids.matchingMethodId).val(cr.matchingMethod);
$id(ids.matchingAreaId).val(cr.matchingArea);
this.refreshColoringRuleSpecificKeywords(cr, ids);
var refreshVisibility = function () {
$id(ids.keywordGroupId).css("display", cr.source == ColoringRuleSource.SpecificKeywords ? "" : "none");
var sourceTitle = cr.source == ColoringRuleSource.SourceTitle;
$id(ids.matchingMethodContainerId).css("display", sourceTitle ? "none" : "");
$id(ids.matchingAreaContainerId).css("display", sourceTitle ? "none" : "");
$id(ids.optionsSpanId).css("display", sourceTitle ? "none" : "");
$id(ids.sourceTitleInfosId).css("display", sourceTitle ? "" : "none");
};
new jscolor($id(ids.colorId)[0]);
refreshVisibility();
// change callbacks
function onChange(id, cb, input, click, onchange) {
function callback() {
try {
var noChange = cb.call(this);
if (noChange) {
return;
}
self.subscription.save();
self.articleManager.refreshColoring();
refreshVisibility();
}
catch (e) {
console.log(e);
}
}
click
? onClick($id(id), callback)
: input
? ($id(id)[0].oninput = callback)
: $id(id).change(callback);
if (onchange) {
$id(id)[0].onchange = callback;
}
}
onChange(ids.highlightId, function () {
cr.highlightAllTitle = isChecked($(this));
});
onChange(ids.sourceId, function () {
cr.source = Number($(this).val());
});
onChange(ids.matchingMethodId, function () {
cr.matchingMethod = Number($(this).val());
});
onChange(ids.matchingAreaId, function () {
cr.matchingArea = Number($(this).val());
});
onChange(ids.colorId, function () {
var str = $(this).val();
if (str.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i)) {
cr.color = str.toUpperCase();
}
else {
$(this).val(str);
return true;
}
}, true, false, true);
onChange(ids.addBtnId, function () {
var keyword = $id(ids.keywordInputId).val();
if (keyword != null && keyword !== "") {
cr.specificKeywords.push(keyword);
}
$id(ids.keywordInputId).val("");
_this.refreshColoringRuleSpecificKeywords(cr, ids);
}, false, true);
onChange(ids.eraseBtnId, function () {
cr.specificKeywords = [];
$id(ids.keywordContainerId).empty();
}, false, true);
// Coloring rule management
onClick($id(ids.removeColoringRuleId), function () {
var rules = self.subscription.getColoringRules();
var i = rules.indexOf(cr);
if (i > -1) {
rules.splice(i, 1);
self.subscription.save();
self.articleManager.refreshColoring();
}
$id(ids.id).remove();
self.refreshColoringRuleArrows();
});
var getMoveColoringRuleCallback = function (up) {
return function () {
var rules = self.subscription.getColoringRules();
var i = rules.indexOf(cr);
if (up ? i > 0 : i < rules.length) {
var swapIdx = up ? i - 1 : i + 1;
var swap = rules[swapIdx];
rules[swapIdx] = rules[i];
rules[i] = swap;
self.subscription.save();
self.articleManager.refreshColoring();
var element = $id(ids.id);
if (up) {
var prev = element.prev();
element.detach().insertBefore(prev);
}
else {
var next = element.next();
element.detach().insertAfter(next);
}
self.refreshColoringRuleArrows();
}
};
};
onClick($id(ids.moveUpColoringRuleId), getMoveColoringRuleCallback(true));
onClick($id(ids.moveDownColoringRuleId), getMoveColoringRuleCallback(false));
};
UIManager.prototype.refreshColoringRuleArrows = function () {
$(".FFnS_MoveUpColoringRule")
.not(":first")
.show();
$(".FFnS_MoveUpColoringRule:first").hide();
$(".FFnS_MoveDownColoringRule")
.not(":last")
.show();
$(".FFnS_MoveDownColoringRule:last").hide();
};
UIManager.prototype.refreshColoringRuleSpecificKeywords = function (cr, ids) {
var keywords = cr.specificKeywords;
var html = "";
for (var i = 0; i < keywords.length; i++) {
var keyword = keywords[i];
var keywordId = this.getKeywordId(ids.id, keyword);
var keywordHTML = bindMarkup(templates.keywordHTML, [
{ name: "keywordId", value: keywordId },
{ name: "keyword", value: keyword }
]);
html += keywordHTML;
}
$id(ids.keywordContainerId).html(html);
};
UIManager.prototype.setUpFilteringListEvents = function () {
getFilteringTypes().forEach(this.setUpFilteringListManagementEvents, this);
};
UIManager.prototype.setUpFilteringListManagementEvents = function (type) {
var _this = this;
var ids = this.getIds(type);
var keywordList = this.subscription.getFilteringList(type);
// Add button
$id(this.getHTMLId(ids.plusBtnId)).click(function () {
var input = $id(_this.getHTMLId(ids.inputId));
var keyword = input.val();
if (keyword != null && keyword !== "") {
var area = $id(_this.getKeywordMatchingSelectId(true, type)).val();
if (area.length > 0) {
keyword = _this.keywordManager.insertArea(keyword, area);
}
_this.subscription.addKeyword(keyword, type);
_this.updateFilteringList(type);
input.val("");
}
});
// Erase all button
$id(this.getHTMLId(ids.eraseBtnId)).click(function () {
if (confirm("Erase all the keywords of this list ?")) {
_this.subscription.resetFilteringList(type);
_this.updateFilteringList(type);
}
});
this.setUpKeywordButtonsEvents(type);
};
UIManager.prototype.setUpKeywordButtonsEvents = function (type) {
var ids = this.getIds(type);
var keywordList = this.subscription.getFilteringList(type);
// Keyword buttons events
var t = this;
for (var i = 0; i < keywordList.length; i++) {
var keywordId = this.getKeywordId(ids.typeId, keywordList[i]);
$id(keywordId).click(function () {
var keyword = $(this).text();
if (confirm("Delete the keyword ?")) {
t.subscription.removeKeyword(keyword, type);
t.updateFilteringList(type);
}
});
}
};
UIManager.prototype.updateFilteringList = function (type) {
this.prepareFilteringList(type);
this.refreshFilteringAndSorting();
};
UIManager.prototype.prepareFilteringList = function (type) {
var ids = this.getIds(type);
var filteringList = this.subscription.getFilteringList(type);
var filteringKeywordsHTML = "";
for (var i = 0; i < filteringList.length; i++) {
var keyword = filteringList[i];
var keywordId = this.getKeywordId(ids.typeId, keyword);
var filteringKeywordHTML = bindMarkup(templates.keywordHTML, [
{ name: "keywordId", value: keywordId },
{ name: "keyword", value: keyword }
]);
filteringKeywordsHTML += filteringKeywordHTML;
}
$id(ids.filetringKeywordsId).html(filteringKeywordsHTML);
this.setUpKeywordButtonsEvents(type);
};
UIManager.prototype.updateAdditionalSortingTypes = function () {
var additionalSortingTypes = [];
$("#FFnS_AdditionalSortingTypes > select").each(function (i, e) {
return additionalSortingTypes.push($(e).val());
});
this.subscription.setAdditionalSortingTypes(additionalSortingTypes);
this.refreshFilteringAndSorting();
};
UIManager.prototype.addArticle = function (article) {
try {
this.articleManager.addArticle(article);
var callback = this.readArticlesMutationCallback(article);
var articleObserver = new MutationObserver(callback);
articleObserver.observe(article, { attributes: true });
callback([], articleObserver);
}
catch (err) {
console.log(err);
}
};
UIManager.prototype.readArticlesMutationCallback = function (article) {
var _this = this;
return function (mr, observer) {
var readClassElement = !$(article).hasClass(ext.articleViewClass)
? $(article)
: $(article).closest(ext.articleViewEntryContainerSelector);
if (readClassElement.hasClass(ext.readArticleClass) &&
!$(article).hasClass("inlineFrame")) {
if (_this.subscription.isHideAfterRead()) {
if (_this.subscription.isReplaceHiddenWithGap()) {
$(article).attr("gap-article", "true");
}
else {
$(article).remove();
}
}
observer.disconnect();
}
};
};
UIManager.prototype.addSection = function (section) {
if (section.id === "section0") {
$(section)
.find("h2")
.text(" ");
}
else {
$(section).remove();
}
};
UIManager.prototype.importFromOtherSub = function () {
var selectedURL = this.getSettingsControlsSelectedSubscription();
if (selectedURL &&
confirm("Import settings from the subscription url /" + selectedURL + " ?")) {
this.settingsManager
.importSubscription(selectedURL)
.then(this.refreshPage, this);
}
};
UIManager.prototype.linkToSub = function () {
var selectedURL = this.getSettingsControlsSelectedSubscription();
if (selectedURL &&
confirm("Link current subscription to: /" + selectedURL + " ?")) {
this.settingsManager.linkToSubscription(selectedURL);
this.refreshPage();
}
};
UIManager.prototype.unlinkFromSub = function () {
if (confirm("Unlink current subscription ?")) {
this.settingsManager.deleteSubscription(this.settingsManager.getActualSubscriptionURL());
this.refreshPage();
}
};
UIManager.prototype.deleteSub = function () {
var selectedURL = this.getSettingsControlsSelectedSubscription();
if (selectedURL && confirm("Delete : /" + selectedURL + " ?")) {
this.settingsManager.deleteSubscription(selectedURL);
this.refreshPage();
}
};
UIManager.prototype.getHTMLId = function (id) {
return "FFnS_" + id;
};
UIManager.prototype.getKeywordId = function (keywordListId, keyword) {
if (!(keyword in this.keywordToId)) {
var id = this.idCount++;
this.keywordToId[keyword] = id;
}
return this.getHTMLId(keywordListId + "_" + this.keywordToId[keyword]);
};
UIManager.prototype.getFilteringTypeTabId = function (filteringType) {
return this.getHTMLId("Tab_" + FilteringType[filteringType]);
};
UIManager.prototype.getIds = function (type) {
var id = getFilteringTypeId(type);
return {
typeId: "Keywords_" + id,
inputId: "Input_" + id,
plusBtnId: "Add_" + id,
eraseBtnId: "DeleteAll_" + id,
filetringKeywordsId: "FiletringKeywords_" + id
};
};
return UIManager;
}());
var ColoringRuleHTMLIds = (function () {
function ColoringRuleHTMLIds(id) {
this.id = id;
this.highlightId = id + " .FFnS_HighlightAllTitle";
this.colorId = id + " .FFnS_SpecificColor";
this.sourceId = id + " .FFnS_ColoringRule_Source";
this.matchingMethodId = id + " .FFnS_KeywordMatchingMethod";
this.matchingMethodContainerId =
id + " .FFnS_ColoringRule_MatchingMethodGroup";
this.matchingAreaId = id + " .FFnS_keywordMatchingSelect";
this.matchingAreaContainerId = id + " .FFnS_ColoringRule_MatchingAreaGroup";
this.keywordInputId = id + " .FFnS_ColoringRule_KeywordInput";
this.addBtnId = id + " .FFnS_ColoringRule_AddKeyword";
this.eraseBtnId = id + " .FFnS_ColoringRule_EraseKeywords";
this.keywordContainerId = id + " .FFnS_ColoringRuleKeywords";
this.keywordGroupId = id + " .FFnS_ColoringRule_KeywordsGroup";
this.specificColorGroupId = id + " .FFnS_SpecificColorGroup";
this.optionsSpanId = id + " .FFnS_ColoringRule_Options";
this.sourceTitleInfosId = id + " .FFnS_ColoringRule_SourceTitleInfos";
this.removeColoringRuleId = id + " .FFnS_RemoveColoringRule";
this.moveUpColoringRuleId = id + " .FFnS_MoveUpColoringRule";
this.moveDownColoringRuleId = id + " .FFnS_MoveDownColoringRule";
}
return ColoringRuleHTMLIds;
}());
var HTMLSubscriptionManager = (function () {
function HTMLSubscriptionManager(manager) {
var _this = this;
this.subscriptionSettings = [];
this.configByElementType = {};
this.manager = manager;
this.configByElementType[HTMLElementType.SelectBox] = {
setUpChangeCallback: function (subscriptionSetting) {
$id(subscriptionSetting.htmlId).change(_this.getChangeCallback(subscriptionSetting));
},
getHTMLValue: function (subscriptionSetting) {
return $id(subscriptionSetting.htmlId).val();
},
update: function (subscriptionSetting) {
var value = _this.manager.subscription["get" + subscriptionSetting.id]();
$id(subscriptionSetting.htmlId).val(value);
}
};
this.configByElementType[HTMLElementType.CheckBox] = {
setUpChangeCallback: function (subscriptionSetting) {
$id(subscriptionSetting.htmlId).change(_this.getChangeCallback(subscriptionSetting));
},
getHTMLValue: function (subscriptionSetting) {
return isChecked($id(subscriptionSetting.htmlId));
},
update: function (subscriptionSetting) {
var value = _this.manager.subscription["is" + subscriptionSetting.id]();
setChecked(subscriptionSetting.htmlId, value);
}
};
this.configByElementType[HTMLElementType.NumberInput] = {
setUpChangeCallback: function (subscriptionSetting) {
var callback = _this.getChangeCallback(subscriptionSetting);
$id(subscriptionSetting.htmlId)[0].oninput = function (ev) {
callback();
};
},
getHTMLValue: function (subscriptionSetting) {
return Number($id(subscriptionSetting.htmlId).val());
},
update: this.configByElementType[HTMLElementType.SelectBox].update
};
this.configByElementType[HTMLElementType.ColorInput] = {
setUpChangeCallback: function (subscriptionSetting) {
var callback = _this.getChangeCallback(subscriptionSetting);
var e = $id(subscriptionSetting.htmlId)[0];
e.oninput = function (ev) {
callback();
};
e.onchange = e.oninput;
},
getHTMLValue: this.configByElementType[HTMLElementType.SelectBox]
.getHTMLValue,
update: function (subscriptionSetting) {
var value = _this.manager.subscription["get" + subscriptionSetting.id]();
var jq = $id(subscriptionSetting.htmlId);
jq.val(value);
if (!subscriptionSetting["jscolor"]) {
subscriptionSetting["jscolor"] = true;
new jscolor(jq[0]);
}
}
};
}
HTMLSubscriptionManager.prototype.getChangeCallback = function (setting) {
return function () {
try {
var val = setting.config.getHTMLValue(setting);
if (val == null) {
return;
}
setting.manager.subscription["set" + setting.id](val);
setting.manager.refreshFilteringAndSorting();
}
catch (e) {
console.log(e);
}
};
};
HTMLSubscriptionManager.prototype.registerSettings = function (ids, type, subscriptionSettingConfig) {
this.addSettings(ids, this.configByElementType[type], subscriptionSettingConfig);
};
HTMLSubscriptionManager.prototype.registerSelectBoxBoolean = function (id, getValueCallback) {
this.registerSettings([id], HTMLElementType.SelectBox, {
update: function (subscriptionSetting) {
$id(subscriptionSetting.htmlId).val(getValueCallback(subscriptionSetting.manager.subscription) + "");
},
getHTMLValue: function (subscriptionSetting) {
return $id(subscriptionSetting.htmlId).val() === "true";
}
});
};
HTMLSubscriptionManager.prototype.addSettings = function (ids, config, subscriptionSettingConfig) {
var _this = this;
ids.forEach(function (id) {
var setting = new HTMLSubscriptionSetting(_this.manager, id, config, subscriptionSettingConfig);
_this.subscriptionSettings.push(setting);
});
};
HTMLSubscriptionManager.prototype.setUpCallbacks = function () {
this.subscriptionSettings.forEach(function (subscriptionSetting) {
subscriptionSetting.setUpCallbacks();
});
};
HTMLSubscriptionManager.prototype.update = function () {
this.subscriptionSettings.forEach(function (subscriptionSetting) {
subscriptionSetting.update();
});
};
return HTMLSubscriptionManager;
}());
var HTMLSubscriptionSetting = (function () {
function HTMLSubscriptionSetting(manager, id, config, subscriptionSettingConfig) {
this.manager = manager;
this.id = id;
this.htmlId = manager.getHTMLId(id);
var getHTMLValue, update;
if (subscriptionSettingConfig != null) {
getHTMLValue = subscriptionSettingConfig.getHTMLValue;
update = subscriptionSettingConfig.update;
}
getHTMLValue = getHTMLValue == null ? config.getHTMLValue : getHTMLValue;
update = update == null ? config.update : update;
this.config = {
setUpChangeCallback: config.setUpChangeCallback,
getHTMLValue: getHTMLValue,
update: update
};
}
HTMLSubscriptionSetting.prototype.update = function () {
this.config.update(this);
};
HTMLSubscriptionSetting.prototype.setUpCallbacks = function () {
this.config.setUpChangeCallback(this);
};
return HTMLSubscriptionSetting;
}());
var HTMLGlobalSettings = (function () {
function HTMLGlobalSettings(id, defaultValue, uiManager, fullRefreshOnChange, sessionStore) {
if (fullRefreshOnChange === void 0) { fullRefreshOnChange = false; }
if (sessionStore === void 0) { sessionStore = true; }
this.id = id;
this.defaultValue = defaultValue;
this.isBoolean = typeof defaultValue === "boolean";
this.uiManager = uiManager;
this.htmlId = uiManager.getHTMLId(id);
this.fullRefreshOnChange = fullRefreshOnChange;
this.sessionStoreEnabled = sessionStore;
}
HTMLGlobalSettings.prototype.init = function () {
return this.load();
};
HTMLGlobalSettings.prototype.load = function () {
var _this = this;
return new AsyncResult(function (p) {
DataStore.getAsync(_this.id, _this.defaultValue).then(function (value) {
_this.setValue(value);
p.done();
}, _this);
}, this);
};
HTMLGlobalSettings.prototype.reset = function () {
var _this = this;
return new AsyncResult(function (p) {
_this.load().then(function () {
_this.refreshHTMLValue();
p.done();
}, _this);
}, this);
};
HTMLGlobalSettings.prototype.getValue = function () {
return this.value;
};
HTMLGlobalSettings.prototype.setValue = function (value) {
this.value = value;
this.sessionStore();
};
HTMLGlobalSettings.prototype.refreshValue = function (value) {
this.setValue(value);
this.save();
this.refreshHTMLValue();
};
HTMLGlobalSettings.prototype.setAdditionalChangeCallback = function (additionalChangeCallback) {
this.additionalChangeCallback = additionalChangeCallback;
};
HTMLGlobalSettings.prototype.save = function () {
DataStore.put(this.id, this.value);
};
HTMLGlobalSettings.prototype.sessionStore = function () {
if (this.sessionStoreEnabled) {
this.uiManager.page.put(this.id, this.value, true);
}
};
HTMLGlobalSettings.prototype.getHTMLValue = function (e) {
if (this.isBoolean) {
return isChecked(e);
}
else {
return Number(e.val());
}
};
HTMLGlobalSettings.prototype.refreshHTMLValue = function () {
if (this.isBoolean) {
setChecked(this.htmlId, this.value);
}
else {
return $id(this.htmlId).val(this.value);
}
};
HTMLGlobalSettings.prototype.initUI = function () {
var _this = this;
var this_ = this;
var additionalCallback = function () {
if (_this.additionalChangeCallback) {
_this.additionalChangeCallback.call(_this, this_.value);
}
};
function changeCallback() {
var val = this_.getHTMLValue($(this));
this_.setValue(val);
this_.save();
if (this_.fullRefreshOnChange) {
this_.uiManager.refreshPage();
}
additionalCallback();
}
if (this.isBoolean) {
$id(this.htmlId).click(changeCallback);
}
else {
$id(this.htmlId)[0].oninput = changeCallback;
}
this.refreshHTMLValue();
additionalCallback();
};
return HTMLGlobalSettings;
}());
var DEBUG = false;
function initResources() {
INITIALIZER.loadScript("jquery.min.js");
INITIALIZER.loadScript("node-creation-observer.js");
var urls = INITIALIZER.getResourceURLs();
ext.plusIconLink = urls.plusIconURL;
ext.eraseIconLink = urls.eraseIconURL;
ext.closeIconLink = urls.closeIconURL;
ext.moveUpIconLink = urls.moveUpIconURL;
ext.moveDownIconLink = urls.moveDownIconURL;
templates.styleCSS = bindMarkup(templates.styleCSS, [
{ name: "open-in-new-tab-url", value: urls.openInNewTabURL },
{ name: "disable-all-filters-url", value: urls.clearFiltersURL },
{ name: "extension-icon", value: urls.extensionIconURL }
]);
injectStyleText(templates.styleCSS);
}
$(document).ready(function () {
try {
initResources();
var uiManager = new UIManager();
var uiManagerBind = callbackBindedTo(uiManager);
NodeCreationObserver.onCreation(ext.subscriptionChangeSelector, function () {
console.log("Feedly page fully loaded");
uiManager.init().then(function () {
NodeCreationObserver.onCreation(ext.articleSelector, uiManagerBind(uiManager.addArticle));
NodeCreationObserver.onCreation(ext.sectionSelector, uiManagerBind(uiManager.addSection));
NodeCreationObserver.onCreation(ext.subscriptionChangeSelector, uiManagerBind(uiManager.updatePage));
}, this);
}, true);
}
catch (e) {
console.log(e);
}
});