Advertisement
Guest User

mal cookie remover

a guest
Apr 1st, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        MAL-CookieRemover
  3. // @description When the MyAnimeList.net login becomes invalid because the ip changed, this script deletes the cookies and redirects to the login page (and back to the previous page after login).
  4. // @namespace   http://userscripts.org/users/524082
  5. // @include     /^https?:\/\/(.*\.)*myanimelist.net\/.*$/
  6. // @grant       none
  7. // @version     1.0
  8. // ==/UserScript==
  9.  
  10. function clearCookies() {
  11.     // code from http://stackoverflow.com/questions/2194473/can-greasemonkey-delete-cookies-from-a-given-domain
  12.     var domain      = document.domain;
  13.     var domain2     = document.domain.replace (/^www\./, "");
  14.     var domain3     = document.domain.replace (/^(\w+\.)+?(\w+\.\w+)$/, "$2");
  15.  
  16.     //listCookies (); //-- Optional, for information or debug...
  17.  
  18.     //--- Loop through cookies and delete them.
  19.     var cookieList  = document.cookie.split (';');
  20.  
  21.     for (var J = cookieList.length - 1;   J >= 0;  --J) {
  22.         var cookieName = cookieList[J].replace (/\s*(\w+)=.+$/, "$1");
  23.  
  24.         //--- To delete a cookie, set its expiration date to a past value.
  25.         document.cookie = cookieName + "=;expires=expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  26.         document.cookie = cookieName + "=;path=/;expires=expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  27.         document.cookie = cookieName + "=;path=/;domain=" + domain  + ";expires=expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  28.         document.cookie = cookieName + "=;path=/;domain=" + domain2 + ";expires=expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  29.         document.cookie = cookieName + "=;path=/;domain=" + domain3 + ";expires=expires=Thu, 01-Jan-1970 00:00:01 GMT;";
  30.     }
  31.  
  32.     //listCookies (); //-- Optional, for information or debug...
  33.  
  34.     //-- Optional function, for information or debug...
  35.     function listCookies () {
  36.         var cookieList  = document.cookie.split (';');
  37.  
  38.         for (var J = 0, numCookies = cookieList.length;   J < numCookies;  ++J) {
  39.             console.log ("Cookie ", J, ": ", cookieList[J]);
  40.         }
  41.     }
  42. }
  43.  
  44. if(document.body.innerHTML.contains("clear your cookies")) {
  45.     clearCookies();
  46.     if(!window.location.href.contains("login.php")) {
  47.         localStorage.setItem("redirectURL", window.location.href);
  48.         window.location.href = "http://" + document.domain + "/login.php";
  49.     }
  50. }
  51.  
  52. var redirectURL = localStorage.getItem("redirectURL");
  53. if(redirectURL !== null && document.cookie.contains("Z=")) {
  54.     localStorage.removeItem("redirectURL");
  55.     window.location.href = redirectURL;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement