Vertix store custom name after refresh vertix.io

Keeps track of your name

目前为 2017-06-29 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Vertix store custom name after refresh vertix.io
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Keeps track of your name
  6. // @author Supercap
  7. // @match http://vertix.io/
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. document.getElementById("playerNameInput").onchange = function () {
  13. setCook("inputName",document.getElementById("playerNameInput").value,100);
  14. };
  15. var interval2 = setInterval(function(){
  16. if(document.getElementById("playerNameInput").value !== "") {
  17. document.getElementById("playerNameInput").value = getCook("inputName");
  18. clearInterval(interval2);
  19. }
  20. }, 100);
  21.  
  22. function setCook(cname, cvalue, exdays) {
  23. var d = new Date();
  24. d.setTime(d.getTime() + (exdays*24*60*60*1000));
  25. var expires = "expires="+ d.toUTCString();
  26. document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
  27. }
  28. function getCook(cname) {
  29. var name = cname + "=";
  30. var decodedCookie = decodeURIComponent(document.cookie);
  31. var ca = decodedCookie.split(';');
  32. for(var i = 0; i <ca.length; i++) {
  33. var c = ca[i];
  34. while (c.charAt(0) == ' ') {
  35. c = c.substring(1);
  36. }
  37. if (c.indexOf(name) == 0) {
  38. return c.substring(name.length, c.length);
  39. }
  40. }
  41. return "";
  42. }