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
extendify / src / Agent / workflows / content / edit-post-strings.js

edit-post-strings.js in Extendify 3.2.1, at src/Agent/workflows/content/edit-post-strings.js

37 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { BLOCK_ID_SEL } from '@agent/lib/block-el';
2 import { UpdatePostConfirm } from '@agent/workflows/content/components/UpdatePostConfirm';
3
4 const { context, abilities } = window.extAgentData;
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
26 export default {
27 available: () =>
28 abilities?.canEditPosts &&
29 !context?.adminPage &&
30 context?.postId &&
31 !context?.isBlogPage &&
32 context.usingBlockEditor &&
33 hasSeveralStrings(),
34 id: 'edit-post-strings',
35 whenFinished: { component: UpdatePostConfirm },
36 };
37