Commits

Anonymous committed 5648059

Initial commit

  • Participants

Comments (0)

Files changed (4)

atlassian-extension.json

+{
+  "key"         : "noprocrast",
+  "name"        : "Anti-procrastination",
+  "description" : "Gives a warning when you visit a page that's probably a flamewar.",
+  "version"     : 1
+}

css/noprocrast.css

+.noprocrast-time-select {
+    float: left;
+    margin: 0 0 0 0.5em;
+}

images/troll_feeding.jpg

Added
New image

js/noprocrast/noprocrast.js

+/**
+ * NoProcrast - warns users about huge comment threads
+ *
+ * @context atl.general
+ */
+
+var jQuery = require('speakeasy/jquery').jQuery,
+    noprocrastImage = require('speakeasy/resources').getImageUrl(module, 'troll_feeding.jpg');
+
+jQuery(function($) {
+    var header = "Wait! Don't feed the trolls!",
+        wpm = 250, // according to Wikipedia
+        words = $('.comment-content').text().split(/\s+/),
+        minutes = Math.ceil(words.length / wpm),
+        threshold = AJS.Cookie.read("noprocrast-time-threshold", 20),
+        times = [10, 20, 40, 60, 120],
+        message, prettyTime, dialog, panel, timeSelect;
+
+    prettyTime = function(mins) {
+	if (mins > 1200) {
+	    return Math.floor(mins / 60) + ' hours';
+	} else if (mins >= 60) {
+	    return '1 hour';
+	}
+	return mins + ' minutes';
+    };
+
+    if (minutes > threshold) {
+	dialog = new AJS.Dialog();
+	dialog.addHeader(header);
+
+	message = '';
+	message += '<p>You will waste ' + minutes + ' minutes reading the comments on this page.</p>';
+        message += '<p>Is it really worth it? Be the change you seek!</p>';
+	message += '<div class="image" style="text-align: center"><img src="' + noprocrastImage + '" alt="" /></div>';
+	panel = dialog.addPanel('Minutes', message);
+
+	dialog.addCancel("Woah, get me out of here", function() {
+	    var path = AJS.Confluence.getContextPath();
+	    if (history.length > 1) {
+		history.go(-1);
+	    } else if (path) {
+		document.location = path;
+	    } else {
+		document.location = "/";
+	    }
+	});
+	dialog.addSubmit("Just let me in!", function() {
+            dialog.hide();
+        });
+
+	// Create a select input so that users can change their time threshold
+	timeSelect = $('<select></select>').addClass('noprocrast-time-select'); //css({'float': 'left', 'marginLeft': '0.5em'});
+	$.each(times, function(i, mins) {
+	    var option = $('<option></option>');
+	    option.val(mins).text(prettyTime(mins));
+	    if (mins == threshold) {
+		option.attr('selected', 'selected');
+	    }
+	    timeSelect.append(option);
+	});
+	timeSelect.change(function() {
+	    AJS.Cookie.save("noprocrast-time-threshold", timeSelect.val());
+	});
+	$(dialog.page[0].buttonpanel).append(timeSelect);
+
+	dialog.show();
+    }
+});