(function (wp) {
const { registerPlugin } = wp.plugins;
const { select, dispatch, useSelect } = wp.data;
const { Fragment, createElement: el } = wp.element;
const { ToolbarButton, Button, PanelBody } = wp.components;
const { BlockControls } = wp.blockEditor || {};
const { PluginSidebar, PluginMoreMenuItem } = wp.editPost || {};
function htmlEscape(str) {
return String(str)
.replace(/&/g, '&')
.replace(//g, '>')
.replace(/"/g, '"')
.replace(/'/g, ''');
}
function makeId(prefix, i) {
return prefix + '-' + Date.now().toString().slice(-6) + '-' + i;
}
function parseLinesToFAQ(raw) {
const lines = raw.split(/\r?\n/).map(l => l.trim()).filter(Boolean);
const items = [];
for (let i = 0; i < lines.length - 1; i += 2) {
items.push({ q: lines[i], a: lines[i + 1] });
}
if (!items.length) return null;
const faqItems = items.map((item, i) => ({
id: makeId('faq-question', i),
title: item.q,
content: item.a,
visible: true
}));
const jsonAttr = JSON.stringify({ questions: faqItems });
let inner = '
';
faqItems.forEach(item => {
inner +=
'
' +
'
' + htmlEscape(item.title) + '
' +
'
' +
htmlEscape(item.content).replace(/\n/g, '
') +
'
' +
'
';
});
inner += '
';
return `
${inner}
`;
}
function getHighlightedText() {
const sel = window.getSelection && window.getSelection();
return sel && sel.rangeCount ? sel.toString() : '';
}
function convertAndReplace() {
const raw = getHighlightedText().trim();
if (!raw) {
alert("Highlight your Q&A text first.\nFormat:\nQ?\nA\nQ?\nA");
return;
}
const faqHTML = parseLinesToFAQ(raw);
if (!faqHTML) {
alert("No valid Q/A pairs detected.");
return;
}
const blocks = wp.blocks.rawHandler({ HTML: faqHTML });
const editor = select('core/block-editor');
const selectedIds = editor.getSelectedBlockClientIds();
if (!selectedIds.length) {
alert("Select a block containing the highlighted text.");
return;
}
dispatch('core/block-editor').replaceBlocks(selectedIds, blocks);
}
function ToolbarFill() {
const selectedCount = useSelect(
s => (s('core/block-editor').getSelectedBlockClientIds() || []).length,
[]
);
if (!BlockControls || !selectedCount) return null;
return el(
BlockControls,
{ group: 'block' },
el(ToolbarButton, {
icon: 'editor-help',
label: 'Convert to FAQ',
onClick: convertAndReplace
})
);
}
function MoreMenuFill() {
if (!PluginMoreMenuItem) return null;
return el(
PluginMoreMenuItem,
{ icon: 'editor-help', onClick: convertAndReplace },
'Convert Selected Text to FAQ'
);
}
// This creates a TOP TOOLBAR BUTTON (fake sidebar)
function SidebarButton() {
return el(
PluginSidebar,
{
name: "studyshoot-faq-topbar",
title: "Convert to FAQ",
icon: "editor-help"
},
el(
PanelBody,
null,
el(Button, { isPrimary: true, onClick: convertAndReplace }, "Convert Now")
)
);
}
registerPlugin('studyshoot-faq-convert', {
render: function () {
return el(
Fragment,
null,
el(ToolbarFill),
el(MoreMenuFill),
el(SidebarButton) // <-- This makes the TOP toolbar button appear
);
}
});
document.addEventListener("keydown", e => {
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === "f") {
e.preventDefault();
convertAndReplace();
}
});
})(window.wp);
(function (wp) {
const { registerPlugin } = wp.plugins;
const { select, dispatch } = wp.data;
function getHighlightedText() {
const sel = window.getSelection && window.getSelection();
return sel && sel.rangeCount ? sel.toString() : '';
}
function convertToListBlock() {
const raw = getHighlightedText().trim();
if (!raw) {
alert("Highlight multiple lines to convert them into a list.");
return;
}
const lines = raw.split(/\r?\n/).map(l => l.trim()).filter(Boolean);
if (!lines.length) {
alert("No valid lines found.");
return;
}
// Build HTML list (Gutenberg will transform this)
const html =
'' +
lines.map(item => '- ' + item + '
').join('') +
'
';
// Convert to WP block(s)
const blocks = wp.blocks.rawHandler({ HTML: html });
const editor = select("core/block-editor");
const selectedIds = editor.getSelectedBlockClientIds();
if (!selectedIds.length) {
alert("Select a block that contains the highlighted text.");
return;
}
// Replace selected block with list block
dispatch("core/block-editor").replaceBlocks(selectedIds, blocks);
}
// Keyboard shortcut: Ctrl + Shift + L
document.addEventListener("keydown", function (e) {
if ((e.ctrlKey || e.metaKey) && e.shiftKey && e.key.toLowerCase() === "l") {
e.preventDefault();
convertToListBlock();
}
});
registerPlugin("studyshoot-list-converter", {
render: function () { return null; }
});
})(window.wp);
(function (wp) {
const { registerPlugin } = wp.plugins;
const { Fragment, useState, createElement: el } = wp.element;
const { Button, TextControl, PanelBody } = wp.components;
const { PluginSidebar, PluginSidebarMoreMenuItem } = wp.editPost || {};
const { select, dispatch } = wp.data;
const DEFAULT_FIND_TEXT = "chatgpt";
const DEFAULT_REPLACE_TEXT = "studyshoot";
function ReplaceSidebar() {
const [findText, setFind] = useState(DEFAULT_FIND_TEXT);
const [replaceText, setReplace] = useState(DEFAULT_REPLACE_TEXT);
// Function to replace text
function runReplace() {
const activeFindText = findText || DEFAULT_FIND_TEXT;
const activeReplaceText = replaceText || DEFAULT_REPLACE_TEXT;
if (!activeFindText) {
alert("Enter text to find.");
return;
}
const content = select("core/editor").getEditedPostContent();
if (!content) {
alert("No content found.");
return;
}
const replacedHTML = content.split(activeFindText).join(activeReplaceText);
const newBlocks = wp.blocks.rawHandler({ HTML: replacedHTML });
if (!newBlocks || !newBlocks.length) {
alert("Error converting to blocks.");
return;
}
dispatch("core/block-editor").resetBlocks(newBlocks);
alert("Replacement completed successfully.");
}
// Function to add line breaks only in paragraphs
function runAddLineBreaks() {
const { select, dispatch } = wp.data;
const { createBlock } = wp.blocks;
const existingBlocks = select("core/block-editor").getBlocks();
if (!existingBlocks || !existingBlocks.length) {
alert("No blocks found.");
return;
}
const newBlocks = [];
existingBlocks.forEach(block => {
// Only process paragraph blocks
if (block.name !== "core/paragraph") {
newBlocks.push(block);
return;
}
const rawHTML = block.attributes.content;
if (!rawHTML) {
newBlocks.push(block);
return;
}
// Split on sentence-ending period followed by whitespace or end of string
// Keeps the period with the sentence, ignores empty results
const sentences = rawHTML
.split(/(?<=\.)\s+/) // split AFTER a period + whitespace
.map(s => s.trim())
.filter(s => s.length > 0);
if (sentences.length <= 1) {
// Nothing to split — keep original block untouched
newBlocks.push(block);
return;
}
// Create one clean paragraph block per sentence
sentences.forEach(sentence => {
newBlocks.push(
createBlock("core/paragraph", {
...block.attributes, // preserve align, className, etc.
content: sentence,
})
);
});
});
dispatch("core/block-editor").resetBlocks(newBlocks);
}
return el(
Fragment,
null,
// Toolbar button in More Menu
el(
PluginSidebarMoreMenuItem,
{
target: "studyshoot-replace-text-sidebar",
icon: "editor-spellcheck"
},
"Replace Text"
),
// Sidebar UI
el(
PluginSidebar,
{
name: "studyshoot-replace-text-sidebar",
title: "Find & Replace",
icon: "editor-spellcheck"
},
el(
PanelBody,
{ title: "Replace Text Tool", initialOpen: true },
el(TextControl, {
label: "Find:",
value: findText || DEFAULT_FIND_TEXT,
placeholder: DEFAULT_FIND_TEXT,
onChange: setFind
}),
el(TextControl, {
label: "Replace with:",
value: replaceText || DEFAULT_REPLACE_TEXT,
placeholder: DEFAULT_REPLACE_TEXT,
onChange: setReplace
}),
// Replace All button
el(Button, {
isPrimary: true,
onClick: runReplace,
style: { marginTop: "12px" }
}, "Replace All"),
// Add Line Breaks button (paragraphs only)
el(Button, {
isSecondary: true,
onClick: runAddLineBreaks,
style: { marginTop: "12px" }
}, "Add Line Breaks")
)
)
);
}
registerPlugin("studyshoot-replace-text-plugin", {
render: ReplaceSidebar
});
})(window.wp);
التعليقات على: دراسة الإعلام في سويسرا
https://studyshoot.com/_/%d8%af%d8%b1%d8%a7%d8%b3%d8%a9-%d8%a7%d9%84%d8%a5%d8%b9%d9%84%d8%a7%d9%85-%d9%81%d9%8a-%d8%b3%d9%88%d9%8a%d8%b3%d8%b1%d8%a7/
منحة | عمل | مستقبل
Thu, 11 Jun 2026 23:36:10 +0000
hourly
1
https://wordpress.org/?v=7.1.3