Created
May 22, 2018 14:38
-
-
Save lois6b/2f33a5709eb2c1f598ebddd8d9213adb to your computer and use it in GitHub Desktop.
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 Añadir Notas | |
// @description comentarios sobre usuarios | |
// @include *://*.stackoverflow.com/* | |
// @include *://*.stackexchange.com/* | |
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js | |
// @version 1.1 | |
// ==/UserScript== | |
var icono = "<img src='https://cdn2.iconfinder.com/data/icons/basicset/bubble_16.png'> "; | |
var add = "<img src='https://cdn2.iconfinder.com/data/icons/line-icon-set-based-at-material-design-1/176/Icon_add-to-photos-compressor-16.png'> "; | |
cargarNotas(); | |
function cargarNotas(elem){ | |
if(elem){ | |
var comentario = localStorage.getItem(elem.attr("user")); | |
if(comentario){ | |
$('div[user="' + elem.attr("user")+'"]').html( icono + comentario); | |
}else{ | |
$('div[user="' + elem.attr("user")+'"]').html( add); | |
} | |
}else{ | |
$('div[class^="user-info "]').each(function(el){ | |
var user = $(this).children().filter(".user-details").children().filter("a").attr("href"); | |
if(user){ | |
var comentario = localStorage.getItem(user); | |
if(comentario){ | |
$(this).after("<div name='notas' user='"+ user+ "' >" + icono + comentario + "</div>"); | |
}else{ | |
$(this).after("<div name='notas' user='"+ user+"' title='Añadir Nota para " + user.substring(user.lastIndexOf("/")+1) + "' >" +add+ "</div>"); | |
} | |
} | |
}); | |
//cargar nota en el title de los comentarios tambien | |
$('a[href*="/users/"]').each(function(el){ | |
var comentario = localStorage.getItem($(this).attr("href")); | |
if(comentario){ | |
var title = $(this).attr("title"); | |
$(this).attr("title", (title ? title + " - " : "") + comentario ); | |
} | |
}); | |
} | |
} | |
$('div[name="notas"]').on('click', function(){ | |
var nota = prompt("Modifica las notas:", this.innerText); | |
if (nota !== null) { | |
localStorage.setItem($(this).attr("user"), nota); | |
cargarNotas($(this)); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment