PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
← All changes | src/Agent/workflows/content/edit-post-strings.js +23 -1 3.1.33.2.1 View file →
@@ -1,8 +1,29 @@
1 +import { BLOCK_ID_SEL } from '@agent/lib/block-el';
1 2 import { UpdatePostConfirm } from '@agent/workflows/content/components/UpdatePostConfirm';
2 3
3 4 const { context, abilities } = window.extAgentData;
4 5
6 +// A wrapper carries its children's text, so counting it repeats every string.
7 +const ownText = (el) => {
8 + let text = '';
9 + for (const node of el.childNodes) {
10 + if (node.nodeType === Node.TEXT_NODE) text += node.nodeValue;
11 + }
12 + return text.replace(/\s+/g, ' ').trim();
13 +};
14 +
15 +// One string is select-block's job; this earns its place on several.
16 +const hasSeveralStrings = () => {
17 + const strings = new Set();
18 + for (const el of document.querySelectorAll(BLOCK_ID_SEL)) {
19 + const text = ownText(el);
20 + if (text) strings.add(text);
21 + if (strings.size > 1) return true;
22 + }
23 + return false;
24 +};
25 +
5 26 export default {
6 27 available: () =>
7 28 abilities?.canEditPosts &&
8 29 !context?.adminPage &&
@@ -7,8 +28,9 @@
7 28 abilities?.canEditPosts &&
8 29 !context?.adminPage &&
9 30 context?.postId &&
10 31 !context?.isBlogPage &&
11 - context.usingBlockEditor,
32 + context.usingBlockEditor &&
33 + hasSeveralStrings(),
12 34 id: 'edit-post-strings',
13 35 whenFinished: { component: UpdatePostConfirm },
14 36 };