// ==UserScript== // @name AutoReviewComments // @namespace benjol // @version 1.0.7 // @description Add pro-forma comments dialog for reviewing (pre-flag) // @include http://*stackoverflow.com/questions* // @include http://*serverfault.com/questions* // @include http://*superuser.com/questions* // @include http://*stackexchange.com/questions* // @include http://*askubuntu.com/questions* // @include http://*answers.onstartups.com/questions* // @include http://mathoverflow.net/questions* // @include http://discuss.area51.stackexchange.com/questions/* // @include http://stackapps.com/questions* // ==/UserScript== function with_jquery(f) { var script = document.createElement("script"); script.type = "text/javascript"; script.textContent = "(" + f.toString() + ")(jQuery)"; document.body.appendChild(script); }; with_jquery(function ($) { $(function () { var scriptVersion = '1.0.7'; //<<<<<<<<<<<<*********************** DON'T FORGET TO UPDATE THIS!!!! ************************* var siteurl = 'http://' + window.location.hostname; //include http in here so we don't get confusion between so and meta.so var arr = document.title.split(' - '); var sitename = arr[arr.length - 1]; if(sitename == "Stack Exchange") sitename = arr[arr.length - 2]; //workaround for SE sites.. var greeting = 'Welcome to ' + sitename + '! '; var greetingOn = false; var markup = ' \ '; var option = ' \
  • \ \ \
  • '; //default comments var comments = [ { Name: "Answers just to say Thanks!", Description: 'Please don\'t add "thanks" as answers. Invest some time in the site and you will gain sufficient privileges to upvote answers you like, which is the $SITENAME$ way of saying thank you.' }, { Name: "Nothing but a URL (and isn't spam)", Description: 'Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.' }, { Name: "Requests to OP for further information", Description: 'This is really a comment, not an answer. With a bit more rep, you will be able to post comments. For the moment I\'ve added the comment for you, and I\'m flagging this post for deletion.' }, { Name: "OP using an answer for further information", Description: 'Please use the Post answer button only for actual answers. You should modify your original question to add additional information.' }, { Name: "OP adding a new question as an answer", Description: 'If you have another question, please ask it by clicking the Ask Question button.' }, { Name: "Another user adding a 'Me too!'", Description: 'If you have a NEW question, please ask it by clicking the Ask Question button. If you have sufficient reputation, you may upvote the question. Alternatively, "star" it as a favorite and you will be notified of any new answers.' }, ]; var weekday_name = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var minute = 60, hour = 3600, day = 86400, sixdays = 518400, week = 604800, month = 2592000, year = 31536000; //Calculate and format datespan for "Member since/for" function datespan(date) { var now = new Date() / 1000; var then = new Date(date * 1000); var today = new Date().setHours(0, 0, 0) / 1000; var nowseconds = now - today; var elapsedSeconds = now - date; var strout = ""; if(elapsedSeconds < nowseconds) strout = "since today"; else if(elapsedSeconds < day + nowseconds) strout = "since yesterday"; else if(elapsedSeconds < sixdays) strout = "since " + weekday_name[then.getDay()]; else if(elapsedSeconds > year) { strout = "for " + Math.round((elapsedSeconds) / year) + " years"; if(((elapsedSeconds) % year) > month) strout += ", " + Math.round(((elapsedSeconds) % year) / month) + " months"; } else if(elapsedSeconds > month) { strout = "for " + Math.round((elapsedSeconds) / month) + " months"; if(((elapsedSeconds) % month) > week) strout += ", " + Math.round(((elapsedSeconds) % month) / week) + " weeks"; } else { strout = "for " + Math.round((elapsedSeconds) / week) + " weeks"; } return strout; } //Calculate and format datespan for "Last seen" function lastseen(date) { var now = new Date() / 1000; var today = new Date().setHours(0, 0, 0) / 1000; var nowseconds = now - today; var elapsedSeconds = now - date; if(elapsedSeconds < minute) return (Math.round(elapsedSeconds) + " seconds ago"); if(elapsedSeconds < hour) return (Math.round((elapsedSeconds) / minute) + " minutes ago"); if(elapsedSeconds < nowseconds) return (Math.round((elapsedSeconds) / hour) + " hours ago"); if(elapsedSeconds < day + nowseconds) return ("yesterday"); var then = new Date(date * 1000); if(elapsedSeconds < sixdays) return ("on " + weekday_name[then.getDay()]); return then.toDateString(); } //Format reputation string function repNumber(r) { if(r < 1E4) return r; else if(r < 1E5) { var d = Math.floor(Math.round(r / 100) / 10); r = Math.round((r - d * 1E3) / 100); return d + (r > 0 ? "." + r : "") + "k" } else return Math.round(r / 1E3) + "k" } //Get userId for post function getUserId(el) { var url = el.parents('div').find('.post-signature:last').find('.user-details > a').attr('href') || "NULL"; if (url == "NULL") return "NULL"; else return url.split('/')[2]; } function isNewUser(date) { return (new Date() / 1000) - date < week } //Ajax to Stack Exchange api to get basic user info, and paste into userinfo element //http://soapi.info/code/js/stable/soapi-explore-beta.htm function getUserInfo(userid, container) { var userinfo = container.find('#userinfo'); if (userid == "NULL") { var html = 'User is not registered.'; userinfo.html(html.replace(/ +/g, ' ')); greetingOn = true; return; } $.ajax({ type: "GET", url: siteurl.replace('http://', 'http://api.') + '/1.0/users/' + userid + '?jsonp=?', dataType: "jsonp", timeout: 2000, success: function (data) { if(data['users'].length > 0) { var user = data['users'][0]; if (isNewUser(user['creation_date'])) { greetingOn = true; container.find('.action-desc').prepend(greeting); } var html = 'User ' + user['display_name'] + ', \ member ' + datespan(user['creation_date']) + ', \ last seen ' + lastseen(user['last_access_date']) + ', \ reputation ' + repNumber(user['reputation']) + ''; userinfo.html(html.replace(/ +/g, ' ')); } else userinfo.fadeOutAndRemove(); }, error: function () { userinfo.fadeOutAndRemove(); } }); } //Show textarea in front of popup to import/export all comments (for other sites or for posting somewhere) function ImportExport(popup) { var tohide = popup.find('#main'); var div = $('