Skip to content

Instantly share code, notes, and snippets.

@notmike101
Last active August 29, 2015 14:14
Show Gist options
  • Save notmike101/c9b959a0622657a31bcb to your computer and use it in GitHub Desktop.
Save notmike101/c9b959a0622657a31bcb to your computer and use it in GitHub Desktop.
(function(){
if(typeof(Storage) === "undefined") {
throw new Error("No Web Storage support! Terminating script. Try updating your browser.");
}
function saveUserNotes(uid,notes) {
try {
localStorage.setItem('lf_notes_'+uid,notes);
return true;
} catch(e) {
return false;
}
}
function getUserNotes(uid) {
var userNotes = localStorage.getItem('lf_notes_'+uid);
if(userNotes === null) {
return '';
} else {
return userNotes;
}
}
var url = window.location.href;
// Add to user profile
if(url.indexOf('/user-') != -1 || url.indexOf('\@') != -1 || url.indexOf('/member.php?action=profile&uid=') != -1) {
if(document.getElementsByClassName('navigation')[0].getElementsByClassName('active')[0].textContent == "Board Message") {
console.log("User does not exist");
} else {
var userID = document.getElementsByClassName("profile_usertitle")[1].textContent.split("UID: ")[1].trim();
console.log("Got user profile [" + userID + "]");
var noteWorkArea = document.getElementsByTagName('table')[4];
if(noteWorkArea === undefined) {
noteWorkArea = document.getElementsByTagName('table')[3].parentNode;
} else {
noteWorkArea = noteWorkArea.parentNode
}
var noteWorker = document.createElement('table');
noteWorker.setAttribute('class','tborder');
noteWorker.setAttribute('border','0');
noteWorker.setAttribute('cellpadding','10');
noteWorker.setAttribute('cellspacing','0');
noteWorker.setAttribute('style','margin-bottom:20px;');
noteWorker.innerHTML = '<tbody><tr><td colspan="2" class="thead"><strong>User Notes</strong></td></tr><tr><td class="trow1"><textarea id="noteTextArea" style="width:100%;resize:none;min-height:300px;max-height:300px;" userID="'+userID+'"></textarea></td></tr></tbody>';
noteWorkArea.insertBefore(noteWorker,noteWorkArea.childNodes[0]);
document.getElementById('noteTextArea').value = getUserNotes(userID);
document.getElementById('noteTextArea').addEventListener('keyup', function(e) {
saveUserNotes(this.getAttribute('userID'),this.value);
console.log("Updated user notes for "+this.getAttribute('userID'));
});
}
} else if(url.indexOf('/thread-') != -1 || url.indexOf('/showthread.php?tid=') != -1) {
var posts = document.getElementById('posts').children;
for(var i = 0;i < posts.length; ++i) {
var userID = posts[i].getElementsByClassName('username')[0].getElementsByTagName('a')[0].getAttribute('href').split('user-')[1];
var noteWorkArea = posts[i].getElementsByClassName('aw')[0].parentNode;
var noteWorker = document.createElement('li');
noteWorker.setAttribute('class','userNotes');
noteWorker.setAttribute('style','margin-top:5px;');
noteWorker.innerHTML = '<textarea id="noteTextArea_'+i+'" style="width:100%;resize:none;min-height:300px;max-height:300px;" userID="'+userID+'"></textarea>'
noteWorkArea.appendChild(noteWorker);
document.getElementById('noteTextArea_'+i).value = getUserNotes(userID);
document.getElementById('noteTextArea_'+i).addEventListener('keyup', function(e) {
saveUserNotes(this.getAttribute('userID'),this.value);
console.log("Updated user notes for "+this.getAttribute('userID'));
});
}
}
})()
@notmike101
Copy link
Author

Made this in about an hour. I got bored...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment