Graham Quince Posted November 12, 2021 Share Posted November 12, 2021 This bit of code took a lot more faffing than I was expecting, but I think it might be useful. Imagine you want to display a random tip from a bank of tips each time someone logs in: Add a noticeboard Hide the Refresh options Get the noticeboard's UUID and add the following code: <div class="styling"></div> <script> var noticeboardUUID = '5594BCA620028E9D37048F60FB777D056CBF7E6CC2DFC92B'; function shuffle(array) { let currentIndex = array.length, randomIndex; while (currentIndex != 0) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex--; // And swap it with the current element. [array[currentIndex], array[randomIndex]] = [ array[randomIndex], array[currentIndex]]; } return array; } arguments[0].find('.styling').append( '<style>'+ 'div[data-content-uuid="' + noticeboardUUID + '"] .notice-table {'+ 'display: none;'+ '}'+ '</style>' ); setTimeout(function(){ tips = $('div[data-content-uuid="' + noticeboardUUID + '"]').find('.notice-table'); var tipsArray = []; $.each(tips.find('.topic-row'), function (key, tip) { tipsArray.push( $(this).attr('class') ); $(this).hide(); }); shuffle(tipsArray); var classToShow = tipsArray[0].split(' '); tips.find('.'+classToShow[3]).show(); tips.show(); }, 3000); </script> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now