Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * JNews || Fix Recaptcha in Dark Mode
- */
- (function ($) {
- function render_recaptcha(mode) {
- if (grecaptcha.render) {
- $('.g-recaptcha').each(function () {
- const clonned = $(this).clone().empty();
- if (clonned[0]) {
- clonned.insertAfter(this);
- $(this).remove();
- grecaptcha.render(clonned[0], {
- sitekey: clonned.data('sitekey'),
- theme: mode
- });
- }
- });
- }
- }
- // === OBSERVER ===
- const targetNode = document.body;
- const config = { attributes: true, attributeFilter: ['class'] };
- const observer = new MutationObserver(function (mutationsList) {
- for (const mutation of mutationsList) {
- if (mutation.type === 'attributes') {
- const isDark = document.body.classList.contains('jnews-dark-mode');
- if (isDark) {
- render_recaptcha('dark');
- } else {
- render_recaptcha('light');
- }
- }
- }
- });
- observer.observe(targetNode, config);
- // Optional: trigger at page load
- if (document.body.classList.contains('jnews-dark-mode')) {
- render_recaptcha('dark');
- } else {
- render_recaptcha('light');
- }
- })(jQuery)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement