Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SE Comment Saver - Save Comments on SE
// ==UserScript==
// @name SE Comment Saver
// @description Save SE
// @version 1.0
// @include http://meta.stackoverflow.com/*
// @include http://*.stackexchange.com/*
// @include http://serverfault.com/*
// @include http://stackoverflow.com/*
// @include http://askubuntu.com/*
// @include http://stackapps.com/*
// @include http://superuser.com/*
// @include http://meta.serverfault.com/*
// @include http://meta.stackoverflow.com/*
// @include http://meta.askubuntu.com/*
// @include http://meta.stackapps.com/*
// @include http://meta.superuser.com/*
// @run-at document-end
// ==/UserScript==
var inject = function($){
$(document).ready(function(){
$('div.comments').each(function(){
if(localStorage[$(this).attr('id')]){
var el = $(this);
setTimeout(function(){
el.next().find('.js-add-link').click();
el.find('textarea').val(localStorage[el.attr('id')]);
},1000);
}
});
$('input[value="Add Comment"]').on('click',function(){
var id = $(this).parents('div.comments').attr('id');
localStorage.removeItem(id);
});
});
$(window).unload(function(){
$('textarea[name=comment]:visible').each(function(){
if($(this).val() != ""){
var id = $(this).parents('div.comments').attr('id');
localStorage[id] = $(this).val();
}
});
});
};
var script = document.createElement('script');
script.type = 'text/javascript';
script.textContent = '(' + inject.toString() + ')(jQuery)';
document.body.appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.