Skip to content

Commit 03fd22f

Browse files
committed
remove unblock button; refactor to match AprilSylph#2132
1 parent 4054a14 commit 03fd22f

2 files changed

Lines changed: 18 additions & 31 deletions

File tree

src/features/postblock/index.css

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
[data-postblock-hidden] {
1+
[data-postblock-hidden], .xkit-postblock-hidden-post-controls ~ div [data-xkit-postblock-hidden-controlled] {
22
content: linear-gradient(transparent, transparent);
33
height: 0;
44
}
55

6-
.xkit-postblock-warning {
6+
.xkit-postblock-hidden-post-controls {
77
padding: 25px 20px;
88
border-radius: 3px;
99
margin-bottom: var(--post-padding);
@@ -16,10 +16,10 @@
1616
line-height: 1.5em;
1717
}
1818

19-
.xkit-postblock-warning button {
19+
.xkit-postblock-hidden-post-controls button {
2020
color: var(--blog-link-color);
2121
}
2222

23-
.xkit-postblock-warning button:disabled {
23+
.xkit-postblock-hidden-post-controls button:disabled {
2424
color: var(--blog-link-color-40);
2525
}

src/features/postblock/index.js

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,20 @@ import { navigate } from '../../utils/tumblr_helpers.js';
1010
const meatballButtonId = 'postblock';
1111
const meatballButtonLabel = 'Block this post';
1212
const hiddenAttribute = 'data-postblock-hidden';
13-
const warningClass = 'xkit-postblock-warning';
13+
const controlsClass = 'xkit-postblock-hidden-post-controls';
14+
const controlledHiddenAttribute = 'data-xkit-postblock-hidden-controlled';
1415
const storageKey = 'postblock.blockedPostRootIDs';
1516
const blogUuidsStorageKey = 'postblock.blockedPostBlogUUIDs';
1617

1718
let blogUuids = {};
1819

19-
const addWarningElement = (postElement, rootID) => {
20-
const showButton = dom('button', null, {
21-
click: ({ currentTarget }) => {
22-
getTimelineItemWrapper(postElement).removeAttribute(hiddenAttribute);
23-
currentTarget.disabled = true;
24-
},
25-
}, 'show it');
26-
27-
const unblockButton = dom('button', null, {
28-
click: () => {
29-
unblockPost(rootID);
30-
warningElement.remove();
31-
},
32-
}, 'unblock it');
33-
34-
const warningElement = dom('div', { class: warningClass }, null, [
35-
'You have blocked this post!',
20+
const addPermalinkPageControls = timelineElement => {
21+
const controlsElement = dom('div', { class: controlsClass }, null, [
22+
'You have hidden this post with PostBlock!',
3623
dom('br'),
37-
showButton,
38-
' / ',
39-
unblockButton,
24+
dom('button', null, { click: () => controlsElement.remove() }, 'show post anyway'),
4025
]);
41-
postElement.closest(timelineSelector).before(warningElement);
26+
timelineElement.prepend(controlsElement);
4227
};
4328

4429
let blockedPostRootIDs = [];
@@ -65,10 +50,12 @@ const processPosts = postElements =>
6550
const rootID = rebloggedRootId || postID;
6651

6752
if (blockedPostRootIDs.includes(rootID)) {
68-
getTimelineItemWrapper(postElement).setAttribute(hiddenAttribute, '');
69-
70-
if (postPermalinkTimelineFilter(postID)(postElement.closest(timelineSelector))) {
71-
addWarningElement(postElement, rootID);
53+
const timelineElement = postElement.closest(timelineSelector);
54+
if (postPermalinkTimelineFilter(postID)(timelineElement)) {
55+
getTimelineItemWrapper(postElement).setAttribute(controlledHiddenAttribute, '');
56+
addPermalinkPageControls(timelineElement);
57+
} else {
58+
getTimelineItemWrapper(postElement).setAttribute(hiddenAttribute, '');
7259
}
7360
} else {
7461
getTimelineItemWrapper(postElement).removeAttribute(hiddenAttribute);
@@ -140,7 +127,7 @@ export const clean = async function () {
140127
onNewPosts.removeListener(processPosts);
141128

142129
$(`[${hiddenAttribute}]`).removeAttr(hiddenAttribute);
143-
$(`.${warningClass}`).remove();
130+
$(`.${controlsClass}`).remove();
144131
};
145132

146133
export const stylesheet = true;

0 commit comments

Comments
 (0)