Last active
August 29, 2015 14:03
-
-
Save fredley/9ffa2debdca18ba65c50 to your computer and use it in GitHub Desktop.
SE Comment Saver - Save Comments on SE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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