#### "use strict"; if ( typeof $().emulateTransitionEnd !== 'function') { throw("Bootstrap doesn’t seem to be available…"); } function colorReps() { $("div.reputation").each(function(){ $(this).text().match(/\s\d/) ? $(this).css({color:"teal", opacity:0.66, fontSize:"85%"}) : $(this).css({color:"#DF3969", opcaity:0.66 , fontSize:"85%"}); }); } function submitVote () { // Need to unbind and/or include a spinner. console.log("submitVote…"); let $clicked = $(this); $clicked.off(); // Right? $clicked.closest("div").animate({opacity:0},999) .children().prop("disabled",true); let $vote = $clicked.parent("label").find("button"); let $form = $vote.closest("form"); let voteName = $vote.attr("name"); let voteNodeId = voteName.replace(/vote__/,""); let nodeId = $form.find("input[name='node_id']").val(); let formData = { node_id: nodeId ,vc: $form.find("input[name='vc']").val() ,op: $form.find("input[name='op']").val() ,sexisgreat: $form.find("input[name='sexisgreat']").val() }; formData[voteName] = $vote.val(); $.ajax({ method: $form.attr("method") ,url: $form.attr("action") ,data: formData }) .fail(function(jqXHR, textStatus, errorThrown){ console.log(jqXHR); if ( textStatus === "abort" ) return; $clicked.closest("div").stop().animate({ opacity: 1 }); $vote.closest("div.reputation").text([textStatus, errorThrown || "unknown"].join(": ")); }) .done(function( html, textStatus, jqXHR ) { console.log("here in top of done with node " + nodeId + " and vote " + voteNodeId); console.log("div.reputation with node " + nodeId + " and vote " + voteNodeId); let $html = $($.parseHTML(html)); let $rep = $html.find("#rep-" + voteNodeId); console.log("received html find " + $rep.html()); $rep.css({opacity:0}); $clicked.closest("div").replaceWith($rep); $rep.animate({ opacity: 1 }, 666); let $xp = $("h1:contains(XP Nodelet)") .filter(function(){ return $(this).children().length === 0 }) .parent() .find("div"); // Can't use the same selector because the DOM isn't the same pre-transform. let $newXp = $html.find("#XP_Nodelet td"); // Account for out of votes for day. if ( $newXp.length ) { $xp.fadeOut(100, function(){ $(this).html( $newXp.html() ).fadeIn(100) }); } else { $xp.closest("section").fadeOut(100, function(){ $(this).remove() }); // Remove all vote buttons too. Untested, might work. $("div.reputation").find("button").closest("div.reputation") .fadeOut(100, function(){ $(this).remove() }); } colorReps(); }); } jQuery(function($) { $("body").hide().fadeIn(100); colorReps(); $("body").css({ color:"#00000a" }); // not being carried over anywhere... let $stripe = $('
Your Mother’s pm.2.0.js is loading…
'); $("body").append($stripe); // Block bottom page/viewed controls. $("#nodethreads-foot form").submit(function(){ return false }); // Block voting $("input[name='op'][value='vote']").closest("form").submit(function(){ return false }); $("input[name='node']").css({width:"100%"}); let $postBody = $("textarea[name='note_doctext']"); $postBody.css({width:"100%", fontFamily:"monospace"}); if ( $postBody.length ) { let $stash = $('
'); $postBody.parent().append($stash); $stash.data( "post", $postBody.val().replace(/\s+/g,"") ); window.onbeforeunload = function() { if ( $("submit['op']").val() == "op" ) return null; if ( $("submit['op']").val() == "create" ) return null; return $stash.data("post") == $postBody.val().replace(/\s+/g,"") ? null : "Unsaved…"; }; } let $voteForm = $("form").find('input[name="op"][value="vote"]').parent("form"); $voteForm.find("input[name='sexisgreat']").remove(); // Ajax -> no vote button. // DOM elements. let voteMap = { "1": '', "-1": '' }; $voteForm.find('input[type="radio"]').each(function (i, v) { let $label = $(v).parent("label"); let $button = $(voteMap[$(v).val()]); $button.attr("name",$(v).attr("name")); $button.attr("value",$(v).val()); $label.html($button); $button.on("click", submitVote); }); let $viewedForm = $("input[name='pageloadtime']").closest("form"); $viewedForm.submit(function(evt){ evt.preventDefault() }); $viewedForm.find("input[type='submit']").on("click", function(evt){ console.log(evt); console.log($(evt.target).html()); console.log(evt.target.nodeName); let $submit = $(evt.target); let formData = $viewedForm.serializeArray(); formData.push({ name:$submit.attr("name"), value:$submit.val() }); $("body").children().fadeOut(100); console.log( $viewedForm.attr("method") + " " + $viewedForm.serialize() ); console.log(formData); $.ajax({ method: $viewedForm.attr("method") ,url: $viewedForm.attr("action") ,data: formData }) .fail(function(jqXHR, textStatus, errorThrown){ if ( textStatus === "abort" ) return; let err = [textStatus, errorThrown || "unknown"].join(": "); let $err = $('
'); $err.text(err).fadeIn().delay(2000).fadeOut(); // Should remove, wrote this once already… $("body").children().fadeIn(100); }) .done(function( html, textStatus, jqXHR ) { let newDoc = document.open("text/html", "replace"); // html = html.replace(/## // What XML generators are currently available on PerlMonks? https://perlmonks.org/?node_id=72241 // PerlMonks Related Scripts https://perlmonks.org/?node_id=26649 // REQUIRES he.js "use strict"; // throw("Not ready to be incurring load from regular visits"); jQuery(function($) { let $currentMsg = $(".cb_msg"); setTimeout(function(){ $currentMsg.fadeOut(function(){ $(this).remove() }) }, 500000); // Your Mother $("table.cb_table").css({margin:"1ex 0", fontSize:"1.4rem"}); // Dup. let $CBform = $("input[type='submit'][name='message_send']").closest("form"); $CBform.find("input[name='message']").css({width:"100%",border:"1px solid gray",borderRadius:"2px"}); $CBform.find("input[name='message_send']").hide(); $CBform.parent().find("hr, input[type='checkbox']").remove(); $CBform.find("label, span.msg, span.cb_more_messages").delay(15000).slideUp(1000, function(){ $CBform.parent().find("br").remove() }); //span.cb_more_messages $CBform.parent().css({padding:0}); // Needs some click animation- $("input[type='submit']").css({border:"1px solid gray",borderRadius:"2px",margin:"2px 3px"}); $("i.cb_quiet").wrap('
'); let intID; let chatURI = document.location.origin + "/bare/"; // .cb_table // Timer, interval, like gmail; check frequently if there are a lot of current messages. // Less and less frequently when there is none. // getCB // displayCB function getCB ( arg ) { if ( ! arg ) arg = { timeout: 5000 }; if ( arg.timeout < 500000 ) arg.timeout += 10000; // maybe 10% of current instead? let queryData = { "node_id":207304 // hardcode node… ,"xmlstyle":"modern" } // Get the parsed->rendered messages. $.ajax({ method: "GET" ,url: chatURI ,data: queryData ,dataType: "xml" }) .fail(function(jqXHR, textStatus, errorThrown){ console.log(jqXHR); console.log([textStatus, errorThrown || "unknown"].join(": ")); console.log('setTimeout( getCB, ' + arg.timeout + ', arg );'); intID = setTimeout( getCB, arg.timeout, arg ); }) .done(function( xml, textStatus, jqXHR ) { console.log("Received…", xml); if ( ! xml ) { console.log('setTimeout( getCB, ' + arg.timeout + ', arg );'); intID = setTimeout( getCB, arg.timeout, arg ); return false; } // Getting null sometimes. let messages = xml.getElementsByTagName("message"); if ( ! messages.length ) { console.log('setTimeout( getCB, ' + arg.timeout + ', arg );'); intID = setTimeout( getCB, arg.timeout, arg ); return false; } let $CBtable = $("table.cb_table"); if ( ! $CBtable.length ) { // No messages in the page currently… $CBtable = $('
'); // and all is quiet... // Always there by class? and all is quiet... $("i.cb_quiet").replaceWith($CBtable); } $CBtable.css({margin:"1ex 0", fontSize:"1.4rem"}); // Dup… for (var i = 0; i < messages.length; i++ ) { let message = { author: messages[i].getElementsByTagName("author")[0].textContent ,user: messages[i].getElementsByTagName("author_user")[0].textContent ,epoch: messages[i].getElementsByTagName("createdepoch")[0].textContent ,id: messages[i].getElementsByTagName("message_id")[0].textContent ,text: messages[i].getElementsByTagName("parsed")[0].textContent }; // Skip duplicates! let renderedMessage = ` [${message.author}]: ${message.text} `; setTimeout(function(){ $(".msg_id_" + message.id).fadeOut() }, 500000); console.log(renderedMessage); $CBtable.append(renderedMessage); // I think the direction is settable… } intID = setTimeout( getCB, 5000 ); }); } getCB(); // console.log( "node_id from CB form -> " + $CBform.find("input[name='node_id']").val() ); $CBform.submit(function(evt){ evt.preventDefault(); sendMessage(); }); function sendMessage () { let formData = { node_id: $CBform.find("input[name='node_id']").val() ,op: $CBform.find("input[name='op']").val() // "message" ,message: he.encode( $CBform.find("input[name='message']").val() ) ,message_send: $CBform.find("input[name='message_send']").val() // "talk" }; console.log(formData); $.ajax({ method: $CBform.attr("method") ,url: $CBform.attr("action") ,data: formData }) .fail(function(jqXHR, textStatus, errorThrown){ console.log(jqXHR); console.log(".fail -> " + [textStatus, errorThrown || "unknown"].join(": ")); }) .done(function( html, textStatus, jqXHR ) { $CBform.find("input[name='message']").val(""); clearTimeout(intID); getCB({ timeout: 10000 }); }); } $(document).on("visibilitychange", function(){ if ( document.hidden ) { console.log("Tab is hidden, ceasing ajax CB"); clearTimeout(intID); } else { getCB({ timeout: 60000 }); console.log("Tab is visible, restarting ajax CB"); } }); }); ##
## body { opacity: 0 !important; transition: opacity 0.5s; } #### plackup -p 8282 -MPlack::App::Directory -e \ 'Plack::App::Directory->new({root => q{/path/to/the/files}})->to_app' \ --enable-ssl \ --ssl-key-file /path/to/certs/localhost.key \ --ssl-cert-file /path/to/certs/localhost.cert