|
|
(15 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | /* Any JavaScript here will be loaded for users using the UniWiki skin */
| |
| | | |
− |
| |
− | //April Fools 4/1/2020 Code =======================================
| |
− | opts = {
| |
− | pageSelector: ".page-User_Rayanth_SeekritStuff",
| |
− | AprilFoolEnable: true,
| |
− | className: 'april-fools',
| |
− | frequency: 0.1,
| |
− | expiryThresholdMs: 2000,
| |
− | addStyleIntvl: null,
| |
− | clearStyleIntvl: null,
| |
− | maxFlicks: 18,
| |
− | minFlicks: 6,
| |
− | };
| |
− |
| |
− | // The "oh dear gods my eyes, turn it off" Button
| |
− | $(function(){
| |
− | var r = $('<input type="checkbox" name="chkAprilFoolEnable" value="3" class="lcs_check lcs_tt1" checked="checked" autocomplete="off" />');
| |
− | var AprilFoolText = '<div style="margin-bottom:1em; padding:0em; font-size: 20px; font-weight:bold; text-align:center; border:1px solid #f43e29; background: #060606; width:auto; color: #ffffff;">The UniWiki is being invaded by the Triglavians!!!</div>';
| |
− | $(opts.pageSelector + " .mw-parser-output").prepend(AprilFoolText, 'Triglavian Invasion' , r);
| |
− | startUpAprilFools();
| |
− | });
| |
− |
| |
− | function startUpAprilFools(){
| |
− | opts.addStyleIntvl = setInterval(() => addStyleToRandomWordsInJQueryObject($(opts.pageSelector + ' .mw-parser-output'), opts), 2000);
| |
− | addStyleToRandomWordsInJQueryObject($(opts.pageSelector + " .mw-parser-output"), opts);
| |
− | opts.clearStyleIntvl = setInterval(() => removeExpiredStyles(opts), 2000);
| |
− | opts.AprilFoolEnable = true;
| |
− | }
| |
− |
| |
− | function shutDownAprilFools(){
| |
− | opts.AprilFoolEnable = false;
| |
− | clearInterval(opts.addStyleIntvl);
| |
− | clearInterval(opts.clearInterval);
| |
− | $('span.april-fools').contents().unwrap();
| |
− | }
| |
− |
| |
− | function addStyleToText(text, className, ratio) {
| |
− | tokens = text.split(' ');
| |
− | result = '';
| |
− | for (let token of tokens) {
| |
− | if (token.trim() === '') {
| |
− | continue;
| |
− | }
| |
− | const shouldAddStyle = ratio > Math.random();
| |
− | if (shouldAddStyle) {
| |
− | token = `<span class="${className}" data-timestamp="${Date.now()}">${token}</span>`
| |
− | }
| |
− | result += `${token} `;
| |
− | }
| |
− | return result;
| |
− | }
| |
− |
| |
− | function addStyleToRandomWordsInJQueryObject(jqueryObject, opts) {
| |
− | if (opts.AprilFoolEnable === false) { return };
| |
− | cur_time = Date.now()
| |
− | let objects = [jqueryObject];
| |
− | while (objects.length > 0) {
| |
− | const object = objects.pop();
| |
− | let $object = $(object);
| |
− | if (object.nodeType === Node.TEXT_NODE) {
| |
− | if (object.textContent.trim() !== ''){
| |
− | const result = addStyleToText(object.textContent, opts.className, opts.frequency);
| |
− | $object.replaceWith(result);
| |
− | }
| |
− | }
| |
− | else {
| |
− | const contents = $object.contents();
| |
− | objects = objects.concat(contents.toArray());
| |
− | }
| |
− | }
| |
− | flicker_text(cur_time);
| |
− | flicker_images();
| |
− | }
| |
− |
| |
− | function removeExpiredStyles(opts) {
| |
− | const spans = $('span.april-fools').filter((_, s) => {
| |
− | const timestamp = s.attributes['data-timestamp'].value;
| |
− | return (Date.now() - timestamp) > opts.expiryThresholdMs;
| |
− | })
| |
− | .contents()
| |
− | .unwrap();
| |
− | }
| |
− |
| |
− | async function flicker_text(cur_time){
| |
− | var amount = Math.round(Math.random() * (opts.maxFlicks-opts.minFlicks) + opts.minFlicks);
| |
− | const spans = $('span.april-fools').filter((_, s) => {
| |
− | const timestamp = s.attributes['data-timestamp'].value;
| |
− | return timestamp > cur_time;
| |
− | })
| |
− |
| |
− | for(let iter = 0; iter < amount; iter++)
| |
− | {
| |
− | spans.toggleClass('april-fools');
| |
− | await sleep(Math.round(Math.random() * 100));
| |
− | }
| |
− | spans.toggleClass('april-fools', true);
| |
− | }
| |
− |
| |
− | async function flicker_images(){
| |
− | if (opts.frequency < Math.random()) { return };
| |
− | var amount = Math.round(Math.random() * (opts.maxFlicks-opts.minFlicks) + opts.minFlicks);
| |
− | const trigs = $('.AF2020_trig')
| |
− | const origs = $('.AF2020_orig')
| |
− | for(let iter = 0; iter < amount; iter++)
| |
− | {
| |
− | trigs.toggle();
| |
− | origs.toggle();
| |
− | await sleep(Math.round(Math.random() * 100));
| |
− | }
| |
− | }
| |
− |
| |
− | function sleep(ms) {
| |
− | return new Promise(resolve => setTimeout(resolve, ms));
| |
− | }
| |
− |
| |
− |
| |
− | //END April Fools 4/1/2020 Code =======================================
| |