I have a script for previewing topics from a recent or unread topic page.
As of version 1.18.3 of NodeBB, the script does not work.
Can you help?
This is the script:
(function() {
'use strict';
function onhover() {
/* globals require, $, socket, app */
var self = $(this);
if (!self.data('preview-loaded')) {
socket.emit('topics.loadMore', {
tid: self.data('my-tid'),
after: 0,
count: 1,
direction: 1
}, (e, d) => {
self.data('preview-loaded', 1);
require('translator').translate(e ? '<span style="color:red;">error: </span>' + e.message : d.mainPost.content,
(d) => {
if (app.user.uid === 0) {
d = d.replace(/\|\|.*\|\|/g,'<a href="https://domain.com/login">You must be logged in to view this link.</a>');
} else {
d = d.replace(/\|\|/g,'');
}
$('#preview-' + self.data('my-tid')).children().html(d.replace(/\|\|/g,''));
});
}
);
}
$('#preview-' + self.data('my-tid')).stop(true).delay(500).fadeIn();
}
function onunhover() {
$('#preview-' + $(this).data('my-tid')).stop(true).fadeOut();
}
$(window).on('action:topics.loaded', (event, data) => {
for (let topic of data.topics) {
let topicElem = $('[data-tid="' + topic.tid + '"]');
createPreview(topicElem);
}
});
function addTopicTools() {
let topicelems = $('[component="category/topic"]');
topicelems.each((i, elem) => {
createPreview($(elem));
});
}
function createPreview(topicElem) {
let tid = parseInt(topicElem.attr('data-tid'));
if (!$('#preview-' + tid).length) {
topicElem.find('.content').append('<div class="post-preview" id="preview-' + tid + '"><div class="wrap-post-preview">טוען...</div></div>');
topicElem.find('.post-preview').hover(function(){$(this).stop(true).fadeIn();},function(){$(this).delay(600).fadeOut();});
topicElem.find('[itemprop="url"]').data('my-tid', tid).hover(
onhover,
onunhover
);
}
}
$(window).on('action:ajaxify.end', addTopicTools);
})();
(The script also exchanges for guests each link to a login page, to encourage registration)
@baris 