No edit summary |
No edit summary |
||
| Line 146: | Line 146: | ||
// Function to change the color of "▶" symbols to white | // Function to change the color of "▶" symbols to white | ||
mw.hook('wikipage.content').add(function ($content) { | mw.hook('wikipage.content').add(function ($content) { | ||
// | // Target the audio-ref elements specifically | ||
var | var audioRefs = $content.find('.audio-ref'); | ||
audioRefs.each(function() { | |||
var $element = $(this); | var $element = $(this); | ||
// | // Find all text nodes within this element | ||
$element.contents().filter(function() { | $element.contents().filter(function() { | ||
return this.nodeType === 3; // Text nodes | return this.nodeType === 3 || this.nodeType === 1; // Text nodes or elements | ||
}).each(function() { | }).each(function() { | ||
var | var node = this; | ||
if ( | // If it's a text node containing the symbol | ||
if (node.nodeType === 3 && node.nodeValue && node.nodeValue.includes('▶')) { | |||
var text = | var text = node.nodeValue; | ||
var parts = text.split( | var parts = text.split(/▶[\uFE0E\uFE0F]?/); // Handle variation selectors | ||
if (parts.length > 1) { | if (parts.length > 1) { | ||
| Line 203: | Line 183: | ||
} | } | ||
node.parentNode.replaceChild(fragment, node); | |||
} | } | ||
} | |||
// If it's an element, check its content recursively | |||
else if (node.nodeType === 1) { | |||
$(node).html($(node).html().replace(/▶[\uFE0E\uFE0F]?/g, '<span style="color: white;">▶</span>')); | |||
} | } | ||
}); | }); | ||
}); | |||
// Also check for play symbols in links and other elements | |||
$content.find('a').each(function() { | |||
var $link = $(this); | |||
var linkText = $link.text(); | |||
if (linkText.includes('▶')) { | |||
var htmlContent = $link.html(); | |||
var updatedHtml = htmlContent.replace(/▶[\uFE0E\uFE0F]?/g, '<span style="color: white;">▶</span>'); | |||
$link.html(updatedHtml); | |||
} | |||
}); | }); | ||
}); | }); | ||
Revision as of 16:21, 13 April 2025
// Add play buttons to spans with a specific class
mw.hook('wikipage.content').add(function ($content) {
// Target spans with your specific class, e.g., 'audio-text'
$content.find('span.audio-text').each(function () {
var $span = $(this);
$span.css({
'display': 'inline-flex',
'align-items': 'center'
});
// Create the play button
var $playButton = $('<button>')
.addClass('play-button')
.text('')
.css({
'margin-left': '10px',
'cursor': 'pointer',
'background': 'transparent',
'color':'white'
})
.click(function (e) {
e.preventDefault();
// Add your play functionality here
// For example, read the text aloud or play an associated audio file
var textToSpeak = $span.text();
console.log('Playing:', textToSpeak);
// Example: Use the Web Speech API for text-to-speech
// Uncomment if you want to use this functionality
/*
if ('speechSynthesis' in window) {
var utterance = new SpeechSynthesisUtterance(textToSpeak);
speechSynthesis.speak(utterance);
}
*/
});
// Insert the play button after the span
$span.append($playButton);
});
});
/* IFRAME COMMUNICATION */
(function() {
'use strict';
// Only run if we're in an iframe
if (window.parent !== window) {
// Wait for the page to load
$(function() {
// Configuration
var PARENT_ORIGIN = 'http://127.0.0.1:5500/wiki/index.html';
var CLICKABLE_ELEMENTS = [
'a', // Category links
'.audio-ref'
];
// Add click handlers to the specified elements
$(CLICKABLE_ELEMENTS.join(', ')).on('click', function(e) {
// Get element information
var elementInfo = {
type: 'elementClicked',
elementId: this.id || 'unnamed-element',
elementTag: this.tagName.toLowerCase(),
elementClass: this.className,
elementText: $(this).text().trim(),
timestamp: Date.now()
};
// Send message to parent React app
window.parent.postMessage(elementInfo, PARENT_ORIGIN);
console.log('Click detected and reported:', elementInfo);
});
console.log('Click detection initialized for iframe communication');
});
}
})();
/* SIDEBAR CUSTOMIZATION */
$(document).ready(function() {
// Get element's position relative to the viewport
function getElementTopPosition(selector) {
var element = $(selector);
if (element.length) {
var elementPosition = element.offset().top;
var scrollTop = $(window).scrollTop();
var positionInViewport = elementPosition - scrollTop;
// Store the position for later use
var storedPosition = elementPosition;
console.log('Element position stored:', storedPosition);
return storedPosition;
}
return 0;
}
// Store positions when page loads
var onePosition = getElementTopPosition('.sidebar-heading.one');
var twoPosition = getElementTopPosition('.sidebar-heading.two');
var threePosition = getElementTopPosition('.sidebar-heading.three');
// Select elements with the scroll-trigger class
$('.sidebar-heading.one').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: onePosition - 202
}, 300); // 300ms animation duration
});
$('.sidebar-heading.two').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: twoPosition - 240
}, 300); // 300ms
});
// Select elements with the scroll-trigger class
$('.sidebar-heading.three').click(function() {
// Find the scrollable container
var container = $('#topbar');
// Scroll to the top of the container (position 0)
container.animate({
scrollTop: threePosition - 275
}, 300); // 300ms animation duration
});
});
// Function to change the color of "▶" symbols to white
mw.hook('wikipage.content').add(function ($content) {
// Target the audio-ref elements specifically
var audioRefs = $content.find('.audio-ref');
audioRefs.each(function() {
var $element = $(this);
// Find all text nodes within this element
$element.contents().filter(function() {
return this.nodeType === 3 || this.nodeType === 1; // Text nodes or elements
}).each(function() {
var node = this;
// If it's a text node containing the symbol
if (node.nodeType === 3 && node.nodeValue && node.nodeValue.includes('▶')) {
var text = node.nodeValue;
var parts = text.split(/▶[\uFE0E\uFE0F]?/); // Handle variation selectors
if (parts.length > 1) {
var fragment = document.createDocumentFragment();
for (var i = 0; i < parts.length; i++) {
// Add text part
if (parts[i]) {
fragment.appendChild(document.createTextNode(parts[i]));
}
// Add symbol with styling (except after the last part)
if (i < parts.length - 1) {
var span = document.createElement('span');
span.textContent = '▶';
span.style.color = 'white';
fragment.appendChild(span);
}
}
node.parentNode.replaceChild(fragment, node);
}
}
// If it's an element, check its content recursively
else if (node.nodeType === 1) {
$(node).html($(node).html().replace(/▶[\uFE0E\uFE0F]?/g, '<span style="color: white;">▶</span>'));
}
});
});
// Also check for play symbols in links and other elements
$content.find('a').each(function() {
var $link = $(this);
var linkText = $link.text();
if (linkText.includes('▶')) {
var htmlContent = $link.html();
var updatedHtml = htmlContent.replace(/▶[\uFE0E\uFE0F]?/g, '<span style="color: white;">▶</span>');
$link.html(updatedHtml);
}
});
});
