Skip to content

Commit

Permalink
add back sidebar button (requires new-xkit#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcustyphoon committed Aug 14, 2020
1 parent 00596cf commit 2988426
Showing 1 changed file with 70 additions and 3 deletions.
73 changes: 70 additions & 3 deletions Extensions/show_originals.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,20 @@ XKit.extensions.show_originals = new Object({
slow: true,

status: "false",
lbl_on: "on",
lbl_off: "off",
my_blogs: [],

preferences: {
"sep-0": {
text: "Functionality",
type: "separator"
},
"show_on_sidebar": {
text: "Show toggle in the sidebar",
default: true,
value: true
},
"show_my_posts": {
text: "Don't hide my posts",
default: true,
Expand Down Expand Up @@ -59,14 +66,50 @@ XKit.extensions.show_originals = new Object({
});
},

run: function() {
run: async function() {
this.running = true;

this.my_blogs = XKit.tools.get_blogs();

//I don't do anything with this right now since XKit.interface.sidebar isn't a thing
// This could be made to work on react by detecting css mapped manualPaginatorButtons, but it's not really necessary
/*
if (!$("body").hasClass("with_auto_paginate")) {
if (XKit.storage.get("show_originals", "shown_warning_about_scrolling", "") !== "yass") {
XKit.notifications.add("Show Originals only works when Endless Scrolling is turned on. Click here to learn more and disable this warning.", "warning", false, function() {
XKit.window.show("Endless Scrolling required.", "Show Originals require Endless Scrolling to be enabled on your dashboard. Click on the Tumblr Settings button (gear icon) on top-right of the page and then Dashboard > Enable endless scrolling.", "error", "<div class=\"xkit-button default\" id=\"xkit-close-message\">OK</div>");
XKit.storage.set("show_originals", "shown_warning_about_scrolling", "yass");
});
}
return;
}
*/

XKit.extensions.show_originals.status = XKit.storage.get("show_originals", "status", "false");

const where = XKit.interface.where();
const show_sidebar_definitely = where.dashboard || where.likes;
const show_sidebar_ifmine = where.queue || where.channel || where.drafts;

if (this.preferences.show_on_sidebar.value && (show_sidebar_definitely || show_sidebar_ifmine && !this.preferences.show_my_posts.value)) {
await XKit.interface.react.sidebar.add({
id: "xshow_originals_sidebar",
title: "Show Originals",
items: [{
id: "xshoworiginals_button",
text: "Originals Only",
count: XKit.extensions.show_originals.lbl_off
}]
});
}

XKit.extensions.show_originals.update_button();

$("#xshoworiginals_button").click(function() {
XKit.extensions.show_originals.toggle();

return false;
});

if (XKit.page.react) {

const automatic_color = 'var(--blog-contrasting-title-color,var(--transparent-white-65))';
Expand Down Expand Up @@ -131,13 +174,36 @@ XKit.extensions.show_originals = new Object({
}
},

update_button: function() {

if (XKit.extensions.show_originals.status == "true") {
$("#xshoworiginals_button .count").html(XKit.extensions.show_originals.lbl_on);
} else {
$("#xshoworiginals_button .count").html(XKit.extensions.show_originals.lbl_off);
}

},

toggle: function() {

if (XKit.extensions.show_originals.status == "true") {
XKit.extensions.show_originals.status = "false";
} else {
XKit.extensions.show_originals.status = "true";
}

XKit.extensions.show_originals.update_button();
XKit.storage.set("show_originals", "status", XKit.extensions.show_originals.status);

},

react_do: function() {

//runs on each post
$('[data-id]:not(.showoriginals-done)').each(async function() {
const $this = $(this).addClass('showoriginals-done');
const {show_my_posts, show_original_reblogs, active_in_peepr, hide_posts_generic, hide_posts_completely} = XKit.extensions.show_originals.preferences;
const {rebloggedFromUrl, rebloggedFromName, rebloggedRootName, blogName, postUrl} = await XKit.interface.react.post_props($this.attr('data-id'));
const {rebloggedFromUrl, rebloggedFromName, rebloggedRootName, blogName} = await XKit.interface.react.post_props($this.attr('data-id'));

// Don't hide posts that aren't reblogs
if (!rebloggedFromUrl) { return; }
Expand Down Expand Up @@ -193,6 +259,7 @@ XKit.extensions.show_originals = new Object({
$('.showoriginals-hidden-note').remove();
XKit.post_listener.remove('showoriginals');
XKit.tools.remove_css("showoriginals");
XKit.interface.react.sidebar.remove("xshow_originals_sidebar");
}

});

0 comments on commit 2988426

Please sign in to comment.