apajohnson

Untitled

Aug 7th, 2014
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Change Display Name and Log In On Group Page
  3. // @namespace http://www.reddit.com/user/goodygood_274/
  4. // @version 0.1
  5. // @include http://tagpro-*.koalabeast.com/*
  6. // @description Change your display name and Log In from the group page
  7. // @license GPL version 3 or any later version; http://www.gnu.org/copyleft/gpl.html
  8. // @author ballparts
  9. // ==/UserScript==
  10.  
  11. // This saves your profile page URL in local storage for use later
  12. url = $('a[href^="/profile"]').attr('href');
  13. if(url !== undefined) {
  14. var n = url.lastIndexOf('/');
  15. var profileNum = url.substring(n + 1);
  16. profilePage = String('/profile/'+profileNum);
  17. localStorage.setItem('profilePage2',profilePage);
  18. }
  19.  
  20. // If you are on the group page, draw a "change displayed name" input box and button, and a login button
  21. if( document.URL.search(/(groups).[a-zA-Z]{8}/) >= 0 ) {
  22. $('#leaveButton').after('<Button id="loginButton">Log in</Button>');
  23. $('#loginButton').after('<Button id="changeDisplayName">Change Display Name</Button>');
  24. $('#changeDisplayName').after('<Input id="displayNameText"></Input>');
  25. $('#changeDisplayName').click(function() {
  26. dnt = document.getElementById('displayNameText');
  27. sessionStorage.setItem('displayName',dnt.value);
  28. sessionStorage.setItem('changeName','yes');
  29. sessionStorage.setItem('groupURL', window.location.href);
  30. window.location.href = localStorage.getItem('profilePage2');
  31. });
  32. $('#loginButton').click(function() {
  33. sessionStorage.setItem('mainPageURL', document.URL.replace(/.com\/.+/,'.com/'));
  34. sessionStorage.setItem('login','yes');
  35. sessionStorage.setItem('groupURL', window.location.href);
  36. window.location.href = sessionStorage.getItem('mainPageURL');
  37. });
  38.  
  39. // determine if the user is logged in. if so, hide the login button.
  40. mainPageHTML = $.get(document.URL.replace(/.com\/.+/,'.com/'));
  41. function checkLoginStatus() {
  42. if(mainPageHTML.responseText !== undefined) {
  43. loggedInTest = mainPageHTML.responseText.search('profile');
  44. if( loggedInTest >= 0 ) {
  45. document.getElementById('loginButton').style.display = 'none';
  46. }
  47. }
  48. }
  49. checkLoginStatus();
  50. }
  51.  
  52. // If you are on the profile page AND the 'changeName' variable is 'yes,' change the displayed name
  53. if( document.URL.search('profile') >= 0 & sessionStorage.getItem('changeName') == 'yes') {
  54. $('#displayedName').val(sessionStorage.getItem('displayName'));
  55. updateButton = document.getElementById('saveReservedName');
  56. updateButton.click();
  57. sessionStorage.setItem('changeName', 'no');
  58. window.location.href = sessionStorage.getItem('groupURL');
  59. }
  60.  
  61. // If you are on the main page AND the 'login' variable is 'yes,' then:
  62. // if the login button is there, press it
  63. // if you're already loggen in, go back to the group
  64. if( window.location.href == sessionStorage.getItem('mainPageURL') & sessionStorage.getItem('login') == 'yes') {
  65. profileTest = $('a[href^="/profile"]').attr('href');
  66. if(profileTest === undefined) {
  67. $('body>article>div>a.button')[1].click();
  68. } else {
  69. sessionStorage.setItem('login','no');
  70. window.location.href = sessionStorage.getItem('groupURL');
  71. }
  72. }
  73.  
  74. setInterval(checkLoginStatus, 100);
Add Comment
Please, Sign In to add comment